Uh oh!
There was an error while loading. Please reload this page.
[SPARK-38647][SQL] Add SupportsReportOrdering mix in interface for Scan (DataSourceV2) - #35965
[SPARK-38647][SQL] Add SupportsReportOrdering mix in interface for Scan (DataSourceV2)#35965EnricoMi wants to merge 22 commits into
Conversation
AmplabJenkins
commented
Mar 24, 2022
Can one of the admins verify this patch? |
2efc6ef to
818e0f7Compare7c67284 to
33623c2CompareEnricoMi
commented
Apr 12, 2022
@sunchao@dongjoon-hyun looks like #35657 (20ffbf7) broke reusing partitioning and order provided by DS V2 in my tests, which worked before rebase. The query planner now introduces a shuffle and sort again. Any suggestion how Spark can pick up the existing partitioning and order with the new partitioning design? Any plans for DS V2 to report ordering? |
EnricoMi
commented
Apr 12, 2022
I have found the issue, option |
EnricoMi
commented
Apr 12, 2022
sunchao
commented
Apr 12, 2022
@EnricoMi the ordering is not supported yet, but potentially can be done by adding another V2 |
EnricoMi
commented
Apr 12, 2022
So you are saying ordering is seen as being part of partitioning. This kind of makes sense. Are you foreseeing that partitioning can transport in-partition order, rather than global order? For instance, some hash partitioning (having no global order) with some in-partition order as used by |
sunchao
commented
Apr 13, 2022
Yes I think it could be a useful addition to |
cloud-fan
commented
Apr 14, 2022
The internal That said, I think a new API |
36e2678 to
699c607CompareEnricoMi
commented
Apr 19, 2022
@cloud-fan thanks for clarification, I have incorporated this distinction into the documentation of |
EnricoMi
commented
Apr 26, 2022
@cloud-fan who would be best to review this? |
HyukjinKwon
commented
Apr 29, 2022
cc @aokolnychyi too FYI |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
This is not correct since Spark can combine input partitions (see groupPartitions).
There was a problem hiding this comment.
Combining the partitions through groupPartitions does not preserve order (when concatenated), that is right. It could be preserved by merging the partitions, though.
The outputOrdering of the data source is as stated. Whoever calls into groupPartitions should consider that order is not preserved (depending on how the Seq[InputPartition] is used) if existing order is desired.
There was a problem hiding this comment.
Whoever calls into groupPartitions should consider ...
Yes, although groupPartitions is called by Spark right now so we should update accordingly in this PR too. Otherwise, after this PR the outputOrdering could be incorrect if grouping happen.
There was a problem hiding this comment.
Alright, when partition grouping happens and multiple partitions are grouped, ordering cannot be preserved.
I have modified outputOrdering not to return the ordering in that case. Making grouped partitions preserve order is out-of-scope of this PR.
There was a problem hiding this comment.
Hmm when partitions.length == 1 I think partition combining can still happen? partitions is of type Seq[Seq[InputPartition]] so even if its length = 1, the inner Seq[InputPartition] can still contain more than one elements.
There was a problem hiding this comment.
You are right, I mis-interpreted if (partitions.length == 1) SinglePartition in def outputPartitioning, but partitions already incorporates groupedPartitions. Fixing that.
There was a problem hiding this comment.
I'm not sure if logicalLink is the idiomatic way of processing a logical plan here (don't see it used much elsewhere) - normally we do in an optimizer rule like V2ScanPartitioning or V2Writes.
@cloud-fan@viirya do you see any issue with this?
There was a problem hiding this comment.
I'm not totally sure this is the correct approach. Could we follow the existing pattern and add an optimizer rule to populate this? we can re-use existing V2ScanPartitioning too (and change its name).
There was a problem hiding this comment.
Awesome! Rules is where the magic happens...
Integrating this into V2ScanPartitioning makes this so much nicer, gets rid of the awful this.logicalLink.isDefined.
I have renamed V2ScanPartitioning to V2ScanPartitioningAndOrdering.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
This may need to be updated since column "i" may not be in the "partitionKeys".
1b024e8 to
f421607CompareEnricoMi
commented
May 9, 2022
@sunchao I have pushed all my changes |
f421607 to
4ba19f7CompareEnricoMi
commented
May 16, 2022
@sunchao@HyukjinKwon@aokolnychyi@cloud-fan I have addressed comments and rebased. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
nit: break this into multiple lines:
MyNamedReference(String part) {
this.parts = new String[] { part }; }
There was a problem hiding this comment.
I'm not totally sure this is the correct approach. Could we follow the existing pattern and add an optimizer rule to populate this? we can re-use existing V2ScanPartitioning too (and change its name).
7c90fd1 to
2e1f5d9CompareEnricoMi
commented
Jun 9, 2022
@sunchao@cloud-fan all comments addressed, all tests green |
2e1f5d9 to
73c13deCompare
sunchao
left a comment
There was a problem hiding this comment.
LGTM. Thanks, and sorry for the late response.
There was a problem hiding this comment.
nit nit: can we keep this one-line?
valscanRules=Seq[LogicalPlan=>LogicalPlan](partitioning, ordering)There was a problem hiding this comment.
Sure, done. Thanks for the review!
…tionAwareDataSource
73c13de to
e444a5dComparesunchao
commented
Jun 21, 2022
Merged to master, thanks! |
EnricoMi
commented
Jun 21, 2022
Thanks @sunchao |
What changes were proposed in this pull request?
As
SupportsReportPartitioningallows implementations ofScanprovide Spark with information about the exiting partitioning of data read by aDataSourceV2, a similar mix in interfaceSupportsReportOrderingshould provide order information.Why are the changes needed?
This prevents Spark from sorting data if they already exhibit a certain order provided by the source.
Does this PR introduce any user-facing change?
It adds
SupportsReportOrderingmix in interface.How was this patch tested?
This adds tests to
DataSourceV2Suite, similar to the test forSupportsReportPartitioning.