maropu commented on a change in pull request #29776:
URL: https://github.com/apache/spark/pull/29776#discussion_r489835439
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala
##########
@@ -85,6 +85,36 @@ class CodegenExpressionCachingSuite extends SparkFunSuite {
assert(instance2.eval(null))
}
+ test("SPARK-32903: GeneratePredicate should eliminate sub-expressions") {
+ Seq(true, false).foreach { enabled =>
Review comment:
nit: `enabled` -> `useSubexprElimination` for readability?
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GeneratePredicate.scala
##########
@@ -30,9 +30,17 @@ object GeneratePredicate extends CodeGenerator[Expression,
BasePredicate] {
protected def bind(in: Expression, inputSchema: Seq[Attribute]): Expression =
BindReferences.bindReference(in, inputSchema)
- protected def create(predicate: Expression): BasePredicate = {
+ def generate(expressions: Expression, useSubexprElimination: Boolean):
BasePredicate =
+ create(canonicalize(expressions), useSubexprElimination)
+
+ protected def create(predicate: Expression): BasePredicate =
create(predicate, false)
+
+ protected def create(predicate: Expression, useSubexprElimination: Boolean):
BasePredicate = {
val ctx = newCodeGenContext()
- val eval = predicate.genCode(ctx)
+
+ // Do sub-expression elimination for predicates.
+ val eval = ctx.generateExpressions(Seq(predicate),
useSubexprElimination)(0)
Review comment:
nit: `useSubexprElimination)(0)` -> `useSubexprElimination).head`
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodegenExpressionCachingSuite.scala
##########
@@ -85,6 +85,36 @@ class CodegenExpressionCachingSuite extends SparkFunSuite {
assert(instance2.eval(null))
}
Review comment:
Just a suggestion; Is this file a right place to add this kind of tests?
Looked around the related suite files in `expressions/codegen/`, I couldn't
find existing tests for common subexpr elimination in
`GenerateMutableProjection` and `GenerateUnsafeProjection`. So, why don't you
create a new test suite (`CodegenSubexpressionEliminationSuite` or something)
and then add this test there? To improve test coverage, it might be better to
add tests having the same granularity for the two projections in a separate PR.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]