This is an automated email from the ASF dual-hosted git repository.
jerryshao pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new 09afd69ef8 [Cherry-pick to branch-1.3] [#14302] fix(iceberg-rest):
Return 400 when register metadata location does not exist (#14628) (#14653)
09afd69ef8 is described below
commit 09afd69ef8578dd2ee7f9e78d572d2091a115039
Author: MaSai <[email protected]>
AuthorDate: Thu Nov 5 18:47:54 2026 +0800
[Cherry-pick to branch-1.3] [#14302] fix(iceberg-rest): Return 400 when
register metadata location does not exist (#14628) (#14653)
## Purpose
Cherry-pick of #14628 onto `branch-1.3`, replacing bot PR #14651 (closed
with conflicts).
## Changes
- Convert Iceberg `NotFoundException` to `BadRequestException` (HTTP
400) in
`IcebergCatalogWrapper.loadTableMetadataFromLocation` (registerTable
schema
pre-check / authz path).
- branch-1.3 adaptations:
- Skip `registerView` wrapping and its unit test (API not on 1.3)
## Closes
Supersedes #14651
Co-authored-by: Cursor <[email protected]>
---
.../gravitino/iceberg/common/ops/IcebergCatalogWrapper.java | 5 +++++
.../iceberg/common/ops/TestIcebergCatalogWrapper.java | 13 +++++++++++++
2 files changed, 18 insertions(+)
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 d60bb881b2..ca77a66053 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
@@ -330,10 +330,15 @@ public class IcebergCatalogWrapper implements
AutoCloseable {
*
* @param metadataLocation metadata file location
* @return parsed table metadata
+ * @throws BadRequestException if no metadata file exists at the location
*/
public TableMetadata loadTableMetadataFromLocation(String metadataLocation) {
try (FileIO fileIO = CatalogUtil.loadFileIO(fileIOImpl(),
fileIOProperties(), null)) {
return TableMetadataParser.read(fileIO, metadataLocation);
+ } catch (NotFoundException e) {
+ // The location comes from the request, so a missing file is a client
error. 404 is reserved
+ // by the REST spec for a namespace or table that does not exist.
+ throw new BadRequestException("Metadata location %s does not exist",
metadataLocation);
}
}
diff --git
a/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/ops/TestIcebergCatalogWrapper.java
b/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/ops/TestIcebergCatalogWrapper.java
index e0dfe9dd98..8e7ff98bfe 100644
---
a/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/ops/TestIcebergCatalogWrapper.java
+++
b/iceberg/iceberg-common/src/test/java/org/apache/gravitino/iceberg/common/ops/TestIcebergCatalogWrapper.java
@@ -313,6 +313,19 @@ public class TestIcebergCatalogWrapper {
}
}
+ @Test
+ public void testLoadTableMetadataFromMissingLocationIsBadRequest(@TempDir
Path warehouseDir)
+ throws Exception {
+ try (IcebergCatalogWrapper wrapper =
+ new IcebergCatalogWrapper(new
IcebergConfig(sqliteConfig(warehouseDir)))) {
+ String location =
warehouseDir.resolve("missing/v1.metadata.json").toUri().toString();
+ BadRequestException e =
+ Assertions.assertThrows(
+ BadRequestException.class, () ->
wrapper.loadTableMetadataFromLocation(location));
+ Assertions.assertTrue(e.getMessage().contains("does not exist"),
e.getMessage());
+ }
+ }
+
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testPurgeDeletesWhatCanBeReadWhenAManifestListIsMissing(