You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "peter-toth (via GitHub)" <gi...@apache.org> on 2026/07/19 09:22:56 UTC
[PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
peter-toth opened a new pull request, #57357:
URL: https://github.com/apache/spark/pull/57357
### What changes were proposed in this pull request?
This PR guards the `SupportsPushDownV2Filters` branch of `PushDownUtils.pushFilters` so that only deterministic filters are translated and pushed to the data source; nondeterministic filters are kept as post-scan filters and evaluated by Spark after the scan. This mirrors the fix made for `SupportsPushDownCatalystFilters` in #57235 (SPARK-58112).
### Why are the changes needed?
Before this change the `SupportsPushDownV2Filters` branch translated and pushed every conjunct, and `V2ExpressionBuilder` translates `Rand`, so a predicate such as `rand() > 0.5` was pushed to a V2 source.
Pushing a nondeterministic predicate is unsound: the data source may evaluate it a different number of times or at a different point than Spark, and a *partial* push — a predicate used for pruning yet also returned for post-scan re-evaluation (e.g. a parquet row group filter, which is an explicitly documented mode of `SupportsPushDownV2Filters#pushedPredicates`) — evaluates the predicate twice with different results, which can change query results.
This is the same class of problem that #57235 (SPARK-58112) fixed for `SupportsPushDownCatalystFilters`. The other pushdown paths already avoid it:
- `SupportsPushDownFilters` (V1 `sources.Filter`): nondeterministic predicates are untranslatable to `sources.Filter`, so they fall through to post-scan.
- the iterative `PartitionPredicate` second pass: guarded by `PushDownUtils.isPushablePartitionFilter` (`f.deterministic`).
Only the `SupportsPushDownV2Filters` first-pass push was left unguarded; this closes that gap so all pushdown paths handle nondeterministic filters consistently.
### Does this PR introduce _any_ user-facing change?
Yes. Data sources implementing `SupportsPushDownV2Filters` will no longer receive nondeterministic filters through `pushPredicates`; those filters remain in Spark as post-scan filters. For a source that fully enforced such a predicate this is an internal change only; for a source that treated a pushed nondeterministic predicate as a (partial) row group filter, this fixes potentially incorrect results.
### How was this patch tested?
Added a regression test in `DataSourceV2Suite` ("SPARK-58207: V2 filter pushdown skips non-deterministic filters") using `AdvancedDataSourceV2WithV2Filter`: it asserts that `rand() > 0.5` is not pushed to the source (only the deterministic `i > 3` is) and that the nondeterministic filter is retained as a post-scan filter. The test fails on master (the source receives `RAND(...) > 0.5`) and passes with this change.
Also ran `DataSourceV2Suite` and `DataSourceV2EnhancedPartitionFilterSuite` (the latter exercises the iterative `PartitionPredicate` second pass) locally, both green.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3632797773
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
But the flag is not going to work. (If most connectors depend on new behavior, and suddenly we flip it)
One option is:
- a hidden API on SupportsPushdownV2Filters that defaults to false, and javadoc'ed to say 'do not do this unless very sure'
- and a jdbc specific flag to return true
Or not even have a flag works for me as well.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3633021513
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
It's never the *connector* that depends on non-det pushdown. A connector just implements `SupportsPushDownV2Filters` and takes whatever Spark hands it. Getting `rand() > 0.5` pushed in gains it nothing and isn't sound anyway, so no connector author would set a `pushDownNondeterministicPredicates()` capability to true on purpose — it'd be dead API. The thing that can accidentally rely on the old behavior is a user's *workflow* that happened to get the results it wanted out of Spark's weird old behavior, and the person who knows about that workflow isn't the connector author.
So the dependency lives at the query/session level, which is exactly where a `spark.sql.legacy.*` conf belongs: flip the default to the correct behavior now, give the few who built on the old one a temporary, deprecatable switch. And flipping the default can't break a connector — keeping non-det filters post-scan only ever makes results more correct, never crashes a source, so it's purely opt-back-in.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5056491388
Removed the legacy config in 247f5f7032d, per the discussion.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5035680273
Thanks @cloud-fan. I don't think @szehon-ho was suggesting a connector-level enablement as the resolution — he raised it conditionally and seemed fine with a SQL conf otherwise. My own view is a bit stronger: allowing non-det pushdown at all was a mistake, so the default should just be to not push.
That said, if a per-connector control is preferred over the session-wide flag, two options both fix the "too coarse" concern:
(a) Drop the config and add a capability, e.g. `default boolean pushDownNondeterministicPredicates()` (default `false`) on `SupportsPushDownV2Filters`. Though I doubt any real connector wants non-det pushdown, so a new public API feels like overkill.
(b) Keep a legacy config but make it a connector allowlist like `spark.sql.sources.useV1SourceList` (default empty), keyed on the source class name.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5015792760
Thanks for the review @cloud-fan!
Since not pushing non-deterministic filters is a behavior change — some sources were allowed to evaluate some non-deterministic predicates — I added a legacy flag `spark.sql.legacy.allowNonDeterministicV2FilterPushDown` (default off) to restore the old behavior if needed. I also use that flag in the H2 `RAND(1) < bonus` pushdown test so it runs both ways and stays green.
It's in a separate follow-up commit on top of the one you approved.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3618305420
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/PushDownUtils.scala:
##########
@@ -93,6 +93,19 @@ object PushDownUtils extends Logging {
(postScanFilters ++ untranslatableExprs).toImmutableArraySeq)
case r: SupportsPushDownV2Filters =>
+ // Non-deterministic filters must not be pushed down: a data source may evaluate a pushed
Review Comment:
this comment is a bit contradictory, maybe must => should.
as the flag is going to push them down anyway
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/PushDownUtils.scala:
##########
@@ -93,6 +93,19 @@ object PushDownUtils extends Logging {
(postScanFilters ++ untranslatableExprs).toImmutableArraySeq)
case r: SupportsPushDownV2Filters =>
+ // Non-deterministic filters must not be pushed down: a data source may evaluate a pushed
Review Comment:
this comment is a bit contradictory, maybe must => should.
as the flag is going to push them if the user chooses to
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3626331980
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
This does not make sense. This can suddenly break all connectors.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3632797773
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
But the flag is not going to work. (If most connectors depend on new behavior, and suddenly we flip it on)
One option is:
- a hidden API on SupportsPushdownV2Filters that defaults to false, and javadoc'ed to say 'do not do this unless very sure'
- and a jdbc specific flag to return true
Or not even have a flag works for me as well.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5028545927
The SupportsV2PushdownFilter is ugly, iiuc you are saying the first round translates non-deterministic filters, but second round PartiitonPredicate does not.
I think if we go the multi-API approach, we can be more fine grain in keeping the old behavior and having a path forward to fix the new behavior.
1. SupportsPushDownFIlter.pushdownNonDeterministic (default false)
2. SupportsPushDownV2Filter.pushdownNonDeterministic (default true)
3. SupportsPushDownCatalystFilter.pushdownNonDeterministic (default true)
We can just leave out the second round PartitionPredicate and say that never pushdown non-deterministic filter (unless there is a need later), wdyt?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3628726920
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
@aokolnychyi on "is it even safe to push a non-det condition into any connector?" — as I mentioned above, I think the answer is no, and not only because of partial-accept double-evaluation. Even if we (a) document a fully-accept-or-deny rule so nothing is evaluated twice, and (b) push the seed so the RNG sequence is identical, a full push can still change results.
Consider a filter with a translatable non-det predicate (say `rand() > 0.5`) next to a non-translatable one (say `monotonically_increasing_id() < 100`). Only the first gets pushed: it's forced down to the scan and evaluated first, over every scanned row, while the untranslatable one stays post-scan, over the survivors. Splitting and reordering two non-det predicates this way changes which rows the pushed one runs over, so the final result can differ — with a single evaluation and the same seed. It's the same move the optimizer refuses to make elsewhere (`CombineFilters`, `PushPredicateThroughNonJoin`, etc. all gate on `deterministic`).
Given that, on the options:
- The capability method (`pushDownNondeterministicPredicates`) is the one I like least — it's a permanent public API that lets a connector keep depending on a behavior that isn't sound even for a fully-enforcing source. I'd rather not add it.
- On "this can suddenly break all connectors": that's the intended, documented breaking change (there's a migration-guide bullet in the PR). The default now does the safe thing — keep non-det filters post-scan — so nothing silently flips to a worse behavior. The legacy config only lets someone who built on the old behavior restore it, and we can deprecate and remove it later.
So I'd like to land this either as-is (safe default + the legacy config as a temporary, deprecatable escape hatch) or with no flag at all (just never push). Either works for me — I'd just avoid the capability.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3634372103
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
@uros-b is it ok for JDBC connector, if next spark release does not push down non-deterministic filter? (if you work on this area before?)
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #57357: [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters
URL: https://github.com/apache/spark/pull/57357
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3633086988
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
Sounds like we're converging on no flag. That's fine by me. If everyone's ok dropping the conf, I'll drop it tomorrow.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5033474878
Thanks @szehon-ho! We should be really careful with non-deterministic expressions — the optimizer never moves or duplicates them on purpose. So IMO allowing them to be pushed down at all was a mistake. Pushing a non-det filter into a scan is a move, and if a source prunes with it *and* returns it for post-scan re-check, it's also a duplicate.
As I see the three pushdown paths:
- `SupportsPushDownFilters` (V1): never pushed non-det — `sources.Filter` can only carry a pushable column vs a literal, so `rand()` isn't even translatable. Nothing to toggle.
- `SupportsPushDownCatalystFilters`: pushed non-det until SPARK-58112 fixed it. But this is an internal interface (`o.a.s.sql.internal.connector`), not publicly available, and only `FileScanBuilder` implements it — and built-in file sources default to V1 anyway (`spark.sql.sources.useV1SourceList`). So ~no blast radius; correct as-is, no flag needed.
- `SupportsPushDownV2Filters`: the only path with real, tested non-det pushdown (the H2 `RAND(1) < bonus` case in `JDBCV2Suite`), so it's the only one that needs care as a behavior change.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3628726920
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
@aokolnychyi on "is it even safe to push a non-det condition into any connector?" — as I mentioned above, I think the answer is no, and not only because of partial-accept double-evaluation. Even if we (a) document a fully-accept-or-deny rule so nothing is evaluated twice, and (b) push the seed so the RNG sequence is identical, a full push can still change results.
Consider a filter with a translatable non-det predicate (say `rand() > 0.5`) next to a non-translatable one (say `monotonically_increasing_id() < 100`). Only the first gets pushed: it's forced down to the scan and evaluated first, over every scanned row, while the untranslatable one stays post-scan, over the survivors. Splitting and reordering two non-det predicates this way changes which rows the pushed one runs over, so the final result (and the semantics of the query) can differ. It's the same move the optimizer refuses to make elsewhere (`CombineFilters`, `PushPredicateThroughNonJoin`, etc. all gate on `deterministic`).
Given that, on the options:
- The capability method (`pushDownNondeterministicPredicates`) is the one I like least — it's a permanent public API that lets a connector keep depending on a behavior that isn't sound even for a fully-enforcing source. I'd rather not add it.
- On "this can suddenly break all connectors": that's the intended, documented breaking change (there's a migration-guide bullet in the PR). The default now does the safe thing — keep non-det filters post-scan — so nothing silently flips to a worse behavior. The legacy config only lets someone who built on the old behavior restore it, and we can deprecate and remove it later.
So I'd like to land this either as-is (safe default + the legacy config as a temporary, deprecatable escape hatch) or with no flag at all (just never push). Either works for me — I'd just avoid the capability.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5037742559
> Drop the config and add a capability, e.g. default boolean pushDownNondeterministicPredicates() (default false) on SupportsPushDownV2Filters. Though I doubt any real connector wants non-det pushdown, so a new public API feels like overkill.
Yea that's what i had in mind, though it is still a public API? I just see the session-wide conf as too wide, if the goal is to ensure no behavior change for a specific DSV2 connector. I do realize its ugly, but Im leaning towards that at the moment. The whitelist seems more confusing to configure, but maybe there is precedent. Cc @aokolnychyi , will try to talk to him today about it.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3626348125
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
What if the filter is used in multiple places and then it gets pushed in one connector scan and not the other? How do we ensure the pushed filter behaves exactly the same as the one we keep on the Spark side? Is it even safe to push down undeterministic conditions into any connectors?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5015189806
cc @szehon-ho @cloud-fan @dongjoon-hyun — as the author/reviewers of #57235 (SPARK-58112).
Non-deterministic predicate handling looks like a gap in the `SupportsPushDownV2Filters` path as well. #57235 guarded `SupportsPushDownCatalystFilters`, but the V2 `Predicate` branch of `PushDownUtils.pushFilters` still translates and pushes non-deterministic predicates — `V2ExpressionBuilder` translates `Rand`, so `rand() > 0.5` reaches the source. The V1 `sources.Filter` path avoids this (nondeterministic predicates are untranslatable), and the iterative `PartitionPredicate` second pass already guards via `isPushablePartitionFilter`, so this branch is the only one left unguarded.
The gap can be closed either way:
- by this PR — guard the branch and keep nondeterministic filters post-scan, the same approach as #57235; or
- by documenting a "fully accept or fully decline" rule on `SupportsPushDownV2Filters`: a source must never push a nondeterministic predicate partially (prune with it and also return it for post-scan re-check, e.g. as a row group filter), since that evaluates it twice with different results.
WDYT — which direction do you prefer for closing it?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "szehon-ho (via GitHub)" <gi...@apache.org>.
szehon-ho commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5028450921
Thanks for this @peter-toth ! I had some thoughts.
Currently jdbc connector uses SupportsPushDown[V2]Filters, so it should not get the non-deterministic version anyway? But agree there could be some proprietary DSV2 connector out there that depend on it getting pushed down.
So are we saying we want to support this feature fully (pushdown of non-deterministic filter)? If so, just wondering should we have a separate boolean API for each flavor
- SupportsPushDownFIlter
- SupportsPushDownV2Filter
- SupportsPushDownCatalystFilter
That makes more sense as the same Spark could be reading from multiple data source and one flag is too coarse. At the very least , we can make it an API that default to false on SupportsPushDownCatalystFilter? (to prevent behavior change as is the goal here)
Or are we quite sure that not pushing down filter is always correct, then a sql conf make sense.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3628726920
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
@aokolnychyi on "is it even safe to push a non-det condition into any connector?" — as I mentioned above, I think the answer is no, and not only because of partial-accept double-evaluation. Even if we (a) document a fully-accept-or-deny rule so nothing is evaluated twice, and (b) push the seed so the RNG sequence is identical, a full push can still change results.
Consider a filter with a translatable non-det predicate (say `rand() > 0.5`) next to a non-translatable one (say `monotonically_increasing_id() < 100`). Only the first gets pushed: it's forced down to the scan and evaluated first, over every scanned row, while the untranslatable one stays post-scan, over the survivors. Splitting and reordering two non-det predicates this way changes which rows the pushed one runs over, so the final result (and the semantics of the query) can differ — with a single evaluation and the same seed. It's the same move the optimizer refuses to make elsewhere (`CombineFilters`, `PushPredicateThroughNonJoin`, etc. all gate on `deterministic`).
Given that, on the options:
- The capability method (`pushDownNondeterministicPredicates`) is the one I like least — it's a permanent public API that lets a connector keep depending on a behavior that isn't sound even for a fully-enforcing source. I'd rather not add it.
- On "this can suddenly break all connectors": that's the intended, documented breaking change (there's a migration-guide bullet in the PR). The default now does the safe thing — keep non-det filters post-scan — so nothing silently flips to a worse behavior. The legacy config only lets someone who built on the old behavior restore it, and we can deprecate and remove it later.
So I'd like to land this either as-is (safe default + the legacy config as a temporary, deprecatable escape hatch) or with no flag at all (just never push). Either works for me — I'd just avoid the capability.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5061686911
Thanks everyone for the review!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "aokolnychyi (via GitHub)" <gi...@apache.org>.
aokolnychyi commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3626337656
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
If we absolutely need this, then some method on the `SupportsPushDownV2Filters` API would be OKish. That said, are we sure it is always safe to do, even in case of JDBC?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -7864,6 +7864,20 @@ object SQLConf {
.createWithDefault(false)
}
+ val LEGACY_ALLOW_NON_DETERMINISTIC_V2_FILTER_PUSHDOWN =
Review Comment:
Each connector must decide this.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5058976220
Updated the description, thanks @cloud-fan.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #57357:
URL: https://github.com/apache/spark/pull/57357#issuecomment-5059976608
**Merge Summary:**
- merged into master https://github.com/apache/spark/commit/018ad68ccb8994425e2e79f9aa9cefca1f1b4c87
- merged into branch-4.x https://github.com/apache/spark/commit/f633033db3d72bd7c1d4ab547eefb3172731f8f5
*Posted by `merge_spark_pr.py`*
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58207][SQL] Skip pushdown for nondeterministic V2 filters [spark]
Posted by "peter-toth (via GitHub)" <gi...@apache.org>.
peter-toth commented on code in PR #57357:
URL: https://github.com/apache/spark/pull/57357#discussion_r3621808558
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/PushDownUtils.scala:
##########
@@ -93,6 +93,19 @@ object PushDownUtils extends Logging {
(postScanFilters ++ untranslatableExprs).toImmutableArraySeq)
case r: SupportsPushDownV2Filters =>
+ // Non-deterministic filters must not be pushed down: a data source may evaluate a pushed
Review Comment:
Thanks. Fixed in https://github.com/apache/spark/pull/57357/commits/76ebb972a31e0cc32a6bce5e3d159db6c77d1f09.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org