-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26572][SQL] fix aggregate codegen result evaluation #23731
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,11 +30,13 @@ import org.apache.spark.SparkException | |
| import org.apache.spark.scheduler.{SparkListener, SparkListenerJobEnd} | ||
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.catalyst.expressions.Uuid | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate.Final | ||
| import org.apache.spark.sql.catalyst.optimizer.ConvertToLocalRelation | ||
| import org.apache.spark.sql.catalyst.plans.logical.{OneRowRelation, Union} | ||
| import org.apache.spark.sql.execution.{FilterExec, QueryExecution, WholeStageCodegenExec} | ||
| import org.apache.spark.sql.execution.aggregate.HashAggregateExec | ||
| import org.apache.spark.sql.execution.exchange.{BroadcastExchangeExec, ReusedExchangeExec, ShuffleExchangeExec} | ||
| import org.apache.spark.sql.execution.joins.BroadcastHashJoinExec | ||
| import org.apache.spark.sql.functions._ | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.test.{ExamplePoint, ExamplePointUDT, SharedSQLContext} | ||
|
|
@@ -2110,4 +2112,28 @@ class DataFrameSuite extends QueryTest with SharedSQLContext { | |
| checkAnswer(res, Row("1-1", 6, 6)) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-26572: fix aggregate codegen result evaluation") { | ||
peter-toth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val baseTable = Seq((1), (1)).toDF("idx") | ||
peter-toth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // BroadcastHashJoinExec with a HashAggregateExec child containing no aggregate expressions | ||
| val distinctWithId = baseTable.distinct().withColumn("id", monotonically_increasing_id()) | ||
|
||
| .join(baseTable, "idx") | ||
| assert(distinctWithId.queryExecution.executedPlan.collectFirst { | ||
| case BroadcastHashJoinExec(_, _, _, _, _, HashAggregateExec(_, _, Seq(), _, _, _, _), _) => | ||
|
||
| true | ||
| }.isDefined) | ||
| checkAnswer(distinctWithId, Seq(Row(1, 25769803776L), Row(1, 25769803776L))) | ||
|
|
||
| // BroadcastHashJoinExec with a HashAggregateExec child containing a Final mode aggregate | ||
| // expression | ||
| val groupByWithId = | ||
| baseTable.groupBy("idx").sum().withColumn("id", monotonically_increasing_id()) | ||
| .join(baseTable, "idx") | ||
| assert(groupByWithId.queryExecution.executedPlan.collectFirst { | ||
| case BroadcastHashJoinExec(_, _, _, _, _, HashAggregateExec(_, _, ae, _, _, _, _), _) | ||
peter-toth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ae.exists(_.mode == Final) => true | ||
| }.isDefined) | ||
| checkAnswer(groupByWithId, Seq(Row(1, 2, 25769803776L), Row(1, 2, 25769803776L))) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick on naming: "variables" are never non-deterministic, only expressions can have the property of being deterministic or not. Two options:
evaluateNondeterministicResultsto emphasis this should (mostly) be used on the results of an output projection list.evaluateRequiredVariablesuses the "variable" notion, so keeping consistency there is fine too.I'm fine either way.
Also, historically Spark SQL's WSCG would use variable names like
evalfor theExprCodetype, e.g.evals: Seq[ExprCode]. Not sure why it started that way but you can see that naming pattern throughout the WSCG code base.Again, your new utility function follows the same names used in
evaluateRequiredVariablesso that's fine. Local consistency is good enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep the consistent naming, +1 for
evaluateNondeterministicVariables.