-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-31694][SQL] Add SupportsPartitions APIs on DataSourceV2 #28617
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
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c8d5846
add supports partitions catalog api
7a83f30
add partition catalog api test
4a77db0
fix suite tests
9ff1c6c
rename partition API
f9288aa
fix code error
866f46a
fix error
0fda123
change comment
e616e75
fix r test error
2d838a4
add suites
9a3664f
change partition API and docs
f6848ed
change suite test name
282b813
change support version
825d2e9
change comment from rename to alter
974f29a
retest
ad84016
add SupportsAtomicPartitionManagement API support
b570496
retest github action
b3a6e2b
change comments and add default API in SupportsAtomicPartitionManagement
279cea6
add override api in InMemoryAtomicPartitionTable
4bf9711
fix suites
c96e0fc
remove replacePartitionMetadatas
4686a24
change dropPartition returns
4f1bff3
restart git actions
bfd17d4
restart git actions
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
85 changes: 85 additions & 0 deletions
85
...c/main/java/org/apache/spark/sql/connector/catalog/SupportsAtomicPartitionManagement.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,85 @@ | ||
| /* | ||
| * 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.catalog; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
| import org.apache.spark.sql.catalyst.InternalRow; | ||
| import org.apache.spark.sql.catalyst.analysis.PartitionAlreadyExistsException; | ||
| import org.apache.spark.sql.catalyst.analysis.PartitionsAlreadyExistException; | ||
|
|
||
| /** | ||
| * An atomic partition interface of {@link Table} to operate multiple partitions atomically. | ||
| * <p> | ||
| * These APIs are used to modify table partition or partition metadata, | ||
| * they will change the table data as well. | ||
| * ${@link #createPartitions}: | ||
| * add an array of partitions and any data they contain to the table | ||
| * ${@link #dropPartitions}: | ||
| * remove an array of partitions and any data they contain from the table | ||
| * | ||
| * @since 3.1.0 | ||
| */ | ||
| @Experimental | ||
| public interface SupportsAtomicPartitionManagement extends SupportsPartitionManagement { | ||
|
|
||
| @Override | ||
| default void createPartition( | ||
| InternalRow ident, | ||
| Map<String, String> properties) | ||
| throws PartitionAlreadyExistsException, UnsupportedOperationException { | ||
| try { | ||
| createPartitions(new InternalRow[]{ident}, new Map[]{properties}); | ||
| } catch (PartitionsAlreadyExistException e) { | ||
| throw new PartitionAlreadyExistsException(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| default boolean dropPartition(InternalRow ident) { | ||
| return dropPartitions(new InternalRow[]{ident}); | ||
| } | ||
|
|
||
| /** | ||
| * Create an array of partitions atomically in table. | ||
| * <p> | ||
| * If any partition already exists, | ||
| * the operation of createPartitions need to be safely rolled back. | ||
| * | ||
| * @param idents an array of new partition identifiers | ||
| * @param properties the metadata of the partitions | ||
| * @throws PartitionsAlreadyExistException If any partition already exists for the identifier | ||
| * @throws UnsupportedOperationException If partition property is not supported | ||
| */ | ||
| void createPartitions( | ||
| InternalRow[] idents, | ||
| Map<String, String>[] properties) | ||
| throws PartitionsAlreadyExistException, UnsupportedOperationException; | ||
|
|
||
| /** | ||
| * Drop an array of partitions atomically from table. | ||
| * <p> | ||
| * If any partition doesn't exists, | ||
| * the operation of dropPartitions need to be safely rolled back. | ||
| * | ||
| * @param idents an array of partition identifiers | ||
| * @return true if partitions were deleted, false if any partition not exists | ||
| */ | ||
| boolean dropPartitions(InternalRow[] idents); | ||
| } | ||
115 changes: 115 additions & 0 deletions
115
...yst/src/main/java/org/apache/spark/sql/connector/catalog/SupportsPartitionManagement.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,115 @@ | ||
| /* | ||
| * 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.catalog; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.apache.spark.annotation.Experimental; | ||
| import org.apache.spark.sql.catalyst.InternalRow; | ||
| import org.apache.spark.sql.catalyst.analysis.NoSuchPartitionException; | ||
| import org.apache.spark.sql.catalyst.analysis.PartitionAlreadyExistsException; | ||
| import org.apache.spark.sql.types.StructType; | ||
|
|
||
| /** | ||
| * A partition interface of {@link Table}. | ||
| * A partition is composed of identifier and properties, | ||
| * and properties contains metadata information of the partition. | ||
| * <p> | ||
| * These APIs are used to modify table partition identifier or partition metadata. | ||
| * In some cases, they will change the table data as well. | ||
| * ${@link #createPartition}: | ||
| * add a partition and any data it contains to the table | ||
| * ${@link #dropPartition}: | ||
| * remove a partition and any data it contains from the table | ||
| * ${@link #replacePartitionMetadata}: | ||
| * point a partition to a new location, which will swap one location's data for the other | ||
| * | ||
| * @since 3.1.0 | ||
| */ | ||
| @Experimental | ||
| public interface SupportsPartitionManagement extends Table { | ||
|
|
||
| /** | ||
| * Get the partition schema of table, | ||
| * this must be consistent with ${@link Table#partitioning()}. | ||
| * @return the partition schema of table | ||
| */ | ||
| StructType partitionSchema(); | ||
|
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. Shall we mention that, this must be consistent with
Contributor
Author
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. ok, sound reasonable to me. |
||
|
|
||
| /** | ||
| * Create a partition in table. | ||
| * | ||
| * @param ident a new partition identifier | ||
| * @param properties the metadata of a partition | ||
| * @throws PartitionAlreadyExistsException If a partition already exists for the identifier | ||
| * @throws UnsupportedOperationException If partition property is not supported | ||
| */ | ||
| void createPartition( | ||
| InternalRow ident, | ||
| Map<String, String> properties) | ||
| throws PartitionAlreadyExistsException, UnsupportedOperationException; | ||
|
|
||
| /** | ||
| * Drop a partition from table. | ||
| * | ||
| * @param ident a partition identifier | ||
| * @return true if a partition was deleted, false if no partition exists for the identifier | ||
| */ | ||
| boolean dropPartition(InternalRow ident); | ||
|
|
||
| /** | ||
| * Test whether a partition exists using an {@link InternalRow ident} from the table. | ||
| * | ||
| * @param ident a partition identifier | ||
| * @return true if the partition exists, false otherwise | ||
| */ | ||
| default boolean partitionExists(InternalRow ident) { | ||
| return listPartitionIdentifiers(ident).length > 0; | ||
| } | ||
|
|
||
| /** | ||
| * Replace the partition metadata of the existing partition. | ||
| * | ||
| * @param ident the partition identifier of the existing partition | ||
| * @param properties the new metadata of the partition | ||
| * @throws NoSuchPartitionException If the partition identifier to alter doesn't exist | ||
| * @throws UnsupportedOperationException If partition property is not supported | ||
| */ | ||
| void replacePartitionMetadata( | ||
| InternalRow ident, | ||
| Map<String, String> properties) | ||
| throws NoSuchPartitionException, UnsupportedOperationException; | ||
|
|
||
| /** | ||
| * Retrieve the partition metadata of the existing partition. | ||
| * | ||
| * @param ident a partition identifier | ||
| * @return the metadata of the partition | ||
| * @throws UnsupportedOperationException If partition property is not supported | ||
| */ | ||
| Map<String, String> loadPartitionMetadata(InternalRow ident) | ||
| throws UnsupportedOperationException; | ||
|
|
||
| /** | ||
| * List the identifiers of all partitions that contains the ident in a table. | ||
| * | ||
| * @param ident a prefix of partition identifier | ||
| * @return an array of Identifiers for the partitions | ||
| */ | ||
| InternalRow[] listPartitionIdentifiers(InternalRow ident); | ||
| } | ||
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
76 changes: 76 additions & 0 deletions
76
...catalyst/src/test/scala/org/apache/spark/sql/connector/InMemoryAtomicPartitionTable.scala
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,76 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import java.util | ||
|
|
||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.analysis.{PartitionAlreadyExistsException, PartitionsAlreadyExistException} | ||
| import org.apache.spark.sql.connector.catalog.SupportsAtomicPartitionManagement | ||
| import org.apache.spark.sql.connector.expressions.Transform | ||
| import org.apache.spark.sql.types.StructType | ||
|
|
||
| /** | ||
| * This class is used to test SupportsAtomicPartitionManagement API. | ||
| */ | ||
| class InMemoryAtomicPartitionTable ( | ||
| name: String, | ||
| schema: StructType, | ||
| partitioning: Array[Transform], | ||
| properties: util.Map[String, String]) | ||
| extends InMemoryPartitionTable(name, schema, partitioning, properties) | ||
| with SupportsAtomicPartitionManagement { | ||
|
|
||
| override def createPartition( | ||
| ident: InternalRow, | ||
| properties: util.Map[String, String]): Unit = { | ||
| if (memoryTablePartitions.containsKey(ident)) { | ||
| throw new PartitionAlreadyExistsException(name, ident, partitionSchema) | ||
| } else { | ||
| memoryTablePartitions.put(ident, properties) | ||
| } | ||
| } | ||
|
|
||
| override def dropPartition(ident: InternalRow): Boolean = { | ||
| if (memoryTablePartitions.containsKey(ident)) { | ||
| memoryTablePartitions.remove(ident) | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| override def createPartitions( | ||
| idents: Array[InternalRow], | ||
| properties: Array[util.Map[String, String]]): Unit = { | ||
| if (idents.exists(partitionExists)) { | ||
| throw new PartitionsAlreadyExistException( | ||
| name, idents.filter(partitionExists), partitionSchema) | ||
| } | ||
| idents.zip(properties).foreach { case (ident, property) => | ||
| createPartition(ident, property) | ||
| } | ||
| } | ||
|
|
||
| override def dropPartitions(idents: Array[InternalRow]): Boolean = { | ||
| if (!idents.forall(partitionExists)) { | ||
| return false; | ||
| } | ||
| idents.forall(dropPartition) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.