Skip to content

Commit

Permalink
fix fallback due to project
Browse files Browse the repository at this point in the history
  • Loading branch information
shuai-xu committed May 28, 2024
1 parent b2e3de8 commit 07c1af3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ object PullOutPreProject extends RewriteSingleNode with PullOutProjectHelper {
val newAgg = copyBaseAggregateExec(agg)(
newGroupingExpressions = newGroupingExpressions,
newAggregateExpressions = newAggregateExpressions)
// ISSUE-5852: literals with same names are lost in expressionMap, need addback to Project
val missingLiterals =
getMissingLiterals(agg.groupingExpressions)
val expressions = expressionMap.values.toSeq ++ missingLiterals
val preProject = ProjectExec(
eliminateProjectList(agg.child.outputSet, expressionMap.values.toSeq),
eliminateProjectList(agg.child.outputSet, expressions),
agg.child)
newAgg.withNewChildren(Seq(preProject))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ trait PullOutProjectHelper {
case alias: Alias =>
alias.child match {
case _: Literal =>
projectExprsMap.getOrElseUpdate(alias.child.canonicalized, alias)
alias.toAttribute
case _ =>
projectExprsMap.getOrElseUpdate(alias.child.canonicalized, alias).toAttribute
Expand All @@ -75,6 +76,19 @@ trait PullOutProjectHelper {
.toAttribute
}

protected def getMissingLiterals(exprs: Seq[NamedExpression]): Seq[NamedExpression] = {
val literalMap = new mutable.HashMap[Expression, NamedExpression]()
exprs.filter({
case alias: Alias =>
alias.child match {
case _: Literal =>
literalMap.put(alias.child.canonicalized, alias).nonEmpty
case _ => false
}
case _ => false
})
}

/**
* Append the pulled-out NamedExpressions after the child output and eliminate the duplicated
* parts in the append.
Expand Down

0 comments on commit 07c1af3

Please sign in to comment.