-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26448][SQL][followup] should not normalize grouping expressions for final aggregate #23692
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 all 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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import org.apache.spark.sql.catalyst.InternalRow | |
| import org.apache.spark.sql.catalyst.encoders.RowEncoder | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression | ||
| import org.apache.spark.sql.catalyst.optimizer.NormalizeFloatingNumbers | ||
| import org.apache.spark.sql.catalyst.planning._ | ||
| import org.apache.spark.sql.catalyst.plans._ | ||
| import org.apache.spark.sql.catalyst.plans.logical._ | ||
|
|
@@ -331,8 +332,17 @@ abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
|
|
||
| val stateVersion = conf.getConf(SQLConf.STREAMING_AGGREGATION_STATE_FORMAT_VERSION) | ||
|
|
||
| // Ideally this should be done in `NormalizeFloatingNumbers`, but we do it here because | ||
|
||
| // `groupingExpressions` is not extracted during logical phase. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be refactored after https://issues.apache.org/jira/browse/SPARK-25914?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea |
||
| val normalizedGroupingExpressions = namedGroupingExpressions.map { e => | ||
| NormalizeFloatingNumbers.normalize(e) match { | ||
| case n: NamedExpression => n | ||
| case other => Alias(other, e.name)(exprId = e.exprId) | ||
| } | ||
| } | ||
|
|
||
| aggregate.AggUtils.planStreamingAggregation( | ||
| namedGroupingExpressions, | ||
| normalizedGroupingExpressions, | ||
| aggregateExpressions.map(expr => expr.asInstanceOf[AggregateExpression]), | ||
| rewrittenResultExpressions, | ||
| stateVersion, | ||
|
|
@@ -414,16 +424,25 @@ abstract class SparkStrategies extends QueryPlanner[SparkPlan] { | |
| "Spark user mailing list.") | ||
| } | ||
|
|
||
| // Ideally this should be done in `NormalizeFloatingNumbers`, but we do it here because | ||
| // `groupingExpressions` is not extracted during logical phase. | ||
| val normalizedGroupingExpressions = groupingExpressions.map { e => | ||
| NormalizeFloatingNumbers.normalize(e) match { | ||
| case n: NamedExpression => n | ||
| case other => Alias(other, e.name)(exprId = e.exprId) | ||
| } | ||
| } | ||
|
|
||
| val aggregateOperator = | ||
| if (functionsWithDistinct.isEmpty) { | ||
| aggregate.AggUtils.planAggregateWithoutDistinct( | ||
| groupingExpressions, | ||
| normalizedGroupingExpressions, | ||
| aggregateExpressions, | ||
| resultExpressions, | ||
| planLater(child)) | ||
| } else { | ||
| aggregate.AggUtils.planAggregateWithOneDistinct( | ||
| groupingExpressions, | ||
| normalizedGroupingExpressions, | ||
| functionsWithDistinct, | ||
| functionsWithoutDistinct, | ||
| resultExpressions, | ||
|
|
||
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.
A small refactor so that we can retain the alias when normalizing.