-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24488] [SQL] Fix issue when generator is aliased multiple times #21508
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
44ae34d
46c4a55
f174263
abd1457
5d5e8e5
e9605dc
3021918
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 |
|---|---|---|
|
|
@@ -1621,11 +1621,13 @@ class Analyzer( | |
| expr.find(_.isInstanceOf[Generator]).isDefined | ||
| } | ||
|
|
||
| private def hasNestedGenerator(expr: NamedExpression): Boolean = expr match { | ||
| case UnresolvedAlias(_: Generator, _) => false | ||
| case Alias(_: Generator, _) => false | ||
| case MultiAlias(_: Generator, _) => false | ||
| case other => hasGenerator(other) | ||
| private def hasNestedGenerator(expr: NamedExpression): Boolean = { | ||
| CleanupAliases.trimNonTopLevelAliases(expr) match { | ||
| case UnresolvedAlias(_: Generator, _) => false | ||
|
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. If we do not have a valid case here, we should not add it. Here, I think we just need to handle the resolved alias.
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.
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. done |
||
| case Alias(_: Generator, _) => false | ||
| case MultiAlias(_: Generator, _) => false | ||
| case other => hasGenerator(other) | ||
| } | ||
| } | ||
|
|
||
| private def trimAlias(expr: NamedExpression): Expression = expr match { | ||
|
|
@@ -1666,24 +1668,26 @@ class Analyzer( | |
| // Holds the resolved generator, if one exists in the project list. | ||
| var resolvedGenerator: Generate = null | ||
|
|
||
| val newProjectList = projectList.flatMap { | ||
| case AliasedGenerator(generator, names, outer) if generator.childrenResolved => | ||
| // It's a sanity check, this should not happen as the previous case will throw | ||
| // exception earlier. | ||
| assert(resolvedGenerator == null, "More than one generator found in SELECT.") | ||
|
|
||
| resolvedGenerator = | ||
| Generate( | ||
| generator, | ||
| unrequiredChildIndex = Nil, | ||
| outer = outer, | ||
| qualifier = None, | ||
| generatorOutput = ResolveGenerate.makeGeneratorOutput(generator, names), | ||
| child) | ||
|
|
||
| resolvedGenerator.generatorOutput | ||
| case other => other :: Nil | ||
| } | ||
| val newProjectList = projectList | ||
| .map(CleanupAliases.trimNonTopLevelAliases(_).asInstanceOf[NamedExpression]) | ||
| .flatMap { | ||
| case AliasedGenerator(generator, names, outer) if generator.childrenResolved => | ||
| // It's a sanity check, this should not happen as the previous case will throw | ||
| // exception earlier. | ||
| assert(resolvedGenerator == null, "More than one generator found in SELECT.") | ||
|
|
||
| resolvedGenerator = | ||
| Generate( | ||
| generator, | ||
| unrequiredChildIndex = Nil, | ||
| outer = outer, | ||
| qualifier = None, | ||
| generatorOutput = ResolveGenerate.makeGeneratorOutput(generator, names), | ||
| child) | ||
|
|
||
| resolvedGenerator.generatorOutput | ||
| case other => other :: Nil | ||
| } | ||
|
|
||
| if (resolvedGenerator != null) { | ||
| Project(newProjectList, resolvedGenerator) | ||
|
|
@@ -2394,6 +2398,7 @@ object CleanupAliases extends Rule[LogicalPlan] { | |
| private def trimAliases(e: Expression): Expression = { | ||
| e.transformDown { | ||
| case Alias(child, _) => child | ||
| case MultiAlias(child, _) => child | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2403,6 +2408,8 @@ object CleanupAliases extends Rule[LogicalPlan] { | |
| exprId = a.exprId, | ||
| qualifier = a.qualifier, | ||
| explicitMetadata = Some(a.metadata)) | ||
| case a: MultiAlias => | ||
| a.copy(child = trimAliases(a.child)) | ||
| case other => trimAliases(other) | ||
| } | ||
|
|
||
|
|
||
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.
CleanupAliases.trimNonTopLevelAliasesonly stripsAliasexpressions. Should we also handle the other two cases?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.
Updated to handle the
MultiAliasandUnresolvedAlias, and updated the unit test to test all 3.