Skip to content

Commit

Permalink
change comments and add default API in SupportsAtomicPartitionManagement
Browse files Browse the repository at this point in the history
Change-Id: I4870b050b2979991d039407e7c99a638b2eb8cd0
  • Loading branch information
jackylee-ch committed Aug 11, 2020
1 parent b570496 commit b3a6e2b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

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.NoSuchPartitionsException;
import org.apache.spark.sql.catalyst.analysis.PartitionAlreadyExistsException;
import org.apache.spark.sql.catalyst.analysis.PartitionsAlreadyExistException;

/**
Expand All @@ -30,9 +32,9 @@
* 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 that their location contains to the table
* add an array of partitions and any data they contain to the table
* ${@link #dropPartitions}:
* remove an array of partitions and any data they contains from the table
* remove an array of partitions and any data they contain from the table
* ${@link #replacePartitionMetadatas}:
* point an array of partitions to new locations, which will swap location's data for the other
*
Expand All @@ -41,6 +43,40 @@
@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) {
try {
dropPartitions(new InternalRow[]{ident});
return true;
} catch (NoSuchPartitionsException e) {
return false;
}
}

@Override
default void replacePartitionMetadata(
InternalRow ident,
Map<String, String> properties)
throws NoSuchPartitionException, UnsupportedOperationException {
try {
replacePartitionMetadatas(new InternalRow[]{ident}, new Map[]{properties});
} catch (NoSuchPartitionsException e) {
throw new NoSuchPartitionException(e.getMessage());
}
}

/**
* Create an array of partitions atomically in table.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* 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 that its location contains to the table
* 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}:
Expand Down

0 comments on commit b3a6e2b

Please sign in to comment.