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
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static void updateHmsTableForIcebergTable(
maxHiveTablePropertySize);
setStorageHandler(parameters, hiveEngineEnabled);
setMetadataHash(metadata, parameters);
parameters.put(TableProperties.FORMAT_VERSION, String.valueOf(metadata.formatVersion()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why don't do this in the setCommonParameters?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

setCommonParameters is also used for views, and a view has its own format version in ViewMetadata. Writing it there would put a view version under the same key as a table version. I kept it in updateHmsTableForIcebergTable so only tables get it. If you would rather have it in the shared method, I can pass the format version in and use a different key for views. What do you prefer?


// Set the basic statistics
if (summary.get(SnapshotSummary.TOTAL_DATA_FILES_PROP) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.FieldSource;
import org.junit.jupiter.params.provider.ValueSource;

/**
Expand Down Expand Up @@ -994,6 +995,54 @@ public void testUUIDinTableProperties() throws Exception {
}
}

@ParameterizedTest
@FieldSource("org.apache.iceberg.TestHelpers#ALL_VERSIONS")
void formatVersionInTableParametersOnCreate(int formatVersion) throws Exception {
Schema schema = getTestSchema();
TableIdentifier tableIdentifier = TableIdentifier.of(DB_NAME, "tbl");
String location = temp.resolve("tbl").toUri().toString();

try {
catalog
.buildTable(tableIdentifier, schema)
.withLocation(location)
.withProperty(TableProperties.FORMAT_VERSION, String.valueOf(formatVersion))
.create();

assertThat(hmsTableParameters())
.containsEntry(TableProperties.FORMAT_VERSION, String.valueOf(formatVersion));
} finally {
catalog.dropTable(tableIdentifier);
}
}

@Test
void formatVersionInTableParametersOnUpgrade() throws Exception {
Schema schema = getTestSchema();
TableIdentifier tableIdentifier = TableIdentifier.of(DB_NAME, "tbl");
String location = temp.resolve("tbl").toString();
int upgradedFormatVersion = 3;

try {
catalog
.buildTable(tableIdentifier, schema)
.withLocation(location)
.withProperty(TableProperties.FORMAT_VERSION, "2")
.create();

catalog
.loadTable(tableIdentifier)
.updateProperties()
.set(TableProperties.FORMAT_VERSION, String.valueOf(upgradedFormatVersion))
.commit();

assertThat(hmsTableParameters())
.containsEntry(TableProperties.FORMAT_VERSION, String.valueOf(upgradedFormatVersion));
} finally {
catalog.dropTable(tableIdentifier);
}
}

@Test
public void testSnapshotStatsTableProperties() throws Exception {
Schema schema = getTestSchema();
Expand Down
Loading