Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/src/main/java/org/apache/iceberg/catalog/TableCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.immutables.value.Value;

/**
* This represents a commit to be applied for a single table with {@link UpdateRequirement}s to be
* validated and {@link MetadataUpdate}s that have been applied. The {@link UpdateRequirement}s and
* {@link MetadataUpdate}s can be derived from table's base and updated {@link TableMetadata} when
* using {@link TableCommit#create(TableIdentifier, TableMetadata, TableMetadata)}.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add Javadoc for the create method? It has requirements for the TableMetadata objects that should be noted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the Javadoc to make this clearer when using the create method

@Value.Immutable
public interface TableCommit {
TableIdentifier identifier();
Expand All @@ -34,6 +40,17 @@ public interface TableCommit {

List<MetadataUpdate> updates();

/**
* This creates a {@link TableCommit} instance to be applied for a single table with {@link
* UpdateRequirement}s to be validated and {@link MetadataUpdate}s that have been applied.
*
* @param identifier The {@link TableIdentifier} to create the {@link TableCommit} for.
* @param base The base {@link TableMetadata} where {@link UpdateRequirement}s are derived from
* and used for validation.
* @param updated The updated {@link TableMetadata} where {@link MetadataUpdate}s that have been
* applied are derived from.
* @return A {@link TableCommit} instance to be applied for a single table
*/
static TableCommit create(TableIdentifier identifier, TableMetadata base, TableMetadata updated) {
Preconditions.checkArgument(null != identifier, "Invalid table identifier: null");
Preconditions.checkArgument(null != base && null != updated, "Invalid table metadata: null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ public void commitTransaction(SessionContext context, List<TableCommit> commits)

for (TableCommit commit : commits) {
tableChanges.add(
new UpdateTableRequest(commit.identifier(), commit.requirements(), commit.updates()));
UpdateTableRequest.create(commit.identifier(), commit.requirements(), commit.updates()));
}

client.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public UpdateTableRequest(
this.updates = updates;
}

public UpdateTableRequest(
UpdateTableRequest(
TableIdentifier identifier,
List<org.apache.iceberg.UpdateRequirement> requirements,
List<MetadataUpdate> updates) {
Expand Down Expand Up @@ -79,6 +79,13 @@ public String toString() {
.toString();
}

public static UpdateTableRequest create(
TableIdentifier identifier,
List<org.apache.iceberg.UpdateRequirement> requirements,
List<MetadataUpdate> updates) {
return new UpdateTableRequest(identifier, requirements, updates);
}

/**
* @deprecated will be removed in 1.5.0, use {@link
* org.apache.iceberg.UpdateRequirements#forCreateTable(List)} instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ public static UpdateTableRequest fromJson(JsonNode json) {
updatesNode.forEach(update -> updates.add(MetadataUpdateParser.fromJson(update)));
}

return new UpdateTableRequest(identifier, requirements, updates);
return UpdateTableRequest.create(identifier, requirements, updates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void invalidTableIdentifier() {
public void roundTripSerde() {
String uuid = "2cc52516-5e73-41f2-b139-545d41a4e151";
UpdateTableRequest commitTableRequestOne =
new UpdateTableRequest(
UpdateTableRequest.create(
TableIdentifier.of("ns1", "table1"),
ImmutableList.of(
new UpdateRequirement.AssertTableUUID(uuid),
Expand All @@ -90,7 +90,7 @@ public void roundTripSerde() {
new MetadataUpdate.AssignUUID(uuid), new MetadataUpdate.SetCurrentSchema(23)));

UpdateTableRequest commitTableRequestTwo =
new UpdateTableRequest(
UpdateTableRequest.create(
TableIdentifier.of("ns1", "table2"),
ImmutableList.of(
new UpdateRequirement.AssertDefaultSpecID(4),
Expand Down Expand Up @@ -160,7 +160,7 @@ public void emptyRequirementsAndUpdates() {
CommitTransactionRequest commitTxRequest =
new CommitTransactionRequest(
ImmutableList.of(
new UpdateTableRequest(
UpdateTableRequest.create(
TableIdentifier.of("ns1", "table1"), ImmutableList.of(), ImmutableList.of())));

String json =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void invalidMetadataUpdates() {
public void roundTripSerde() {
String uuid = "2cc52516-5e73-41f2-b139-545d41a4e151";
UpdateTableRequest request =
new UpdateTableRequest(
UpdateTableRequest.create(
TableIdentifier.of("ns1", "table1"),
ImmutableList.of(
new org.apache.iceberg.UpdateRequirement.AssertTableUUID(uuid),
Expand Down Expand Up @@ -198,7 +198,7 @@ public void roundTripSerdeWithoutIdentifier() {
@Test
public void emptyRequirementsAndUpdates() {
UpdateTableRequest request =
new UpdateTableRequest(
UpdateTableRequest.create(
TableIdentifier.of("ns1", "table1"), ImmutableList.of(), ImmutableList.of());

String json =
Expand Down