-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33779][SQL] DataSource V2: API to request distribution and ordering on write #30706
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
Closed
Closed
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions
35
...yst/src/main/java/org/apache/spark/sql/connector/distributions/ClusteredDistribution.java
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,35 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.distributions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
| import org.apache.spark.sql.connector.expressions.Expression; | ||
|
|
||
| /** | ||
| * A distribution where tuples that share the same values for clustering expressions are co-located | ||
| * in the same partition. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public interface ClusteredDistribution extends Distribution { | ||
| /** | ||
| * Returns clustering expressions. | ||
| */ | ||
| Expression[] clustering(); | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
sql/catalyst/src/main/java/org/apache/spark/sql/connector/distributions/Distribution.java
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,28 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.distributions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
|
|
||
| /** | ||
| * An interface that defines how data is distributed across partitions. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public interface Distribution {} |
56 changes: 56 additions & 0 deletions
56
sql/catalyst/src/main/java/org/apache/spark/sql/connector/distributions/Distributions.java
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,56 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.distributions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
| import org.apache.spark.sql.connector.expressions.Expression; | ||
| import org.apache.spark.sql.connector.expressions.SortOrder; | ||
|
|
||
| /** | ||
| * Helper methods to create distributions to pass into Spark. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public class Distributions { | ||
| private Distributions() { | ||
| } | ||
|
|
||
| /** | ||
| * Creates a distribution where no promises are made about co-location of data. | ||
| */ | ||
| public static UnspecifiedDistribution unspecified() { | ||
| return LogicalDistributions.unspecified(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a distribution where tuples that share the same values for clustering expressions are | ||
| * co-located in the same partition. | ||
| */ | ||
| public static ClusteredDistribution clustered(Expression[] clustering) { | ||
| return LogicalDistributions.clustered(clustering); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a distribution where tuples have been ordered across partitions according | ||
| * to ordering expressions, but not necessarily within a given partition. | ||
| */ | ||
| public static OrderedDistribution ordered(SortOrder[] ordering) { | ||
| return LogicalDistributions.ordered(ordering); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...alyst/src/main/java/org/apache/spark/sql/connector/distributions/OrderedDistribution.java
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,35 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.distributions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
| import org.apache.spark.sql.connector.expressions.SortOrder; | ||
|
|
||
| /** | ||
| * A distribution where tuples have been ordered across partitions according | ||
| * to ordering expressions, but not necessarily within a given partition. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public interface OrderedDistribution extends Distribution { | ||
| /** | ||
| * Returns ordering expressions. | ||
| */ | ||
| SortOrder[] ordering(); | ||
| } |
28 changes: 28 additions & 0 deletions
28
...t/src/main/java/org/apache/spark/sql/connector/distributions/UnspecifiedDistribution.java
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,28 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.distributions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
|
|
||
| /** | ||
| * A distribution where no promises are made about co-location of data. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public interface UnspecifiedDistribution extends Distribution {} |
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
42 changes: 42 additions & 0 deletions
42
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/NullOrdering.java
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,42 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
|
|
||
| /** | ||
| * A null order used in sorting expressions. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public enum NullOrdering { | ||
| NULLS_FIRST, NULLS_LAST; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| switch (this) { | ||
| case NULLS_FIRST: | ||
| return "NULLS FIRST"; | ||
| case NULLS_LAST: | ||
| return "NULLS LAST"; | ||
| default: | ||
| throw new IllegalArgumentException("Unexpected null order: " + this); | ||
| } | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/SortDirection.java
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,42 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
|
|
||
| /** | ||
| * A sort direction used in sorting expressions. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public enum SortDirection { | ||
| ASCENDING, DESCENDING; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| switch (this) { | ||
| case ASCENDING: | ||
| return "ASC"; | ||
| case DESCENDING: | ||
| return "DESC"; | ||
| default: | ||
| throw new IllegalArgumentException("Unexpected sort direction: " + this); | ||
| } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
sql/catalyst/src/main/java/org/apache/spark/sql/connector/expressions/SortOrder.java
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,43 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.expressions; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
|
|
||
| /** | ||
| * Represents a sort order in the public expression API. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public interface SortOrder extends Expression { | ||
| /** | ||
| * Returns the sort expression. | ||
| */ | ||
| Expression expression(); | ||
|
|
||
| /** | ||
| * Returns the sort direction. | ||
| */ | ||
| SortDirection direction(); | ||
|
|
||
| /** | ||
| * Returns the null ordering. | ||
| */ | ||
| NullOrdering nullOrdering(); | ||
| } |
57 changes: 57 additions & 0 deletions
57
...t/src/main/java/org/apache/spark/sql/connector/write/RequiresDistributionAndOrdering.java
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,57 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.write; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
| import org.apache.spark.sql.connector.distributions.Distribution; | ||
| import org.apache.spark.sql.connector.distributions.UnspecifiedDistribution; | ||
| import org.apache.spark.sql.connector.expressions.SortOrder; | ||
|
|
||
| /** | ||
| * A write that requires a specific distribution and ordering of data. | ||
| * | ||
| * @since 3.2.0 | ||
| */ | ||
| @Experimental | ||
| public interface RequiresDistributionAndOrdering extends Write { | ||
| /** | ||
| * Returns the distribution required by this write. | ||
| * <p> | ||
| * Spark will distribute incoming records across partitions to satisfy the required distribution | ||
| * before passing the records to the data source table on write. | ||
| * <p> | ||
| * Implementations may return {@link UnspecifiedDistribution} if they don't require any specific | ||
| * distribution of data on write. | ||
| * | ||
| * @return the required distribution | ||
| */ | ||
| Distribution requiredDistribution(); | ||
|
|
||
| /** | ||
| * Returns the ordering required by this write. | ||
| * <p> | ||
| * Spark will order incoming records within partitions to satisfy the required ordering | ||
| * before passing those records to the data source table on write. | ||
| * <p> | ||
| * Implementations may return an empty array if they don't require any specific ordering of data | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pardon for the late comment. The return value is an array. |
||
| * on write. | ||
| * | ||
| * @return the required ordering | ||
| */ | ||
| SortOrder[] requiredOrdering(); | ||
| } | ||
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.
We already have
org.apache.spark.sql.connector.read.partitioning.ClusteredDistribution, shall we remove that and always use this new one? The new one is better as it's more flexible (using Expression rather than String).It's better if we can avoid breaking existing APIs, but I can't figure out a good way. The old
ClusteredDistributionis only used in a mixin trait and marked asEvolving. Seems OK to break it.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.
cc @aokolnychyi
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.
We have started this discussion in comments to the original PR a bit. Some background here and here.
Overall, there are two options: break the API now and use new interfaces instead of the old ones in other places or evolve these two separately for a while and replace the read side once we have a clear plan for bucketed joins.
My first idea was to break the API and migrate to the new interfaces like suggested by @cloud-fan as that seems inevitable at some point. However, there were a couple of good points mentioned by reviewers on the original PR and I am now inclined to evolve these separately for a while until we know what changes will be required to support bucketed tables. I would like to avoid breaking the read side twice if possible.
That said, I don't feel strongly here and each option has its own benefits and drawbacks. I'll be fine with either one.
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.
also cc @viirya @HeartSaVioR @rdblue @dongjoon-hyun @sunchao who reviewed the change
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.
I'm OK to break it later, just don't leave the old one there forever. Shall we create a blocker ticket for Spark 3.2 to remove the old
ClusteredDistribution?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.
I created a blocker SPARK-33807 to track this.
Thanks, everyone!
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.
Hi @aokolnychyi , do you have time to clean it up now?
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.
Since
Partitioning.satisfyis still referring to the old interface I'm wondering whether we should defer this to 3.3.0 timeframe. For my storage partitioned join work I found that I need to change thePartitioninginterface again in a backward incompatible way so that it can work for joins. It may be better to break it once instead of two times. That's my 2 cents.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.
OK, let's retarget it to 3.3
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.
Sorry for my late reply. I also assumed we don't have any clarity on how the
Partitioninginterface should look like so I think delaying the update and breaking that API once is better.