sunchao commented on code in PR #5867:
URL: https://github.com/apache/datafusion-comet/pull/5867#discussion_r4735095596
##########
spark/src/main/scala/org/apache/comet/rules/CometExecRule.scala:
##########
@@ -1345,9 +1345,13 @@ case class CometExecRule(session: SparkSession,
queryStagePrep: Boolean = false)
// skip a function's arguments (see
`QueryPlanSerde.canShortCircuitNulls`). Spark's
// generated code for an aggregate shares them whatever
// spark.sql.subexpressionElimination.enabled says, and other operators
only when it is on.
+ // Only a project shares however Spark runs it. A filter in whole-stage
code does not
+ // through Spark 4.1, and an aggregate's expressions mix its functions'
inputs, which
+ // share, with its results.
val nativeOp = QueryPlanSerde.withSharedSubexpressions(
op.expressions,
- alwaysShared = op.isInstanceOf[BaseAggregateExec]) {
+ alwaysShared = op.isInstanceOf[BaseAggregateExec],
+ certain = op.isInstanceOf[ProjectExec]) {
Review Comment:
**[P3, non-blocking] Account for interpreted projection's lazy CSE.** With
ANSI and subexpression elimination on, add `spark.sql.codegen.wholeStage=false`
and `spark.sql.codegen.factoryMode=NO_CODEGEN` to the new repeated-lookup
fixture. On its `m = NULL, s = 'abc'` row, Spark's interpreted projection
evaluates the shared cast only when requested, and `element_at` returns NULL
without requesting the key. Here `certain = true` exempts the repeat because
both CSE sets contain it. The dispatched kernel still generates and invokes its
cast helper before checking the map, so it raises `CAST_INVALID_INPUT`. The
base falls back to Spark for this DOUBLE-key lookup. Could the exemption
exclude known interpreted execution and add this fixture variant? The internal
config gives a direct way to exercise the path. [Spark's on-demand
CSE](https://github.com/apache/spark/blob/v4.1.3/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SubExprEvaluationRuntime.scala#L41-L65)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]