Skip to content

Commit 3ddccc6

Browse files
committed
[SPARK-38333][SQL] PlanExpression expression should skip addExprTree function in Executor
1 parent 9f6aad4 commit 3ddccc6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class EquivalentExpressions {
197197
expr.exists(_.isInstanceOf[LambdaVariable]) ||
198198
// `PlanExpression` wraps query plan. To compare query plans of `PlanExpression` on executor,
199199
// can cause error like NPE.
200-
(expr.isInstanceOf[PlanExpression[_]] && Utils.isInRunningSparkTask)
200+
(expr.exists(_.isInstanceOf[PlanExpression[_]]) && Utils.isInRunningSparkTask)
201201

202202
if (!skip && !updateExprInMap(expr, map, useCount)) {
203203
val uc = useCount.signum

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/SubexpressionEliminationSuite.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
*/
1717
package org.apache.spark.sql.catalyst.expressions
1818

19-
import org.apache.spark.SparkFunSuite
19+
import org.apache.spark.{SparkFunSuite, TaskContext, TaskContextImpl}
2020
import org.apache.spark.sql.catalyst.expressions.codegen._
21+
import org.apache.spark.sql.catalyst.plans.logical.LocalRelation
2122
import org.apache.spark.sql.internal.SQLConf
2223
import org.apache.spark.sql.types.{BinaryType, DataType, Decimal, IntegerType}
2324

@@ -419,6 +420,21 @@ class SubexpressionEliminationSuite extends SparkFunSuite with ExpressionEvalHel
419420
}
420421
}
421422

423+
test("SPARK-38333: PlanExpression expression should skip addExprTree function in Executor") {
424+
try {
425+
// suppose we are in executor
426+
val context1 = new TaskContextImpl(0, 0, 0, 0, 0, null, null, null, cpus = 0)
427+
TaskContext.setTaskContext(context1)
428+
429+
val equivalence = new EquivalentExpressions
430+
val expression = DynamicPruningExpression(Exists(LocalRelation()))
431+
equivalence.addExprTree(expression)
432+
assert(equivalence.getExprState(expression).isEmpty)
433+
} finally {
434+
TaskContext.unset()
435+
}
436+
}
437+
422438
test("SPARK-35886: PromotePrecision should not overwrite genCode") {
423439
val p = PromotePrecision(Literal(Decimal("10.1")))
424440

0 commit comments

Comments
 (0)