saurabh-net opened a new pull request, #60776: URL: https://github.com/apache/spark/pull/60776
### What changes were proposed in this pull request? This is the Catalyst-internal patch (PR #1a, no public API changes) for [SPARK-62199](https://issues.apache.org/jira/browse/SPARK-62199) ([SPIP design doc](https://docs.google.com/document/d/1fgUl8U-RfUPdcvbcrc3C_gIoyN4GWQcIPjnD6uj-gOg/edit)). - Add opt-in `Expression.rowOrderIndependent` (defaulting conservatively to `deterministic` via a cached `ClassValue` override check that catches `LinkageError`, so `false` for all existing nondeterministic expressions and legacy `.asNondeterministic()` UDFs) and `StaticInvoke.isRowOrderIndependent = false`. - Gate relaxed Catalyst rewrites behind an internal kill-switch `SQLConf` (`spark.sql.optimizer.rowOrderIndependentNondeterministicPushdown.enabled`, default `true`): - `PushPredicateThroughNonJoin`: allow disjoint predicates, `DynamicPruningSubquery`, and `BloomFilterMightContain` across row-order-independent `Project`, grouped `Aggregate`, and row-preserving `UnaryNode` (`Sort`, `Repartition*`, `EvalPython`) while preserving written-order ANSI/throwable barriers. - `CollapseProject`: inline single-reference non-lambda row-order-independent expressions in `mergeProjectExpressions` while keeping `canCollapseExpressions` unchanged (deterministic-only for `CombineUnions`, `patterns.scala`, and `V2ScanRelationPushDown`). - `OperationHelper.collectProjectsAndFilters` (`patterns.scala`), `PushDownLeftSemiAntiJoin`, and `V2ScanRelationPushDown.pushDownOffset`: allow pushdown across row-order-independent projections. - Keep `PushProjectionThroughLimitAndOffset` deterministic-only (preventing per-partition fan-out under `LocalLimit` and evaluation on rows dropped by `GlobalLimit` / `Offset`) and keep `ExpressionSet` / multi-ref `InlineCTE` barriers intact. - Add an always-on `isDeterministic` guard in `V2ExpressionBuilder` for `ApplyFunctionExpression`, `Invoke`, and `StaticInvoke`. Public UDF, DSv2 `ScalarFunction`, PySpark, and Spark Connect opt-in APIs are separated into a follow-up SPIP-scoped PR (PR #1b). Random-IV `aes_encrypt` (SPARK-59768 / PR #58867, SPARK-60934 / PR #60178) is proposed as the first in-tree caller via a 2-line follow-up once sequencing is agreed on `dev@spark`. ### Why are the changes needed? `Expression.deterministic` currently conflates value repeatability with row-order, row-subset, and task-context dependence ([SPARK-13473](https://issues.apache.org/jira/browse/SPARK-13473)). As a result, Catalyst blocks unrelated filter pushdown, partition pruning, dynamic partition pruning, semi/anti-join pushdown, and DSv2 offset pushdown across nondeterministic projections such as random-IV `aes_encrypt` ([SPARK-59768](https://issues.apache.org/jira/browse/SPARK-59768), [SPARK-60934](https://issues.apache.org/jira/browse/SPARK-60934)) and external/AI UDFs ([SPARK-61672](https://issues.apache.org/jira/browse/SPARK-61672), [SPARK-61404](https://issues.apache.org/jira/browse/SPARK-61404)). Distinguishing per-row value-only nondeterminism (`rowOrderIndependent = true`, `deterministic = false`) lets Catalyst push unrelated filters below these projections while keeping `deterministic == false` invariants (`rand()`, `uuid()`, `monotonically_increasing_id()`, multi-ref CTE sharing, ANSI error ordering, and limit barriers) intact. ### Does this PR introduce _any_ user-facing change? No behavior change for existing expressions or legacy `.asNondeterministic()` UDFs (aside from the standalone `isDeterministic` correctness guard in `V2ExpressionBuilder`). ### How was this patch tested? - Added unit and integration suites: `RowOrderIndependentExpressionSuite` (built-in `FunctionRegistry` sweep, custom subclasses, `ClassLoader` `LinkageError` conservative fallback) and `RowOrderIndependentPushdownSuite` (Parquet/DSv2 pruning, DPP, multi-partition `LIMIT` call-count guard, ANSI barriers, kill-switch). - Extended `FilterPushdownSuite`, `CollapseProjectSuite`, `LeftSemiAntiJoinPushDownSuite`, `PhysicalOperationSuite`, `InlineCTESuite`, `InferFiltersFromConstraintsSuite`, `PruneFiltersSuite`, `PushProjectionThroughLimitAndOffsetSuite`, and `DataSourceV2StrategySuite`. - Verified targeted Catalyst and SQL Core suites plus `scalastyle:check` cleanly on `master` (`634e3261`). ### Was this patch authored or co-authored using generative AI tooling? Yes (all changes reviewed, tested, and verified by the author). -- 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]
