-
Notifications
You must be signed in to change notification settings - Fork 495
Add properties from TableMetadata into Table entity internalProperties #2735
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1566,14 +1566,44 @@ public void doCommit(TableMetadata base, TableMetadata metadata) { | |
| "Generic table with same name already exists: %s", tableIdentifier); | ||
| } | ||
| } | ||
| Map<String, String> storedProperties = new HashMap<>(); | ||
| storedProperties.put("location", metadata.location()); | ||
|
collado-mike marked this conversation as resolved.
Outdated
|
||
| storedProperties.put("format-version", String.valueOf(metadata.formatVersion())); | ||
| storedProperties.put("table-uuid", metadata.uuid()); | ||
| storedProperties.put("current-schema-id", String.valueOf(metadata.currentSchemaId())); | ||
| if (metadata.currentSnapshot() != null) { | ||
| storedProperties.put( | ||
| "current-snapshot-id", String.valueOf(metadata.currentSnapshot().snapshotId())); | ||
| } | ||
| storedProperties.put("last-column-id", String.valueOf(metadata.lastColumnId())); | ||
| storedProperties.put("next-row-id", String.valueOf(metadata.nextRowId())); | ||
| storedProperties.put("last-sequence-number", String.valueOf(metadata.lastSequenceNumber())); | ||
| storedProperties.put("last-updated-ms", String.valueOf(metadata.lastUpdatedMillis())); | ||
| if (metadata.sortOrder() != null) { | ||
| storedProperties.put( | ||
| "default-sort-order-id", String.valueOf(metadata.defaultSortOrderId())); | ||
| } | ||
| if (metadata.spec() != null) { | ||
| storedProperties.put("default-spec-id", String.valueOf(metadata.defaultSpecId())); | ||
| storedProperties.put( | ||
| "last-partition-id", String.valueOf(metadata.lastAssignedPartitionId())); | ||
| } | ||
| if (metadata.currentSnapshot() != null) { | ||
| storedProperties.put( | ||
| "current-snapshot-id", String.valueOf(metadata.currentSnapshot().snapshotId())); | ||
| } | ||
| IcebergTableLikeEntity entity = | ||
| IcebergTableLikeEntity.of(resolvedPath == null ? null : resolvedPath.getRawLeafEntity()); | ||
| String existingLocation; | ||
| if (null == entity) { | ||
| existingLocation = null; | ||
| entity = | ||
| new IcebergTableLikeEntity.Builder( | ||
| PolarisEntitySubType.ICEBERG_TABLE, tableIdentifier, newLocation) | ||
| PolarisEntitySubType.ICEBERG_TABLE, | ||
| tableIdentifier, | ||
| Map.of(), | ||
|
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. nit: If we're using the builder pattern, why have rich constructor parameters? Why not call In this case the
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. The problem is in setting the builder
.setInternalProperties(props)
.setMetadataLocation(newLocation)
.build();but if we reverse the order and call the following, we're broken: builder
.setMetadataLocation(newLocation)
.setInternalProperties(props)
.build();It's not obvious from the caller's perspective, but With the existing constructor, it's impossible to order the setting of the
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. Good point, TIL 🤔 However, having this kind of effects in the codebase it pretty risky in the long term maintenance perspective, IMHO. Would it be reasonable to refactor the builders / related code to allow for more intuitive usage (in another PR, of course)?
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. Yeah, I was thinking about making |
||
| storedProperties, | ||
| newLocation) | ||
| .setCatalogId(getCatalogId()) | ||
| .setBaseLocation(metadata.location()) | ||
| .setId( | ||
|
|
@@ -1583,6 +1613,7 @@ public void doCommit(TableMetadata base, TableMetadata metadata) { | |
| existingLocation = entity.getMetadataLocation(); | ||
| entity = | ||
| new IcebergTableLikeEntity.Builder(entity) | ||
| .setInternalProperties(storedProperties) | ||
| .setBaseLocation(metadata.location()) | ||
| .setMetadataLocation(newLocation) | ||
| .build(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |||||
| import java.lang.reflect.Method; | ||||||
| import java.time.Clock; | ||||||
| import java.util.Arrays; | ||||||
| import java.util.Comparator; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
|
|
@@ -62,6 +63,7 @@ | |||||
| import org.apache.iceberg.FileMetadata; | ||||||
| import org.apache.iceberg.FileScanTask; | ||||||
| import org.apache.iceberg.MetadataUpdate; | ||||||
| import org.apache.iceberg.NullOrder; | ||||||
| import org.apache.iceberg.PartitionSpec; | ||||||
| import org.apache.iceberg.RowDelta; | ||||||
| import org.apache.iceberg.Schema; | ||||||
|
|
@@ -103,6 +105,7 @@ | |||||
| import org.apache.polaris.core.context.CallContext; | ||||||
| import org.apache.polaris.core.context.RealmContext; | ||||||
| import org.apache.polaris.core.entity.CatalogEntity; | ||||||
| import org.apache.polaris.core.entity.NamespaceEntity; | ||||||
| import org.apache.polaris.core.entity.PolarisBaseEntity; | ||||||
| import org.apache.polaris.core.entity.PolarisEntity; | ||||||
| import org.apache.polaris.core.entity.PolarisEntitySubType; | ||||||
|
|
@@ -154,6 +157,7 @@ | |||||
| import org.apache.polaris.service.types.TableUpdateNotification; | ||||||
| import org.assertj.core.api.AbstractCollectionAssert; | ||||||
| import org.assertj.core.api.Assertions; | ||||||
| import org.assertj.core.api.InstanceOfAssertFactories; | ||||||
| import org.assertj.core.api.ListAssert; | ||||||
| import org.assertj.core.api.ThrowableAssert.ThrowingCallable; | ||||||
| import org.assertj.core.configuration.PreferredAssumptionException; | ||||||
|
|
@@ -2282,6 +2286,90 @@ public void testTableOperationsDoesNotRefreshAfterCommit(boolean updateMetadataO | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void testTableInternalPropertiesStoredOnCommit() { | ||||||
|
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. [Non-blocker] Since we are testing the extraction of metadata fields, it would be good if we could add/or parametrize this test with different format-version (1,2,3). Technically the |
||||||
| Assumptions.assumeTrue( | ||||||
| requiresNamespaceCreate(), | ||||||
| "Only applicable if namespaces must be created before adding children"); | ||||||
|
|
||||||
| catalog.createNamespace(NS); | ||||||
| catalog.buildTable(TABLE, SCHEMA).create(); | ||||||
| catalog.loadTable(TABLE).newFastAppend().appendFile(FILE_A).commit(); | ||||||
| Table afterAppend = catalog.loadTable(TABLE); | ||||||
| EntityResult schemaResult = | ||||||
|
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.
Suggested change
[nit] Let's use |
||||||
| metaStoreManager.readEntityByName( | ||||||
| polarisContext, | ||||||
| List.of(catalogEntity), | ||||||
| PolarisEntityType.NAMESPACE, | ||||||
| PolarisEntitySubType.NULL_SUBTYPE, | ||||||
| NS.toString()); | ||||||
| Assertions.assertThat(schemaResult).returns(true, EntityResult::isSuccess); | ||||||
| EntityResult tableResult = | ||||||
| metaStoreManager.readEntityByName( | ||||||
| polarisContext, | ||||||
| List.of(catalogEntity, schemaResult.getEntity()), | ||||||
| PolarisEntityType.TABLE_LIKE, | ||||||
| PolarisEntitySubType.ICEBERG_TABLE, | ||||||
| TABLE.name()); | ||||||
| Assertions.assertThat(tableResult) | ||||||
| .returns(true, EntityResult::isSuccess) | ||||||
| .extracting(er -> PolarisEntity.of(er.getEntity())) | ||||||
| .extracting(PolarisEntity::getInternalPropertiesAsMap) | ||||||
| .asInstanceOf(InstanceOfAssertFactories.map(String.class, String.class)) | ||||||
| .containsEntry(NamespaceEntity.PARENT_NAMESPACE_KEY, NS.toString()) | ||||||
| .containsEntry( | ||||||
| "current-snapshot-id", String.valueOf(afterAppend.currentSnapshot().snapshotId())) | ||||||
| .containsEntry("location", afterAppend.location()) | ||||||
| .containsEntry("table-uuid", afterAppend.uuid().toString()) | ||||||
| .containsEntry("current-schema-id", String.valueOf(afterAppend.schema().schemaId())) | ||||||
| .containsEntry( | ||||||
| "last-column-id", | ||||||
| afterAppend.schema().columns().stream() | ||||||
| .max(Comparator.comparing(Types.NestedField::fieldId)) | ||||||
| .map(Types.NestedField::fieldId) | ||||||
| .orElse(0) | ||||||
| .toString()) | ||||||
| .containsEntry( | ||||||
| "last-sequence-number", String.valueOf(afterAppend.currentSnapshot().sequenceNumber())); | ||||||
|
|
||||||
| catalog.loadTable(TABLE).refresh(); | ||||||
| catalog.loadTable(TABLE).newFastAppend().appendFile(FILE_B).commit(); | ||||||
| validatePropertiesUpdated( | ||||||
| schemaResult, | ||||||
| "current-snapshot-id", | ||||||
| tbl -> String.valueOf(tbl.currentSnapshot().snapshotId())); | ||||||
|
|
||||||
| catalog.loadTable(TABLE).refresh(); | ||||||
| catalog.loadTable(TABLE).updateSchema().addColumn("new_col", Types.LongType.get()).commit(); | ||||||
| validatePropertiesUpdated( | ||||||
| schemaResult, "current-schema-id", tbl -> String.valueOf(tbl.schema().schemaId())); | ||||||
|
|
||||||
| catalog.loadTable(TABLE).refresh(); | ||||||
| catalog.loadTable(TABLE).replaceSortOrder().desc("new_col", NullOrder.NULLS_FIRST).commit(); | ||||||
| validatePropertiesUpdated( | ||||||
| schemaResult, | ||||||
| "default-sort-order-id", | ||||||
| table -> String.valueOf(table.sortOrder().orderId())); | ||||||
| } | ||||||
|
|
||||||
| private void validatePropertiesUpdated( | ||||||
| EntityResult schemaResult, String key, Function<Table, String> expectedValue) { | ||||||
| Table afterUpdate = catalog.loadTable(TABLE); | ||||||
| EntityResult tableResult = | ||||||
| metaStoreManager.readEntityByName( | ||||||
| polarisContext, | ||||||
| List.of(catalogEntity, schemaResult.getEntity()), | ||||||
| PolarisEntityType.TABLE_LIKE, | ||||||
| PolarisEntitySubType.ICEBERG_TABLE, | ||||||
| TABLE.name()); | ||||||
| Assertions.assertThat(tableResult) | ||||||
| .returns(true, EntityResult::isSuccess) | ||||||
| .extracting(er -> PolarisEntity.of(er.getEntity())) | ||||||
| .extracting(PolarisEntity::getInternalPropertiesAsMap) | ||||||
| .asInstanceOf(InstanceOfAssertFactories.map(String.class, String.class)) | ||||||
| .containsEntry(key, expectedValue.apply(afterUpdate)); | ||||||
| } | ||||||
|
|
||||||
| @Test | ||||||
| public void testEventsAreEmitted() { | ||||||
| IcebergCatalog catalog = catalog(); | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.