-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41631][SQL] Support implicit lateral column alias resolution on Aggregate #39040
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 1 commit
04959c2
6f44c85
725e5ac
660e1d2
fd06094
7d4f80f
b9704d5
777f13a
09480ea
c972738
97ee293
5785943
757cffb
29de892
72991c6
d45fe31
1f55f73
f753529
b9f706f
94d5c9e
d2e75fd
edde37c
fb7b18c
3698cff
e700d6a
8d20986
d952aa7
44d5a3d
ccebc1c
5540b70
338ba11
136a930
5076ad2
2f2dee5
3a5509a
a23debb
b200da0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
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.plans.logical.{Aggregate, LogicalPlan, Proj | |
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.catalyst.trees.TreeNodeTag | ||
| import org.apache.spark.sql.catalyst.trees.TreePattern.LATERAL_COLUMN_ALIAS_REFERENCE | ||
| import org.apache.spark.sql.catalyst.util.toPrettySQL | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
|
|
@@ -101,6 +102,14 @@ object ResolveLateralColumnAliasReference extends Rule[LogicalPlan] { | |
| */ | ||
| val NAME_PARTS_FROM_UNRESOLVED_ATTR = TreeNodeTag[Seq[String]]("name_parts_from_unresolved_attr") | ||
|
|
||
| private def assignAlias(expr: Expression): NamedExpression = { | ||
| expr match { | ||
| case ne: NamedExpression => ne | ||
| case e => | ||
| Alias(e, toPrettySQL(e))() | ||
| } | ||
| } | ||
|
|
||
| override def apply(plan: LogicalPlan): LogicalPlan = { | ||
| if (!conf.getConf(SQLConf.LATERAL_COLUMN_ALIAS_IMPLICIT_ENABLED)) { | ||
| plan | ||
|
|
@@ -172,24 +181,15 @@ object ResolveLateralColumnAliasReference extends Rule[LogicalPlan] { | |
| lcaRef.nameParts, aggExpr) | ||
| } | ||
| } | ||
| val ne = expressionMap.getOrElseUpdate( | ||
| aggExpr.canonicalized, | ||
| ResolveAliases.assignAliases(Seq(UnresolvedAlias(aggExpr))).map { | ||
| // TODO temporarily clear the metadata for an issue found in test | ||
| case a: Alias => a.copy(a.child, a.name)( | ||
| a.exprId, a.qualifier, None, a.nonInheritableMetadataKeys) | ||
| case other => other | ||
| }.head) | ||
| val ne = expressionMap.getOrElseUpdate(aggExpr.canonicalized, assignAlias(aggExpr)) | ||
| newAggExprs += ne | ||
| ne.toAttribute | ||
| case e if groupingExpressions.exists(_.semanticEquals(e)) => | ||
| // TODO one concern here, is condition here be able to match all grouping | ||
|
||
| // expressions? For example, Agg [age + 10] [1 + age + 10], when transforming down, | ||
| // is it possible that (1 + age) + 10, so that it won't be able to match (age + 10) | ||
| // add a test. | ||
| val ne = expressionMap.getOrElseUpdate( | ||
| e.canonicalized, | ||
| ResolveAliases.assignAliases(Seq(UnresolvedAlias(e))).head) | ||
| val ne = expressionMap.getOrElseUpdate(e.canonicalized, assignAlias(e)) | ||
| newAggExprs += ne | ||
| ne.toAttribute | ||
| }.asInstanceOf[NamedExpression] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.