World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8932] fix(iceberg):The Iceberg REST server config interface shouldn't return view endpoints for JDBC catalog with v0 schema version (#8991)
Xiaojian Sundfcdffee84fe
diff --git a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.javaindex 3db4b29dc7..e8ad09d4bf 100644--- a/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java+++ b/iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergCatalogWrapper.java@@ -43,6 +43,7 @@ import org.apache.iceberg.catalog.Namespace;import org.apache.iceberg.catalog.SupportsNamespaces;import org.apache.iceberg.catalog.TableIdentifier;import org.apache.iceberg.catalog.ViewCatalog;+import org.apache.iceberg.jdbc.JdbcCatalogWithMetadataLocationSupport;import org.apache.iceberg.rest.CatalogHandlers;import org.apache.iceberg.rest.requests.CreateNamespaceRequest;import org.apache.iceberg.rest.requests.CreateTableRequest;@@ -262,7 +263,18 @@ public class IcebergCatalogWrapper implements AutoCloseable {}public boolean supportsViewOperations() {- return catalog instanceof ViewCatalog;+ if (!(catalog instanceof ViewCatalog)) {+ return false;+ }++ // JDBC catalog only supports view operations from v1 schema version+ if (catalog instanceof JdbcCatalogWithMetadataLocationSupport) {+ JdbcCatalogWithMetadataLocationSupport jdbcCatalog =+ (JdbcCatalogWithMetadataLocationSupport) catalog;+ return jdbcCatalog.supportsViewsWithSchemaVersion();+ }++ return true;}@Overridediff --git a/iceberg/iceberg-common/src/main/java/org/apache/iceberg/jdbc/JdbcCatalogWithMetadataLocationSupport.java b/iceberg/iceberg-common/src/main/java/org/apache/iceberg/jdbc/JdbcCatalogWithMetadataLocationSupport.javaindex 70efa855ea..e4a65a9d2c 100644--- a/iceberg/iceberg-common/src/main/java/org/apache/iceberg/jdbc/JdbcCatalogWithMetadataLocationSupport.java+++ b/iceberg/iceberg-common/src/main/java/org/apache/iceberg/jdbc/JdbcCatalogWithMetadataLocationSupport.java@@ -57,6 +57,17 @@ public class JdbcCatalogWithMetadataLocationSupport extends JdbcCatalogreturn table.get(METADATA_LOCATION_PROP);}+ /**+ * Check if the JDBC catalog schema version supports view operations. View operations are+ * supported from V1 schema version onwards.+ *+ * @return true if the schema version supports view operations, false otherwise+ */+ public boolean supportsViewsWithSchemaVersion() {+ // V0 doesn't support views, only V1 and later versions do+ return jdbcSchemaVersion != null && jdbcSchemaVersion != SchemaVersion.V0;+ }+private void loadFields() {try {this.jdbcCatalogName = (String) FieldUtils.readField(this, "catalogName", true);diff --git a/iceberg/iceberg-common/src/test/java/org/apache/iceberg/jdbc/TestJdbcCatalogWithMetadataLocationSupport.java b/iceberg/iceberg-common/src/test/java/org/apache/iceberg/jdbc/TestJdbcCatalogWithMetadataLocationSupport.javaindex b029be1726..d6443ca15f 100644--- a/iceberg/iceberg-common/src/test/java/org/apache/iceberg/jdbc/TestJdbcCatalogWithMetadataLocationSupport.java+++ b/iceberg/iceberg-common/src/test/java/org/apache/iceberg/jdbc/TestJdbcCatalogWithMetadataLocationSupport.java@@ -20,9 +20,13 @@package org.apache.iceberg.jdbc;import com.google.common.collect.ImmutableMap;+import java.util.HashMap;+import java.util.Map;import org.apache.iceberg.CatalogProperties;import org.junit.jupiter.api.Assertions;import org.junit.jupiter.api.Test;+import org.junit.jupiter.params.ParameterizedTest;+import org.junit.jupiter.params.provider.CsvSource;public class TestJdbcCatalogWithMetadataLocationSupport {@@ -40,4 +44,24 @@ public class TestJdbcCatalogWithMetadataLocationSupport {CatalogProperties.WAREHOUSE_LOCATION,"warehouse")));}++ @ParameterizedTest+ @CsvSource({+ "V0, false, JDBC catalog with V0 schema version should not support views",+ "V1, true, JDBC catalog with V1 schema version should support views"+ })+ void testSupportsViewsWithSchemaVersion(+ String schemaVersion, boolean expectedSupportsViews, String message) {+ JdbcCatalogWithMetadataLocationSupport catalog =+ new JdbcCatalogWithMetadataLocationSupport(true);+ Map<String, String> properties = new HashMap<>();+ properties.put(CatalogProperties.URI, "jdbc:sqlite::memory:");+ properties.put(CatalogProperties.WAREHOUSE_LOCATION, "warehouse");+ properties.put("jdbc.schema-version", schemaVersion);++ catalog.initialize("test_jdbc_" + schemaVersion.toLowerCase(), properties);++ Assertions.assertEquals(+ expectedSupportsViews, catalog.supportsViewsWithSchemaVersion(), message);+ }}diff --git a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergConfig.java b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergConfig.javaindex 58103e52b7..fc8c0a35a7 100644--- a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergConfig.java+++ b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergConfig.java@@ -119,4 +119,26 @@ public class TestIcebergConfig extends IcebergTestBase {Response response = getIcebergClientBuilder(path, Optional.empty()).get();Assertions.assertEquals(500, response.getStatus());}++ @ParameterizedTest+ @ValueSource(strings = {"", IcebergRestTestUtil.PREFIX})+ public void testConfigEndpointsContainViewOperations(String prefix) {+ setUrlPathWithPrefix(prefix);+ String warehouseName = IcebergRestTestUtil.PREFIX;+ Map<String, String> queryParams = ImmutableMap.of("warehouse", warehouseName);+ Response resp =+ getIcebergClientBuilder(IcebergRestTestUtil.CONFIG_PATH, Optional.of(queryParams)).get();+ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());++ ConfigResponse response = resp.readEntity(ConfigResponse.class);++ // Verify that view endpoints are present+ boolean hasViewListEndpoint =+ response.endpoints().stream()+ .anyMatch(endpoint -> endpoint.path().contains("namespaces/{namespace}/views"));++ Assertions.assertTrue(+ hasViewListEndpoint,+ "Config response should contain view list endpoint for catalog that supports views");+ }}