Skip to content

Commit 3426310

Browse files
committed
another fix
1 parent 003833f commit 3426310

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ class EquivalentExpressions {
6969
*/
7070
def addExprTree(root: Expression, ignoreLeaf: Boolean = true): Unit = {
7171
val skip = root.isInstanceOf[LeafExpression] && ignoreLeaf
72-
// the children of CodegenFallback will not be used to generate code (call eval() instead)
73-
if (!skip && !addExpr(root) && !root.isInstanceOf[CodegenFallback]) {
72+
// There are some special expressions that we should not recurse into children.
73+
// 1. CodegenFallback: it's children will not be used to generate code (call eval() instead)
74+
// 2. ReferenceToExpressions: it's kind of an explicit sub-expression elimination.
75+
val shouldRecurse = root match {
76+
case _: CodegenFallback => false
77+
case _: ReferenceToExpressions => false
78+
case _ => true
79+
}
80+
if (!skip && !addExpr(root) && shouldRecurse) {
7481
root.children.foreach(addExprTree(_, ignoreLeaf))
7582
}
7683
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ class CodegenContext {
110110
}
111111

112112
def declareMutableStates(): String = {
113-
mutableStates.map { case (javaType, variableName, _) =>
113+
mutableStates.distinct.map { case (javaType, variableName, _) =>
114114
s"private $javaType $variableName;"
115115
}.mkString("\n")
116116
}
117117

118118
def initMutableStates(): String = {
119-
mutableStates.map(_._3).mkString("\n")
119+
mutableStates.distinct.map(_._3).mkString("\n")
120120
}
121121

122122
/**

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ case class MapObjects private(
436436

437437
override def nullable: Boolean = true
438438

439-
override def children: Seq[Expression] = Seq(loopVar, lambdaFunction, inputData)
439+
override def children: Seq[Expression] = lambdaFunction :: inputData :: Nil
440440

441441
override def eval(input: InternalRow): Any =
442442
throw new UnsupportedOperationException("Only code-generated evaluation is supported")

sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/TypedAggregateExpression.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ case class TypedAggregateExpression(
126126
override lazy val mergeExpressions: Seq[Expression] = {
127127
val leftBuffer = bufferDeserializer transform {
128128
case a: AttributeReference => a.left
129-
case l: LambdaVariable => l.copy(value = l.value + "_left", isNull = l.isNull + "_left")
130129
}
131130
val rightBuffer = bufferDeserializer transform {
132131
case a: AttributeReference => a.right
133-
case l: LambdaVariable => l.copy(value = l.value + "_right", isNull = l.isNull + "_right")
134132
}
135133
val merged = Invoke(
136134
aggregatorLiteral,

0 commit comments

Comments
 (0)