From 525a25135fddaf61fdd1992c993afe0f9e45209d Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Thu, 19 Sep 2024 20:06:03 +0200 Subject: [PATCH] Simplify IcebergMetadataUpdate/trusted-location --- .../iceberg/nessie/NessieModelIceberg.java | 4 +-- .../iceberg/rest/IcebergMetadataUpdate.java | 29 +++++++++---------- .../nessie/TestNessieModelIceberg.java | 2 +- .../service/impl/CatalogServiceImpl.java | 2 +- .../rest/IcebergApiV1TableResource.java | 2 +- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/nessie/NessieModelIceberg.java b/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/nessie/NessieModelIceberg.java index 4b9f4c02f3a..c5ed952448b 100644 --- a/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/nessie/NessieModelIceberg.java +++ b/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/nessie/NessieModelIceberg.java @@ -90,8 +90,8 @@ import org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.AssignUUID; import org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.RemoveProperties; import org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetCurrentSchema; +import org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetLocation; import org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetProperties; -import org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetTrustedLocation; import org.projectnessie.catalog.formats.iceberg.types.IcebergDecimalType; import org.projectnessie.catalog.formats.iceberg.types.IcebergFixedType; import org.projectnessie.catalog.formats.iceberg.types.IcebergListType; @@ -1103,7 +1103,7 @@ public static void assignUUID(AssignUUID u, NessieEntitySnapshot snapshot) { uuid); } - public static void setLocation(SetTrustedLocation u, NessieEntitySnapshot.Builder builder) { + public static void setLocation(SetLocation u, NessieEntitySnapshot.Builder builder) { builder.icebergLocation(u.location()); } diff --git a/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/rest/IcebergMetadataUpdate.java b/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/rest/IcebergMetadataUpdate.java index 662eff56c41..0ae81163760 100644 --- a/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/rest/IcebergMetadataUpdate.java +++ b/catalog/format/iceberg/src/main/java/org/projectnessie/catalog/formats/iceberg/rest/IcebergMetadataUpdate.java @@ -21,6 +21,7 @@ import static org.projectnessie.catalog.formats.iceberg.nessie.NessieModelIceberg.icebergStatisticsFileToNessie; import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSubTypes; @@ -480,32 +481,28 @@ static SetDefaultSortOrder setDefaultSortOrder(int sortOrderId) { interface SetLocation extends IcebergMetadataUpdate { String location(); - @Override - default void applyToTable(IcebergTableMetadataUpdateState state) { - // don't trust locations sent by clients + @JsonIgnore + @Value.Default + default boolean trusted() { + return false; } - @Override - default void applyToView(IcebergViewMetadataUpdateState state) { - // don't trust locations sent by clients - } - } - - @NessieImmutable - interface SetTrustedLocation extends SetLocation { - @Override default void applyToTable(IcebergTableMetadataUpdateState state) { - NessieModelIceberg.setLocation(this, state.builder()); + if (trusted()) { + NessieModelIceberg.setLocation(this, state.builder()); + } } @Override default void applyToView(IcebergViewMetadataUpdateState state) { - NessieModelIceberg.setLocation(this, state.builder()); + if (trusted()) { + NessieModelIceberg.setLocation(this, state.builder()); + } } - static SetTrustedLocation setTrustedLocation(String location) { - return ImmutableSetTrustedLocation.of(location); + static SetLocation setTrustedLocation(String location) { + return ImmutableSetLocation.of(location, true); } } diff --git a/catalog/format/iceberg/src/test/java/org/projectnessie/catalog/formats/iceberg/nessie/TestNessieModelIceberg.java b/catalog/format/iceberg/src/test/java/org/projectnessie/catalog/formats/iceberg/nessie/TestNessieModelIceberg.java index 7dc93b0f266..3bf77ed02b2 100644 --- a/catalog/format/iceberg/src/test/java/org/projectnessie/catalog/formats/iceberg/nessie/TestNessieModelIceberg.java +++ b/catalog/format/iceberg/src/test/java/org/projectnessie/catalog/formats/iceberg/nessie/TestNessieModelIceberg.java @@ -30,7 +30,7 @@ import static org.projectnessie.catalog.formats.iceberg.meta.IcebergSchema.INITIAL_SCHEMA_ID; import static org.projectnessie.catalog.formats.iceberg.nessie.NessieModelIceberg.newIcebergTableSnapshot; import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.AddSchema.addSchema; -import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetTrustedLocation.setTrustedLocation; +import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetLocation.setTrustedLocation; import static org.projectnessie.catalog.formats.iceberg.types.IcebergType.binaryType; import static org.projectnessie.catalog.formats.iceberg.types.IcebergType.integerType; import static org.projectnessie.catalog.formats.iceberg.types.IcebergType.listType; diff --git a/catalog/service/impl/src/main/java/org/projectnessie/catalog/service/impl/CatalogServiceImpl.java b/catalog/service/impl/src/main/java/org/projectnessie/catalog/service/impl/CatalogServiceImpl.java index 5cbb3c92b2e..fb920dbac9a 100644 --- a/catalog/service/impl/src/main/java/org/projectnessie/catalog/service/impl/CatalogServiceImpl.java +++ b/catalog/service/impl/src/main/java/org/projectnessie/catalog/service/impl/CatalogServiceImpl.java @@ -31,8 +31,8 @@ import static org.projectnessie.catalog.formats.iceberg.nessie.NessieModelIceberg.newIcebergTableSnapshot; import static org.projectnessie.catalog.formats.iceberg.nessie.NessieModelIceberg.newIcebergViewSnapshot; import static org.projectnessie.catalog.formats.iceberg.nessie.NessieModelIceberg.typeToEntityName; +import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetLocation.setTrustedLocation; import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetProperties.setProperties; -import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetTrustedLocation.setTrustedLocation; import static org.projectnessie.catalog.service.api.NessieSnapshotResponse.nessieSnapshotResponse; import static org.projectnessie.catalog.service.impl.Util.objIdToNessieId; import static org.projectnessie.catalog.service.objtypes.EntitySnapshotObj.snapshotObjIdForContent; diff --git a/catalog/service/rest/src/main/java/org/projectnessie/catalog/service/rest/IcebergApiV1TableResource.java b/catalog/service/rest/src/main/java/org/projectnessie/catalog/service/rest/IcebergApiV1TableResource.java index c0dd3ec512c..68d5ed8bd9e 100644 --- a/catalog/service/rest/src/main/java/org/projectnessie/catalog/service/rest/IcebergApiV1TableResource.java +++ b/catalog/service/rest/src/main/java/org/projectnessie/catalog/service/rest/IcebergApiV1TableResource.java @@ -33,8 +33,8 @@ import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetCurrentSchema.setCurrentSchema; import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetDefaultPartitionSpec.setDefaultPartitionSpec; import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetDefaultSortOrder.setDefaultSortOrder; +import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetLocation.setTrustedLocation; import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetProperties.setProperties; -import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.SetTrustedLocation.setTrustedLocation; import static org.projectnessie.catalog.formats.iceberg.rest.IcebergMetadataUpdate.UpgradeFormatVersion.upgradeFormatVersion; import static org.projectnessie.catalog.service.rest.TableRef.tableRef; import static org.projectnessie.model.Content.Type.ICEBERG_TABLE;