Repository navigation
feat: add support for comet cartesian join #6938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coderfender
wants to merge
8
commits into
apache:main
Choose a base branch
from
coderfender:feat_native_cartesian_single_partition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+445
−9
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c9292a
add support for comet cartesian join
coderfender aaca944
address review: make native cartesian product opt-in (default false)
coderfender b57a0df
add benchmarks for comet cartesian join
coderfender e6c48c2
add benchmarks for comet cartesian join move ests to sql file
coderfender 5b702fa
Merge remote-tracking branch 'upstream/main' into feat_native_cartesi…
coderfender 41e3cd6
update documentation per review
coderfender 986b4ec
update documentation per review
coderfender e063de9
Merge remote-tracking branch 'upstream/main' into feat_native_cartesi…
coderfender File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
spark/src/test/resources/sql-tests/join/cartesian_product.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one | ||
| -- or more contributor license agreements. See the NOTICE file | ||
| -- distributed with this work for additional information | ||
| -- regarding copyright ownership. The ASF licenses this file | ||
| -- to you under the Apache License, Version 2.0 (the | ||
| -- "License"); you may not use this file except in compliance | ||
| -- with the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, | ||
| -- software distributed under the License is distributed on an | ||
| -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| -- KIND, either express or implied. See the License for the | ||
| -- specific language governing permissions and limitations | ||
| -- under the License. | ||
|
|
||
| -- Tests for CartesianProductExec, which Spark plans for a cross join with no equi key when | ||
| -- nothing is broadcast. Comet runs it natively only without a condition and when each input | ||
| -- reports exactly one partition. A non-bucketed Parquet scan reports UnknownPartitioning(0), so | ||
| -- each side is coalesced to one partition. Partition coalescing is off so AQE cannot merge the | ||
| -- REPARTITION(2) case, and the tiny advisory size makes AQE try to split the REBALANCE(1) case. | ||
|
|
||
| -- Config: spark.comet.exec.cartesianProduct.enabled=true | ||
| -- Config: spark.sql.autoBroadcastJoinThreshold=-1 | ||
| -- Config: spark.sql.adaptive.autoBroadcastJoinThreshold=-1 | ||
| -- Config: spark.sql.adaptive.coalescePartitions.enabled=false | ||
| -- Config: spark.sql.adaptive.advisoryPartitionSizeInBytes=1k | ||
| -- ConfigMatrix: spark.sql.adaptive.enabled=true,false | ||
|
|
||
| statement | ||
| CREATE TABLE cp_left(k int, v int) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO cp_left VALUES (0, 10), (NULL, 11), (2, NULL), (NULL, NULL) | ||
|
|
||
| statement | ||
| CREATE TABLE cp_right(k int, v int) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO cp_right VALUES (0, 100), (NULL, NULL) | ||
|
|
||
| statement | ||
| CREATE TABLE cp_empty(k int, v int) USING parquet | ||
|
|
||
| statement | ||
| CREATE TABLE cp_large(k int, v int) USING parquet | ||
|
|
||
| -- More rows than the default batch size of 8192. | ||
| statement | ||
| INSERT INTO cp_large SELECT id, id FROM range(10000) | ||
|
|
||
| -- Native, with NULLs on both sides | ||
| query | ||
| SELECT * FROM (SELECT /*+ COALESCE(1) */ * FROM cp_left) l | ||
| CROSS JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_right) r | ||
|
|
||
| -- Native, empty left side (the side CrossJoinExec buffers) | ||
| query | ||
| SELECT * FROM (SELECT /*+ COALESCE(1) */ * FROM cp_empty) l | ||
| CROSS JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_right) r | ||
|
|
||
| -- Native, empty right side | ||
| query | ||
| SELECT * FROM (SELECT /*+ COALESCE(1) */ * FROM cp_left) l | ||
| CROSS JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_empty) r | ||
|
|
||
| -- Native, right side spanning several batches | ||
| query | ||
| SELECT * FROM (SELECT /*+ COALESCE(1) */ * FROM cp_left) l | ||
| CROSS JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_large) r | ||
|
|
||
| -- Native, AQE must not split the REBALANCE(1) input into several partitions | ||
| query | ||
| SELECT * FROM (SELECT /*+ REBALANCE(1) */ * FROM cp_large) l | ||
| CROSS JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_right) r | ||
|
|
||
| -- A join condition falls back to Spark | ||
| query expect_fallback(CartesianProduct with a join condition is not supported natively) | ||
| SELECT * FROM (SELECT /*+ COALESCE(1) */ * FROM cp_left) l | ||
| JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_right) r ON l.v > r.v | ||
|
|
||
| -- A multi-partition input falls back to Spark | ||
| query expect_fallback(Native CartesianProduct requires single-partition inputs) | ||
| SELECT * FROM (SELECT /*+ REPARTITION(2) */ * FROM cp_left) l | ||
| CROSS JOIN (SELECT /*+ COALESCE(1) */ * FROM cp_right) r |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, no plain file scan passes this check, since non-bucketed scans report
UnknownPartitioning(0). Inputs qualify only aftercoalesce(1),repartition(1), a single-slicerangeor aSinglePartitionexchange, which is what every benchmark case forces. Under AQE this rule runs before shuffle partitions are coalesced, so a shuffle that later shrinks to one partition is probably still rejected, though I have not run that. Could the config note and theoperators.mdentry say this, so users know when enabling it helps? Separately, for the large-left, small-right case, DataFusion 55.2CrossJoinExec::build_batchemits one batch per left row, sized by the right batch, so 262144 x 64 produces 262144 batches of 64 rows. That probably explains why that case gains 3.1X against 18.6X for the square one. I read this from the source and did not measure it.