Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLUTEN-6082][CH]Fix lag diff #6085

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.gluten.substrait.rel.LocalFilesNode.ReadFileFormat._
import org.apache.spark.SparkEnv
import org.apache.spark.internal.Logging
import org.apache.spark.sql.catalyst.catalog.BucketSpec
import org.apache.spark.sql.catalyst.expressions.{Alias, AttributeReference, DenseRank, Lag, Lead, NamedExpression, Rank, RowNumber}
import org.apache.spark.sql.catalyst.expressions.{Alias, AttributeReference, DenseRank, Expression, Lag, Lead, Literal, NamedExpression, Rank, RowNumber}
import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning}
import org.apache.spark.sql.execution.SparkPlan
Expand Down Expand Up @@ -225,10 +225,25 @@ object CHBackendSettings extends BackendSettingsApi with Logging {
func => {
val aliasExpr = func.asInstanceOf[Alias]
val wExpression = WindowFunctionsBuilder.extractWindowExpression(aliasExpr.child)

def checkLagOrLead(third: Expression): Unit = {
third match {
case _: Literal =>
allSupported = allSupported
case _ =>
logInfo("Not support lag/lead function with default value not literal null")
allSupported = false
break
}
}

wExpression.windowFunction match {
case _: RowNumber | _: AggregateExpression | _: Rank | _: Lead | _: Lag |
_: DenseRank =>
case _: RowNumber | _: AggregateExpression | _: Rank | _: DenseRank =>
allSupported = allSupported
case l: Lag =>
checkLagOrLead(l.third)
case l: Lead =>
checkLagOrLead(l.third)
case _ =>
logDebug(s"Not support window function: ${wExpression.getClass}")
allSupported = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,15 @@ class GlutenClickHouseTPCHSaltNullParquetSuite extends GlutenClickHouseTPCHAbstr
|from nation
|order by n_regionkey, n_nationkey, n_lag
|""".stripMargin
val sql1 =
"""
| select n_regionkey, n_nationkey,
| lag(n_nationkey, 1, n_nationkey) OVER (PARTITION BY n_regionkey ORDER BY n_nationkey) as n_lag
|from nation
|order by n_regionkey, n_nationkey, n_lag
|""".stripMargin
compareResultsAgainstVanillaSpark(sql, true, { _ => })
compareResultsAgainstVanillaSpark(sql1, true, { _ => }, false)
}

test("window lag with null value") {
Expand Down
Loading