You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "SubhamSinghal (via GitHub)" <gi...@apache.org> on 2026/09/18 06:28:35 UTC
[PR] feat(pwmj): support left/right mark joins [datafusion]
SubhamSinghal opened a new pull request, #25467:
URL: https://github.com/apache/datafusion/pull/25467
## Which issue does this PR close?
Part of #17427.
## Rationale for this change
`PiecewiseMergeJoinExec` supported every Semi/Anti existence join but rejected `LeftMark`/`RightMark`, falling back to `NestedLoopJoinExec`. Mark joins answer the same per-row existence question Semi/Anti already answer -- they just keep every row instead of filtering by it, attaching the answer as a boolean `mark` column. No algorithmic reason forces a single range predicate onto the slower path for these.
## What changes are included in this PR?
- `LeftMark` served by `ExistencePWMJStream` (`existence_join.rs`): same watermark as `LeftSemi`/`LeftAnti`, but the final pass emits every buffered row with a `mark` column built from it instead of slicing.
- `RightMark` served by `RightExistencePWMJStream` (`right_existence_join.rs`): buffered-extreme comparison factored into a shared `matched_mask`; `RightMark` keeps every streamed row and appends the comparison as `mark`, folding NULL to `false` (mark is documented to never be NULL).
- `PiecewiseMergeJoinExec::try_new` and the physical planner no longer reject/exclude Mark joins from the PWMJ path.
- `RightMark`'s `maintains_input_order` corrected: appending a column doesn't reorder rows, so it now matches `RightSemi`/`RightAnti` instead of a placeholder `false`.
- Documented (in `try_new`) and pinned (SLT) an invariant: null-aware `LeftMark` (scalar `NOT IN`) can never reach PWMJ, since it always requires a non-empty equi-join `on`, while PWMJ only activates when `on` is empty. `PiecewiseMergeJoinExec` has no `null_aware` field and always builds a non-nullable `mark`, so this must hold.
| | PWMJ | NestedLoopJoin | speedup |
|---|---|---|---|
| LeftMark, all_match | 246 µs | 77.7 ms | ~316× |
| LeftMark, no_match | 224 µs | 78.6 ms | ~350× |
| LeftMark, half_match | 245 µs | 78.6 ms | ~320× |
| RightMark, all_match | 20.5 µs | 78.8 ms | ~3845× |
| RightMark, no_match | 20.4 µs | 78.9 ms | ~3866× |
| RightMark, half_match | 20.5 µs | 78.6 ms | ~3834× |
## What is the testing strategy for this PR?
- Unit tests (`existence_join.rs`, `right_existence_join.rs`): `join_left_mark`, `join_right_mark`, all-NULL-buffered-side cases for both, `RightMark` NaN/-0.0 handling, a `RightMark` NULL-streamed-key case against a non-null buffered extreme, and a `RightMark` coalescer order-preservation case.
- `pwmj.slt`: `LeftMark` has no SQL syntax of its own, so it's reached via `EXISTS` inside a disjunction (`x > 100 OR EXISTS (...)`), with `EXPLAIN` pinning `PiecewiseMergeJoin: join_type=LeftMark`. Covers real NULL buffered keys and List/LargeList/FixedSizeList/Dictionary keys. Also pins that a size-skewed range mark join never gets swapped to `RightMark` (PWMJ's `swap_inputs` is unimplemented) and that the null-aware `NOT IN` invariant above holds, plan and result both.
- `RightMark` has no SQL path today (no optimizer rule constructs it), so it's covered only by unit tests and the fuzz test below.
- `fuzz_pwmj_matches_nested_loop` (`join_fuzz.rs`, `extended_tests`): both Mark types added to the differential fuzz matrix against a `NestedLoopJoinExec` oracle, compared as `(id, mark)` pairs across randomized `i32`/`f64` inputs, operators, partition counts, and NULL/duplicate keys.
- Proto roundtrip tests updated: the wire-rejection test no longer expects Mark types to fail (no wire format change was needed -- the shared `JoinType` enum already covered them), and a new test executes both the original and roundtripped plan and compares output row-for-row, including `mark`.
- `cargo fmt`, `cargo clippy`, and `cargo doc` all pass clean on the touched crates.
## Are there any user-facing changes?
Yes: queries that decorrelate to a `LeftMark`/`RightMark` join with a single range predicate (no equi-join key) and no other filter now use `PiecewiseMergeJoinExec` instead of `NestedLoopJoinExec` -- a plan-shape and performance change, not a semantic one. No public API changes.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#issuecomment-5726118859
benchmark PR: https://github.com/apache/datafusion/pull/24955
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#issuecomment-5726452140
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/25467?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `88.10573%` with `27 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 82.35%. Comparing base ([`3b16a3d`](https://app.codecov.io/gh/apache/datafusion/commit/3b16a3d0eef765b81ce5aad20997b193a42ad02a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`d9507f0`](https://app.codecov.io/gh/apache/datafusion/commit/d9507f0e2fb7ef60e1d04140e3f3c06f17c6e86c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 1 commits behind head on main.
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/25467?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...joins/piecewise\_merge\_join/right\_existence\_join.rs](https://app.codecov.io/gh/apache/datafusion/pull/25467?src=pr&el=tree&filepath=datafusion%2Fphysical-plan%2Fsrc%2Fjoins%2Fpiecewise_merge_join%2Fright_existence_join.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1wbGFuL3NyYy9qb2lucy9waWVjZXdpc2VfbWVyZ2Vfam9pbi9yaWdodF9leGlzdGVuY2Vfam9pbi5ycw==) | 87.30% | [5 Missing and 20 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/25467?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [...n/src/joins/piecewise\_merge\_join/existence\_join.rs](https://app.codecov.io/gh/apache/datafusion/pull/25467?src=pr&el=tree&filepath=datafusion%2Fphysical-plan%2Fsrc%2Fjoins%2Fpiecewise_merge_join%2Fexistence_join.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9waHlzaWNhbC1wbGFuL3NyYy9qb2lucy9waWVjZXdpc2VfbWVyZ2Vfam9pbi9leGlzdGVuY2Vfam9pbi5ycw==) | 93.10% | [0 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/25467?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #25467 +/- ##
========================================
Coverage 82.34% 82.35%
========================================
Files 1137 1137
Lines 432713 432902 +189
Branches 432713 432902 +189
========================================
+ Hits 356338 356508 +170
- Misses 54842 54849 +7
- Partials 21533 21545 +12
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/25467?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4052516026
##########
datafusion/sqllogictest/test_files/pwmj.slt:
##########
@@ -503,6 +503,148 @@ ORDER BY 1 NULLS FIRST;
NULL
1
+# ------------------------------------------------------------------
+# LeftMark via PiecewiseMergeJoin
+# ------------------------------------------------------------------
+
+# `LeftMark` has no SQL syntax of its own -- it is produced by decorrelating an EXISTS/IN
+# subquery that appears inside a disjunction, since the outer filter then needs the
+# subquery's match result (the `mark`) as a value rather than as a row filter. Same data and
+# correlation as the plain-EXISTS `LeftSemi` case above: no `t1.t1_id` is over 100, so the
+# `OR` degenerates to the mark alone and the result is identical -- 11 is the one row whose
+# mark is `false` and is correctly excluded.
+query I
+SELECT t1.t1_id
+FROM join_t1 t1
+WHERE t1.t1_id > 100 OR EXISTS (SELECT 1 FROM join_t2 t2 WHERE t1.t1_id > t2.t2_id)
+ORDER BY 1;
+----
+22
+33
+44
+
+query TT
+EXPLAIN
+SELECT t1.t1_id
+FROM join_t1 t1
+WHERE t1.t1_id > 100 OR EXISTS (SELECT 1 FROM join_t2 t2 WHERE t1.t1_id > t2.t2_id)
+ORDER BY 1;
+----
+logical_plan
+01)Sort: t1.t1_id ASC NULLS LAST
+02)--Projection: t1.t1_id
+03)----Filter: t1.t1_id > Int32(100) OR __correlated_sq_1.mark
+04)------LeftMark Join: Filter: t1.t1_id > __correlated_sq_1.t2_id
+05)--------SubqueryAlias: t1
+06)----------TableScan: join_t1 projection=[t1_id]
+07)--------SubqueryAlias: __correlated_sq_1
+08)----------SubqueryAlias: t2
+09)------------TableScan: join_t2 projection=[t2_id]
+physical_plan
+01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST]
+02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true]
+03)----FilterExec: t1_id@0 > 100 OR mark@1, projection=[t1_id@0]
+04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+05)--------PiecewiseMergeJoin: operator=Gt, join_type=LeftMark, on=(t1_id > t2_id)
+06)----------SortExec: expr=[t1_id@0 ASC], preserve_partitioning=[false]
+07)------------DataSourceExec: partitions=1, partition_sizes=[1]
+08)----------DataSourceExec: partitions=1, partition_sizes=[1]
+
+# `PiecewiseMergeJoinExec::swap_inputs` is unimplemented (`todo!()`), and the physical
+# optimizer's statistics-driven swap subrule (`join_selection.rs`) only ever downcasts to
+# `HashJoinExec`/`CrossJoinExec`/`NestedLoopJoinExec` -- it does not consider
+# `PiecewiseMergeJoinExec` at all. So unlike the equijoin case in `mark_join_matrix.slt`
+# (where a size-skewed `LeftMark` on `HashJoinExec` gets swapped to `RightMark` with inputs
+# flipped), a size-skewed range mark join through PWMJ has nothing to trigger that swap and
+# must stay `LeftMark` regardless of which side is bigger. This pins that: if
+# `swap_inputs` is ever implemented and wired in, this plan changing to `RightMark` is the
+# signal to add real `RightMark` coverage here rather than an accidental behavior change.
+statement ok
+CREATE TABLE pwmj_mark_swap_l(k INT) AS VALUES (1);
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4047078989
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/existence_join.rs:
##########
@@ -462,6 +476,16 @@ pub(super) fn extreme_key(values: &ArrayRef, descending: bool) -> Result<ArrayRe
extreme.to_array_of_size(1)
}
+/// Builds the `LeftMark` `mark` column from the watermark: `false` for the unmatched prefix
+/// `[0, min_marked)`, `true` for the matched suffix `[min_marked, len)` -- the same split
+/// `LeftSemi`/`LeftAnti` slice the buffered batch on, just kept as one column instead of used
+/// to drop rows.
+fn mark_column(len: usize, min_marked: usize) -> ArrayRef {
+ let mut mark = vec![false; len];
+ mark[min_marked..].fill(true);
+ Arc::new(BooleanArray::from(mark))
Review Comment:
```suggestion
let mut mark = BooleanBufferBuilder::new(len);
mark.append_n(min_marked, false);
mark.append_n(len - min_marked, true);
Arc::new(BooleanArray::new(mark.finish(), None))
```
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/right_existence_join.rs:
##########
@@ -325,6 +340,26 @@ impl RightExistencePWMJStream {
// latter so the stream's declared schema is what it yields.
Ok(RecordBatch::try_new(Arc::clone(&self.schema), columns)?)
}
+
+ /// Keeps every streamed row -- nothing is filtered -- and appends the comparison against
+ /// the single buffered extreme as a `mark` column: `true` where some buffered row
+ /// matches, `false` everywhere else, including where the streamed key is NULL (the `mark`
+ /// column is documented never to be NULL; see `JoinType::LeftMark`).
+ fn mark_streamed_batch(&self, batch: &RecordBatch) -> Result<RecordBatch> {
+ let mark: ArrayRef = match self.matched_mask(batch)? {
+ None => Arc::new(BooleanArray::from(vec![false; batch.num_rows()])),
Review Comment:
```suggestion
None => Arc::new(BooleanArray::new(
BooleanBuffer::new_unset(batch.num_rows()),
None,
)),
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #25467:
URL: https://github.com/apache/datafusion/pull/25467
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#issuecomment-5748323707
Thanks @SubhamSinghal @kumarUjjawal @comphead 🚀
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4052513334
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/exec.rs:
##########
@@ -320,14 +320,21 @@ impl PiecewiseMergeJoinExec {
join_type: JoinType,
num_partitions: usize,
) -> Result<Self> {
- // Semi/Anti joins are handled by the existence streams; Mark joins are not
- // supported yet.
- if is_existence_join(join_type) && !is_supported_existence_join(join_type) {
- return not_impl_err!(
- "Existence join {join_type} is currently not supported for PiecewiseMergeJoin"
- );
- }
-
+ // There is no `null_aware` parameter here, unlike `HashJoinExec::try_new`: this
+ // constructor cannot express a null-aware mark join (see `JoinType::LeftMark`'s
+ // scalar-`NOT IN` variant, where `mark` is nullable), and `mark_streamed_batch`/
+ // `emit_matched` always build a non-nullable `mark` column. That is only sound
+ // because a null-aware mark join can never reach here: `decorrelate_predicate_subquery`
+ // only sets `null_aware` when the whole predicate is pure hash-equality with no
+ // residual (`mark_filter_is_hashable_only`), which means `join_on` is always
+ // non-empty for one -- and the PWMJ branch in `physical_planner.rs` only ever
+ // constructs this exec when `join_on` is empty. If either side of that ever changes
+ // (the PWMJ gate growing to accept a residual equijoin condition alongside a range
+ // predicate -- see the `TODO` on that branch -- or decorrelation producing
+ // `null_aware` from something other than a pure-equality predicate), this invariant
+ // breaks silently: a null-aware mark join would compute a plain boolean `mark` where
+ // SQL requires `NULL` (`UNKNOWN`), and nothing here would notice.
+ //
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#issuecomment-5726956461
@comphead @kumarUjjawal PR for left and right mark join
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4048193912
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/exec.rs:
##########
@@ -320,14 +320,21 @@ impl PiecewiseMergeJoinExec {
join_type: JoinType,
num_partitions: usize,
) -> Result<Self> {
- // Semi/Anti joins are handled by the existence streams; Mark joins are not
- // supported yet.
- if is_existence_join(join_type) && !is_supported_existence_join(join_type) {
- return not_impl_err!(
- "Existence join {join_type} is currently not supported for PiecewiseMergeJoin"
- );
- }
-
+ // There is no `null_aware` parameter here, unlike `HashJoinExec::try_new`: this
+ // constructor cannot express a null-aware mark join (see `JoinType::LeftMark`'s
+ // scalar-`NOT IN` variant, where `mark` is nullable), and `mark_streamed_batch`/
+ // `emit_matched` always build a non-nullable `mark` column. That is only sound
+ // because a null-aware mark join can never reach here: `decorrelate_predicate_subquery`
+ // only sets `null_aware` when the whole predicate is pure hash-equality with no
+ // residual (`mark_filter_is_hashable_only`), which means `join_on` is always
+ // non-empty for one -- and the PWMJ branch in `physical_planner.rs` only ever
+ // constructs this exec when `join_on` is empty. If either side of that ever changes
+ // (the PWMJ gate growing to accept a residual equijoin condition alongside a range
+ // predicate -- see the `TODO` on that branch -- or decorrelation producing
+ // `null_aware` from something other than a pure-equality predicate), this invariant
+ // breaks silently: a null-aware mark join would compute a plain boolean `mark` where
+ // SQL requires `NULL` (`UNKNOWN`), and nothing here would notice.
+ //
Review Comment:
This comment's central claim is false. It says that if the invariant breaks, "a null-aware mark join would compute a plain boolean `mark` where SQL requires `NULL` ... and nothing here would notice." The planner already notices, unconditionally:
```rust
// physical_planner.rs:1609-1614
if *null_aware && join_on.is_empty() {
return plan_err!(
"null_aware {join_type} join requires equi-join keys, but the join has none"
);
}
```
That runs before the `let join = if join_on.is_empty() { ... }` branch that constructs this exec, so for `null_aware == true` either `join_on` is non-empty (and the PWMJ branch is not taken) or it is empty (and planning fails). PWMJ cannot see a null-aware join, by explicit guard rather than by emergent reasoning.
So the 16 lines reconstructing `decorrelate_predicate_subquery`'s behavior are both unnecessary and misleading: they tell a maintainer the property is unguarded when it is enforced five statements earlier in the same function. Two lines pointing at that guard carry the whole argument, and stay true if decorrelation changes.
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/utils.rs:
##########
@@ -20,35 +20,13 @@ use datafusion_expr::JoinType;
// Returns boolean for whether the join is a right existence join served by
// `RightExistencePWMJStream`, which reads nothing but a single min/max off the buffered side.
//
-// `RightMark` is deliberately excluded even though it is a right existence join: it needs the
-// buffered side walked in order and an extra boolean column, so it must not inherit this
-// stream's relaxed input requirements if the `try_new` gate is ever loosened.
+// `RightMark` belongs here too: deciding its mark column is the same one-key comparison as
+// `RightSemi`/`RightAnti`, just kept instead of used to filter, so it needs no more of the
+// buffered side than they do.
pub(super) fn is_supported_right_existence_join(join_type: JoinType) -> bool {
Review Comment:
With `is_existence_join` and `is_supported_existence_join` gone, "supported" no longer distinguishes anything: every existence join is supported now. The name reads as though some right existence join is still rejected. `is_right_existence_join` says what it tests.
##########
datafusion/proto/tests/cases/plans/joins.rs:
##########
@@ -1079,3 +1062,89 @@ async fn roundtrip_planned_piecewise_merge_join() -> Result<()> {
}
Ok(())
}
+
+/// `roundtrip_test`/`roundtrip_test_and_return` only compare the `Debug` string of the
+/// before/after plans -- which, per their own doc comment, "often isn't sufficient to
+/// guarantee that no information is lost during serde because the string representation of
+/// a plan often only shows a subset of state". `LeftMark`/`RightMark` add no new field to
+/// encode (`join_type` already selects them from the shared proto enum, see
+/// `join_type_to_proto`/`join_type_from_proto`), so the real risk is not a missing wire field
+/// but a decoded plan that behaves differently at execution time. This actually executes both
+/// the original and the roundtripped plan over real data and compares their output batches
+/// row for row, including the `mark` column.
+#[tokio::test]
+async fn roundtrip_piecewise_merge_join_mark_executes_correctly() -> Result<()> {
Review Comment:
Drop this. `roundtrip_piecewise_merge_join` above already round-trips both Mark types, and its field-count assertion (4 for `LeftMark`, 3 for `RightMark`) is by itself proof that `join_type` survived the wire: no other join type produces those widths, and the exec derives everything else from the six constructor arguments inside `try_new`. Executing both Mark types over real data is what `fuzz_pwmj_matches_nested_loop` does, across randomized inputs, operators and partition counts, rather than one hand-built four-row case.
The doc comment argues the Debug-string comparison is too weak, which is true in general, but the PR description also establishes there is no new wire field here. 75 lines and three new imports (`Int64Array`, `RecordBatch`, `MemorySourceConfig`) for the one bit the field-count assertion already pins.
##########
datafusion/sqllogictest/test_files/pwmj.slt:
##########
@@ -503,6 +503,148 @@ ORDER BY 1 NULLS FIRST;
NULL
1
+# ------------------------------------------------------------------
+# LeftMark via PiecewiseMergeJoin
+# ------------------------------------------------------------------
+
+# `LeftMark` has no SQL syntax of its own -- it is produced by decorrelating an EXISTS/IN
+# subquery that appears inside a disjunction, since the outer filter then needs the
+# subquery's match result (the `mark`) as a value rather than as a row filter. Same data and
+# correlation as the plain-EXISTS `LeftSemi` case above: no `t1.t1_id` is over 100, so the
+# `OR` degenerates to the mark alone and the result is identical -- 11 is the one row whose
+# mark is `false` and is correctly excluded.
+query I
+SELECT t1.t1_id
+FROM join_t1 t1
+WHERE t1.t1_id > 100 OR EXISTS (SELECT 1 FROM join_t2 t2 WHERE t1.t1_id > t2.t2_id)
+ORDER BY 1;
+----
+22
+33
+44
+
+query TT
+EXPLAIN
+SELECT t1.t1_id
+FROM join_t1 t1
+WHERE t1.t1_id > 100 OR EXISTS (SELECT 1 FROM join_t2 t2 WHERE t1.t1_id > t2.t2_id)
+ORDER BY 1;
+----
+logical_plan
+01)Sort: t1.t1_id ASC NULLS LAST
+02)--Projection: t1.t1_id
+03)----Filter: t1.t1_id > Int32(100) OR __correlated_sq_1.mark
+04)------LeftMark Join: Filter: t1.t1_id > __correlated_sq_1.t2_id
+05)--------SubqueryAlias: t1
+06)----------TableScan: join_t1 projection=[t1_id]
+07)--------SubqueryAlias: __correlated_sq_1
+08)----------SubqueryAlias: t2
+09)------------TableScan: join_t2 projection=[t2_id]
+physical_plan
+01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST]
+02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true]
+03)----FilterExec: t1_id@0 > 100 OR mark@1, projection=[t1_id@0]
+04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+05)--------PiecewiseMergeJoin: operator=Gt, join_type=LeftMark, on=(t1_id > t2_id)
+06)----------SortExec: expr=[t1_id@0 ASC], preserve_partitioning=[false]
+07)------------DataSourceExec: partitions=1, partition_sizes=[1]
+08)----------DataSourceExec: partitions=1, partition_sizes=[1]
+
+# `PiecewiseMergeJoinExec::swap_inputs` is unimplemented (`todo!()`), and the physical
+# optimizer's statistics-driven swap subrule (`join_selection.rs`) only ever downcasts to
+# `HashJoinExec`/`CrossJoinExec`/`NestedLoopJoinExec` -- it does not consider
+# `PiecewiseMergeJoinExec` at all. So unlike the equijoin case in `mark_join_matrix.slt`
+# (where a size-skewed `LeftMark` on `HashJoinExec` gets swapped to `RightMark` with inputs
+# flipped), a size-skewed range mark join through PWMJ has nothing to trigger that swap and
+# must stay `LeftMark` regardless of which side is bigger. This pins that: if
+# `swap_inputs` is ever implemented and wired in, this plan changing to `RightMark` is the
+# signal to add real `RightMark` coverage here rather than an accidental behavior change.
+statement ok
+CREATE TABLE pwmj_mark_swap_l(k INT) AS VALUES (1);
Review Comment:
This pins the absence of a rewrite that cannot fire. As the comment itself establishes, `join_selection.rs` only ever downcasts to `HashJoinExec`/`CrossJoinExec`/`NestedLoopJoinExec`, so no amount of size skew reaches `PiecewiseMergeJoinExec::swap_inputs`. The cost is a 1000-row `generate_series` table and a `DataSourceExec: partitions=4, partition_sizes=[1, 0, 0, 0]` pin that any change to `target_partitions` defaults or `generate_series` partitioning will break, for a signal that a `todo!()` nobody calls is still uncalled.
If the concern is that implementing `swap_inputs` later silently produces a `RightMark` with no coverage, the durable place to state that is a comment on `swap_inputs` itself.
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/exec.rs:
##########
@@ -705,8 +713,10 @@ impl ExecutionPlan for PiecewiseMergeJoinExec {
match self.join_type {
// Right existence joins never read a buffered *row*, only a single min/max over
// the whole side, so they fold the buffered input away as it arrives instead of
- // collecting it.
- JoinType::RightSemi | JoinType::RightAnti => {
+ // collecting it. `RightMark` decides its `mark` column with the exact same
+ // comparison as `RightSemi`/`RightAnti` -- it just keeps every row instead of
+ // filtering by it -- so it takes the same path.
+ JoinType::RightSemi | JoinType::RightAnti | JoinType::RightMark => {
Review Comment:
This hardcodes the right-existence set while `required_input_ordering`, `input_distribution_requirements`, and `benefits_from_input_partitioning` all derive it from `is_supported_right_existence_join`. Four sites, three sharing a predicate and one spelling it out.
The two have to agree: this arm selects `RightExistencePWMJStream`, which reads the buffered side unordered and multi-partition, and the predicate is what asks for those relaxed requirements. If they drift, a join type gets routed to a stream whose input requirements were never requested, which is a wrong-answer bug rather than a compile error. Call the predicate here too.
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/existence_join.rs:
##########
@@ -462,6 +476,16 @@ pub(super) fn extreme_key(values: &ArrayRef, descending: bool) -> Result<ArrayRe
extreme.to_array_of_size(1)
}
+/// Builds the `LeftMark` `mark` column from the watermark: `false` for the unmatched prefix
+/// `[0, min_marked)`, `true` for the matched suffix `[min_marked, len)` -- the same split
+/// `LeftSemi`/`LeftAnti` slice the buffered batch on, just kept as one column instead of used
+/// to drop rows.
+fn mark_column(len: usize, min_marked: usize) -> ArrayRef {
+ let mut mark = vec![false; len];
+ mark[min_marked..].fill(true);
+ Arc::new(BooleanArray::from(mark))
Review Comment:
Once @jayzhan211's `BooleanBufferBuilder` form lands, this is four lines with one caller. Inline it into `emit_matched` and drop the helper plus its four-line doc comment, which restates the arm that calls it.
Supporting their suggestion rather than repeating it: `BooleanBuffer::new_unset`/`BooleanBufferBuilder` is already the house pattern for exactly this in the sibling mark implementation, including `nested_loop_join.rs:3226` using `BooleanBuffer::new_unset(right_batch.num_rows())` for the same "no buffered match, mark everything false" case that `mark_streamed_batch` builds with `vec![false; n]`. The current `vec![false; len]` plus `fill(true)` plus bit-packing is three passes and a byte-per-row temporary where the builder is one pass.
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/existence_join.rs:
##########
@@ -409,22 +412,33 @@ impl ExistencePWMJStream {
.load(AtomicOrdering::SeqCst)
.min(buffered_len);
- let sliced = match self.join_type {
+ let (num_rows, columns) = match self.join_type {
JoinType::LeftSemi => {
- buffered_batch.slice(min_marked, buffered_len - min_marked)
+ let sliced =
+ buffered_batch.slice(min_marked, buffered_len - min_marked);
+ (sliced.num_rows(), sliced.columns().to_vec())
+ }
+ // `LeftMark` keeps every buffered row -- nothing to slice -- and appends
+ // the watermark as a `mark` column instead of using it to drop rows.
+ JoinType::LeftMark => {
+ let mut columns = buffered_batch.columns().to_vec();
+ columns.push(mark_column(buffered_len, min_marked));
+ (buffered_len, columns)
+ }
+ // `LeftAnti`: the unmarked prefix, which includes every null-keyed row --
+ // nulls sort first and the watermark never drops below the buffered null
+ // count.
+ _ => {
Review Comment:
This is a three-way dispatch with two arms named and the third left as `_`, documented as `LeftAnti` in a comment. Spell it `JoinType::LeftAnti` and let a fourth join type reaching this stream be a compile error rather than silently taking the anti slice. Same shape as `filter_streamed_batch`'s `_ =>` for `RightAnti`, which is worth the same treatment.
##########
datafusion/sqllogictest/test_files/pwmj.slt:
##########
@@ -1236,6 +1466,130 @@ physical_plan
05)--------DataSourceExec: partitions=1, partition_sizes=[1]
06)------DataSourceExec: partitions=1, partition_sizes=[1]
+# `LeftMark` shares the exact same buffered-side comparator (`JoinKeyComparator`, sorted by
+# `required_input_ordering`) as `LeftSemi`/`LeftAnti` above -- only `emit_matched`'s final step
+# differs (slice vs. `mark` column) -- so this pins that a dictionary key marks correctly
+# through that shared path too. `>` : only 'e' (id 3) is above 'c', same outcome the `EXISTS`
+# query above already pinned for `LeftSemi`.
+query I
+SELECT l.id FROM ex_dict_l l
+WHERE l.id > 100 OR EXISTS (SELECT 1 FROM ex_dict_r r WHERE l.v > r.v) ORDER BY 1;
+----
+3
+
+# ------------------------------------------------------------------
+# Existence joins: LeftMark with List/LargeList/FixedSizeList keys
+# ------------------------------------------------------------------
+
+statement ok
+CREATE TABLE ex_list_l(id INT, v INT[]);
+
+statement ok
+INSERT INTO ex_list_l VALUES (1, [1]), (2, [2]), (3, [4]), (4, [5]);
+
+statement ok
+CREATE TABLE ex_list_r(v INT[]);
+
+statement ok
+INSERT INTO ex_list_r VALUES ([2]), ([4]);
+
+# `>` : `EXISTS r WHERE l.v > r.v` holds iff `l.v` beats the smallest `r.v` ([2]), which only
+# [4] (id 3) and [5] (id 4) do.
+query I
+SELECT l.id FROM ex_list_l l
+WHERE l.id > 100 OR EXISTS (SELECT 1 FROM ex_list_r r WHERE l.v > r.v) ORDER BY 1;
+----
+3
+4
+
+# `LargeList`/`FixedSizeList` go through the same generic comparator as `List` above
Review Comment:
These roughly 100 lines cover key types through a code path that cannot be key-type sensitive, and the PR says so twice. `pwmj.slt:1469`: "`LeftMark` shares the exact same buffered-side comparator (`JoinKeyComparator`...) as `LeftSemi`/`LeftAnti` above -- only `emit_matched`'s final step differs (slice vs. `mark` column)". That final step is `buffered_batch.columns().to_vec()` plus a boolean column, which cannot observe whether the key was `List`, `LargeList`, `FixedSizeList` or a dictionary. The comparator itself is already covered for all four types by the `LeftSemi`/`LeftAnti` cases above. Keep one nested-key `LeftMark` case as a smoke test and drop `LargeList`, `FixedSizeList` and the dictionary variant.
Same argument shrinks the EXPLAIN volume. `pwmj.slt` goes from 25 to 32 `query TT`, and five of the new ones pin the same shape (`FilterExec ... OR mark@1` over `ProjectionExec` over `PiecewiseMergeJoin: join_type=LeftMark`) with only table and operator names differing: here, at `1505`, and the multi-NULL (`1224`) and `-0.0` (`1308`) blocks, whose comments likewise say they re-pin outcomes already covered for `LeftSemi`/`LeftAnti`. Keep the one canonical `LeftMark` EXPLAIN near the top of the section and make the rest result-only. Every unrelated planner change currently has to update all of them.
##########
datafusion/sqllogictest/test_files/pwmj.slt:
##########
@@ -503,6 +503,148 @@ ORDER BY 1 NULLS FIRST;
NULL
1
+# ------------------------------------------------------------------
+# LeftMark via PiecewiseMergeJoin
+# ------------------------------------------------------------------
+
+# `LeftMark` has no SQL syntax of its own -- it is produced by decorrelating an EXISTS/IN
+# subquery that appears inside a disjunction, since the outer filter then needs the
+# subquery's match result (the `mark`) as a value rather than as a row filter. Same data and
+# correlation as the plain-EXISTS `LeftSemi` case above: no `t1.t1_id` is over 100, so the
+# `OR` degenerates to the mark alone and the result is identical -- 11 is the one row whose
+# mark is `false` and is correctly excluded.
+query I
+SELECT t1.t1_id
+FROM join_t1 t1
+WHERE t1.t1_id > 100 OR EXISTS (SELECT 1 FROM join_t2 t2 WHERE t1.t1_id > t2.t2_id)
+ORDER BY 1;
+----
+22
+33
+44
+
+query TT
+EXPLAIN
+SELECT t1.t1_id
+FROM join_t1 t1
+WHERE t1.t1_id > 100 OR EXISTS (SELECT 1 FROM join_t2 t2 WHERE t1.t1_id > t2.t2_id)
+ORDER BY 1;
+----
+logical_plan
+01)Sort: t1.t1_id ASC NULLS LAST
+02)--Projection: t1.t1_id
+03)----Filter: t1.t1_id > Int32(100) OR __correlated_sq_1.mark
+04)------LeftMark Join: Filter: t1.t1_id > __correlated_sq_1.t2_id
+05)--------SubqueryAlias: t1
+06)----------TableScan: join_t1 projection=[t1_id]
+07)--------SubqueryAlias: __correlated_sq_1
+08)----------SubqueryAlias: t2
+09)------------TableScan: join_t2 projection=[t2_id]
+physical_plan
+01)SortPreservingMergeExec: [t1_id@0 ASC NULLS LAST]
+02)--SortExec: expr=[t1_id@0 ASC NULLS LAST], preserve_partitioning=[true]
+03)----FilterExec: t1_id@0 > 100 OR mark@1, projection=[t1_id@0]
+04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+05)--------PiecewiseMergeJoin: operator=Gt, join_type=LeftMark, on=(t1_id > t2_id)
+06)----------SortExec: expr=[t1_id@0 ASC], preserve_partitioning=[false]
+07)------------DataSourceExec: partitions=1, partition_sizes=[1]
+08)----------DataSourceExec: partitions=1, partition_sizes=[1]
+
+# `PiecewiseMergeJoinExec::swap_inputs` is unimplemented (`todo!()`), and the physical
+# optimizer's statistics-driven swap subrule (`join_selection.rs`) only ever downcasts to
+# `HashJoinExec`/`CrossJoinExec`/`NestedLoopJoinExec` -- it does not consider
+# `PiecewiseMergeJoinExec` at all. So unlike the equijoin case in `mark_join_matrix.slt`
+# (where a size-skewed `LeftMark` on `HashJoinExec` gets swapped to `RightMark` with inputs
+# flipped), a size-skewed range mark join through PWMJ has nothing to trigger that swap and
+# must stay `LeftMark` regardless of which side is bigger. This pins that: if
+# `swap_inputs` is ever implemented and wired in, this plan changing to `RightMark` is the
+# signal to add real `RightMark` coverage here rather than an accidental behavior change.
+statement ok
+CREATE TABLE pwmj_mark_swap_l(k INT) AS VALUES (1);
+
+statement ok
+CREATE TABLE pwmj_mark_swap_r(k INT) AS SELECT * FROM generate_series(1, 1000);
+
+query TT
+EXPLAIN
+SELECT l.k
+FROM pwmj_mark_swap_l l
+WHERE l.k > 100000 OR EXISTS (SELECT 1 FROM pwmj_mark_swap_r r WHERE l.k > r.k)
+ORDER BY 1;
+----
+logical_plan
+01)Sort: l.k ASC NULLS LAST
+02)--Projection: l.k
+03)----Filter: l.k > Int32(100000) OR __correlated_sq_1.mark
+04)------LeftMark Join: Filter: l.k > __correlated_sq_1.k
+05)--------SubqueryAlias: l
+06)----------TableScan: pwmj_mark_swap_l projection=[k]
+07)--------SubqueryAlias: __correlated_sq_1
+08)----------SubqueryAlias: r
+09)------------TableScan: pwmj_mark_swap_r projection=[k]
+physical_plan
+01)SortPreservingMergeExec: [k@0 ASC NULLS LAST]
+02)--SortExec: expr=[k@0 ASC NULLS LAST], preserve_partitioning=[true]
+03)----FilterExec: k@0 > 100000 OR mark@1, projection=[k@0]
+04)------PiecewiseMergeJoin: operator=Gt, join_type=LeftMark, on=(k > k)
+05)--------SortExec: expr=[k@0 ASC], preserve_partitioning=[false]
+06)----------DataSourceExec: partitions=1, partition_sizes=[1]
+07)--------DataSourceExec: partitions=4, partition_sizes=[1, 0, 0, 0]
+
+# `PiecewiseMergeJoinExec::try_new` has no `null_aware` parameter and always builds a
+# non-nullable `mark` column, which is only sound because a null-aware `LeftMark` join (the
+# one scalar `NOT IN` plans, per `JoinType::LeftMark`'s doc) can never reach the PWMJ branch:
+# `decorrelate_predicate_subquery` only sets `null_aware` for a pure hash-equality predicate,
+# which always has a non-empty `join_on`, while PWMJ only activates when `join_on` is empty.
+# This pins the query that null-aware coverage in `null_aware_mark_join.slt` already uses
+# (with `enable_piecewise_merge_join` on, unlike that file) and asserts it still plans to
+# `HashJoinExec ... null_aware`, not `PiecewiseMergeJoin`: if that invariant is ever broken
+# (the PWMJ gate loosened to accept a residual equijoin condition, or decorrelation start
+# setting `null_aware` for something other than a pure-equality predicate), this is the
+# query that should end up on PWMJ and lose its nullable `mark` -- so this plan changing is
+# the signal, not a query that never had a chance to reach PWMJ in the first place.
+statement ok
+CREATE TABLE pwmj_null_aware_l(id INT) AS VALUES (1), (2), (NULL);
Review Comment:
Redundant with the planner guard (see my comment on `exec.rs:323`). `physical_planner.rs:1609` turns a null-aware join with empty `join_on` into a `plan_err!`, so the outcome this block guards against cannot be reached, and the query pinned here is the one the comment admits `null_aware_mark_join.slt` already covers.
The one thing it adds over that file is running with `enable_piecewise_merge_join = true` (which defaults to `false`). That is worth a sentence, not two tables, an EXPLAIN and a duplicated three-valued result assertion: the invariant lives in the `plan_err!`, and deleting that guard already fails its own tests.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4052518760
##########
datafusion/sqllogictest/test_files/pwmj.slt:
##########
@@ -1236,6 +1466,130 @@ physical_plan
05)--------DataSourceExec: partitions=1, partition_sizes=[1]
06)------DataSourceExec: partitions=1, partition_sizes=[1]
+# `LeftMark` shares the exact same buffered-side comparator (`JoinKeyComparator`, sorted by
+# `required_input_ordering`) as `LeftSemi`/`LeftAnti` above -- only `emit_matched`'s final step
+# differs (slice vs. `mark` column) -- so this pins that a dictionary key marks correctly
+# through that shared path too. `>` : only 'e' (id 3) is above 'c', same outcome the `EXISTS`
+# query above already pinned for `LeftSemi`.
+query I
+SELECT l.id FROM ex_dict_l l
+WHERE l.id > 100 OR EXISTS (SELECT 1 FROM ex_dict_r r WHERE l.v > r.v) ORDER BY 1;
+----
+3
+
+# ------------------------------------------------------------------
+# Existence joins: LeftMark with List/LargeList/FixedSizeList keys
+# ------------------------------------------------------------------
+
+statement ok
+CREATE TABLE ex_list_l(id INT, v INT[]);
+
+statement ok
+INSERT INTO ex_list_l VALUES (1, [1]), (2, [2]), (3, [4]), (4, [5]);
+
+statement ok
+CREATE TABLE ex_list_r(v INT[]);
+
+statement ok
+INSERT INTO ex_list_r VALUES ([2]), ([4]);
+
+# `>` : `EXISTS r WHERE l.v > r.v` holds iff `l.v` beats the smallest `r.v` ([2]), which only
+# [4] (id 3) and [5] (id 4) do.
+query I
+SELECT l.id FROM ex_list_l l
+WHERE l.id > 100 OR EXISTS (SELECT 1 FROM ex_list_r r WHERE l.v > r.v) ORDER BY 1;
+----
+3
+4
+
+# `LargeList`/`FixedSizeList` go through the same generic comparator as `List` above
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4052515209
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/existence_join.rs:
##########
@@ -409,22 +412,33 @@ impl ExistencePWMJStream {
.load(AtomicOrdering::SeqCst)
.min(buffered_len);
- let sliced = match self.join_type {
+ let (num_rows, columns) = match self.join_type {
JoinType::LeftSemi => {
- buffered_batch.slice(min_marked, buffered_len - min_marked)
+ let sliced =
+ buffered_batch.slice(min_marked, buffered_len - min_marked);
+ (sliced.num_rows(), sliced.columns().to_vec())
+ }
+ // `LeftMark` keeps every buffered row -- nothing to slice -- and appends
+ // the watermark as a `mark` column instead of using it to drop rows.
+ JoinType::LeftMark => {
+ let mut columns = buffered_batch.columns().to_vec();
+ columns.push(mark_column(buffered_len, min_marked));
+ (buffered_len, columns)
+ }
+ // `LeftAnti`: the unmarked prefix, which includes every null-keyed row --
+ // nulls sort first and the watermark never drops below the buffered null
+ // count.
+ _ => {
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
##########
datafusion/proto/tests/cases/plans/joins.rs:
##########
@@ -1079,3 +1062,89 @@ async fn roundtrip_planned_piecewise_merge_join() -> Result<()> {
}
Ok(())
}
+
+/// `roundtrip_test`/`roundtrip_test_and_return` only compare the `Debug` string of the
+/// before/after plans -- which, per their own doc comment, "often isn't sufficient to
+/// guarantee that no information is lost during serde because the string representation of
+/// a plan often only shows a subset of state". `LeftMark`/`RightMark` add no new field to
+/// encode (`join_type` already selects them from the shared proto enum, see
+/// `join_type_to_proto`/`join_type_from_proto`), so the real risk is not a missing wire field
+/// but a decoded plan that behaves differently at execution time. This actually executes both
+/// the original and the roundtripped plan over real data and compares their output batches
+/// row for row, including the `mark` column.
+#[tokio::test]
+async fn roundtrip_piecewise_merge_join_mark_executes_correctly() -> Result<()> {
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4052513668
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/exec.rs:
##########
@@ -705,8 +713,10 @@ impl ExecutionPlan for PiecewiseMergeJoinExec {
match self.join_type {
// Right existence joins never read a buffered *row*, only a single min/max over
// the whole side, so they fold the buffered input away as it arrives instead of
- // collecting it.
- JoinType::RightSemi | JoinType::RightAnti => {
+ // collecting it. `RightMark` decides its `mark` column with the exact same
+ // comparison as `RightSemi`/`RightAnti` -- it just keeps every row instead of
+ // filtering by it -- so it takes the same path.
+ JoinType::RightSemi | JoinType::RightAnti | JoinType::RightMark => {
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/utils.rs:
##########
@@ -20,35 +20,13 @@ use datafusion_expr::JoinType;
// Returns boolean for whether the join is a right existence join served by
// `RightExistencePWMJStream`, which reads nothing but a single min/max off the buffered side.
//
-// `RightMark` is deliberately excluded even though it is a right existence join: it needs the
-// buffered side walked in order and an extra boolean column, so it must not inherit this
-// stream's relaxed input requirements if the `try_new` gate is ever loosened.
+// `RightMark` belongs here too: deciding its mark column is the same one-key comparison as
+// `RightSemi`/`RightAnti`, just kept instead of used to filter, so it needs no more of the
+// buffered side than they do.
pub(super) fn is_supported_right_existence_join(join_type: JoinType) -> bool {
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(pwmj): support left/right mark joins [datafusion]
Posted by "SubhamSinghal (via GitHub)" <gi...@apache.org>.
SubhamSinghal commented on code in PR #25467:
URL: https://github.com/apache/datafusion/pull/25467#discussion_r4052512840
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/existence_join.rs:
##########
@@ -462,6 +476,16 @@ pub(super) fn extreme_key(values: &ArrayRef, descending: bool) -> Result<ArrayRe
extreme.to_array_of_size(1)
}
+/// Builds the `LeftMark` `mark` column from the watermark: `false` for the unmatched prefix
+/// `[0, min_marked)`, `true` for the matched suffix `[min_marked, len)` -- the same split
+/// `LeftSemi`/`LeftAnti` slice the buffered batch on, just kept as one column instead of used
+/// to drop rows.
+fn mark_column(len: usize, min_marked: usize) -> ArrayRef {
+ let mut mark = vec![false; len];
+ mark[min_marked..].fill(true);
+ Arc::new(BooleanArray::from(mark))
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
##########
datafusion/physical-plan/src/joins/piecewise_merge_join/right_existence_join.rs:
##########
@@ -325,6 +340,26 @@ impl RightExistencePWMJStream {
// latter so the stream's declared schema is what it yields.
Ok(RecordBatch::try_new(Arc::clone(&self.schema), columns)?)
}
+
+ /// Keeps every streamed row -- nothing is filtered -- and appends the comparison against
+ /// the single buffered extreme as a `mark` column: `true` where some buffered row
+ /// matches, `false` everywhere else, including where the streamed key is NULL (the `mark`
+ /// column is documented never to be NULL; see `JoinType::LeftMark`).
+ fn mark_streamed_batch(&self, batch: &RecordBatch) -> Result<RecordBatch> {
+ let mark: ArrayRef = match self.matched_mask(batch)? {
+ None => Arc::new(BooleanArray::from(vec![false; batch.num_rows()])),
Review Comment:
Addressed in 8885ca1914c081f0f5c97984d7248fcf5c18cd7d
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org