This is an automated email from the ASF dual-hosted git repository.
fanng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new dfcdffee84 [#8932] fix(iceberg):The Iceberg REST server config
interface shouldn't return view endpoints for JDBC catalog with v0 schema
version (#8991)
dfcdffee84 is described below
commit dfcdffee84fe14e03b7948876deb1056c4d1907e
Author: Xiaojian Sun <[email protected]>
AuthorDate: Sat Nov 1 09:29:36 2025 +0800
[#8932] fix(iceberg):The Iceberg REST server config interface shouldn't
return view endpoints for JDBC catalog with v0 schema version (#8991)
### What changes were proposed in this pull request?
The Iceberg REST server config interface shouldn't return view endpoints
for JDBC catalog with v0 schema version
### Why are the changes needed?
Fix: #([8932](https://github.com/apache/gravitino/issues/8932))
### Does this PR introduce _any_ user-facing change?
N/A
### How was this patch tested?
org.apache.iceberg.jdbc.TestJdbcCatalogWithMetadataLocationSupport#testSupportsViewsWithSchemaVersion
org.apache.gravitino.iceberg.service.rest.TestIcebergConfig#testConfigEndpointsContainViewOperations
---
.../iceberg/common/ops/IcebergCatalogWrapper.java | 14 ++++++++++++-
.../JdbcCatalogWithMetadataLocationSupport.java | 11 ++++++++++
...TestJdbcCatalogWithMetadataLocationSupport.java | 24 ++++++++++++++++++++++
.../iceberg/service/rest/TestIcebergConfig.java | 22 ++++++++++++++++++++
4 files changed, 70 insertions(+), 1 deletion(-)
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.java
index 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;
}
@Override
diff --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.java
index 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
JdbcCatalog
return 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.java
index 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.java
index 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");
+ }
}