I like it. And I wonder whether we should/need to go one step further: Separate 
out per-query determinism. E.g. current_timestamp() vs rand()
Some vendors also track a different “external action” which is a relative of 
“stateful”. Maybe worthwhile investigating whether they are teh same or merely 
an overlap in effect.
For example send_mail(email) is order independent, but it cannot be pushed 
down/pulled up, or dropped.


On Nov 23, 2026, at 11:51 AM, Saurabh Maurya via dev <[email protected]> 
wrote:

Hi Spark devs,

I'd like to start a discussion on a SPIP exploring how Catalyst can distinguish 
row-order-independent nondeterministic expressions from stateful or 
order-dependent ones.

Today, Expression.deterministic conflates output repeatability with row-order, 
row-subset, and task-context dependence (SPARK-13473). As a result, Catalyst 
blocks unrelated pushdowns across nondeterministic projections, a trade-off 
that recently came up for both random-IV aes_encrypt (SPARK-59768 / PR #58867, 
SPARK-60934 / PR #60178) and AI/external UDFs (SPARK-61672, SPARK-61404 / PR 
#60311).

  -- Before: filter trapped above Project
  Project [id, score]
  +- Filter (dt = '2026-01-15')
     +- Project [id, dt, score_udf(payload) AS score]
        +- FileScan events PartitionFilters: []

  -- After: partition pruned
  Project [id, score_udf(payload) AS score]
  +- FileScan events PartitionFilters: [dt = '2026-01-15']

Other engines separate these two properties so unrelated filters can still push 
down (for example, ClickHouse separates isDeterministic from isStateful, Apache 
Doris separates Volatile from NoneMovableFunction, and Hive separates 
deterministic from stateful in @UDFType), whereas Spark needs an opt-in design 
to keep protecting seeded rand()/uuid() and monotonically_increasing_id().

The proposal adds an opt-in Expression.rowOrderIndependent property (inheriting 
deterministic by default, so false for all existing nondeterministic 
expressions and .asNondeterministic() UDFs). Opting in lets Catalyst push 
unrelated filters, dynamic partition pruning, semi/anti-joins, and DSv2 offsets 
below row-order-independent projections so expensive expressions like random-IV 
encryption or remote UDFs skip filtered-out rows.

Everything relying on deterministic == false stays unchanged: 
rand()/uuid()/monotonically_increasing_id(), multi-ref CTE sharing 
(ReusedExchange, 1x execution), PushProjectionThroughLimitAndOffset, ANSI error 
ordering, and SPARK-59726 PolicyEnforcement barriers.

To make feedback concrete, I put up an initial Catalyst-internal PR (#60776, no 
public API changes) and a stacked [WIP] draft PR (#60778) sketching the UDF, 
DSv2, and Spark Connect APIs.

Does an opt-in Expression.rowOrderIndependent property (vs. extending 
Expression.stateful or another shape) feel like the right abstraction for 
Catalyst?

I am also looking for a PMC shepherd if folks feel this direction is worth 
pursuing.

SPIP document:
https://docs.google.com/document/d/1fgUl8U-RfUPdcvbcrc3C_gIoyN4GWQcIPjnD6uj-gOg/edit

JIRA:
https://issues.apache.org/jira/browse/SPARK-62199

PR #1a (Catalyst-internal):
https://github.com/apache/spark/pull/60776

PR #1b (Public APIs, WIP Draft):
https://github.com/apache/spark/pull/60778

Thanks,
Saurabh Maurya

Reply via email to