rdtr opened a new pull request, #7836: URL: https://github.com/apache/datafusion-comet/pull/7836
## Which issue does this PR close? Closes #7814. ## Rationale for this change With ANSI on, subexpression elimination on and `spark.sql.codegen.factoryMode=NO_CODEGEN`, `SELECT m[CAST(s AS INT)], m2[CAST(s AS INT)] FROM t` raises `CAST_INVALID_INPUT` in Comet on a row where both maps are NULL and `s` is `'bad'`. Spark returns NULL for that row. The native null short-circuit (`canSkipEvaluation` / `canShortCircuitNulls`) keeps an argument evaluated on every row when it holds a subexpression that the operator's expressions share, because Spark's generated code evaluates eliminated subexpressions eagerly. Under NO_CODEGEN Spark runs interpreted projections and aggregates instead, whose `SubExprEvaluationRuntime` evaluates an eliminated subexpression only when an expression asks for it. A lookup on a NULL map never asks for its key, so Spark never evaluates the cast there. ## What changes are included in this PR? `SharedSubexpressions.raising` in `QueryPlanSerde` returns no shared subexpressions when `spark.sql.codegen.factoryMode` is `NO_CODEGEN`, so the lookups skip their keys on NULL rows as Spark does. This is the option suggested in the issue. With generated code (the default `FALLBACK` mode) nothing changes, and the existing `map_null_short_circuit_cse_off.sql` still checks that the aggregate raises there. A projection that falls back to the interpreter after a compile failure in `FALLBACK` mode is not covered, since that is not known when the plan is converted. ## How are these changes tested? New fixture `expressions/map/map_null_short_circuit_no_codegen.sql` with the queries from the issue: the projection and the aggregate return Spark's rows natively, and a key that fails where the map is not NULL still raises `CAST_INVALID_INPUT`. Without the change the fixture fails with `CAST_INVALID_INPUT`. `CometSqlFileTestSuite` passes on Spark 4.1.3 (default profile), and the `short_circuit` fixtures pass on Spark 3.5 and 4.2. -- 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]
