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 2472719ca4 [Cherry-pick to branch-1.3] [#12654] fix(core): Fix fileset
schema location resolution when schema properties omit location (#12655)
(#12668)
2472719ca4 is described below
commit 2472719ca4bf6de982b8a8793b5fe4f1415fd56c
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Aug 27 17:53:21 2026 +0800
[Cherry-pick to branch-1.3] [#12654] fix(core): Fix fileset schema location
resolution when schema properties omit location (#12655) (#12668)
**Cherry-pick Information:**
- Original commit: 364a4edb77def2505622ec2d5565841640755272
- Target branch: `branch-1.3`
- Status: ✅ Clean cherry-pick (no conflicts)
Co-authored-by: Tanay Paul <[email protected]>
---
.../authorization/AuthorizationUtils.java | 24 +++++++++--------
.../authorization/TestAuthorizationUtils.java | 31 ++++++++++++++++++++--
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java
b/core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java
index 7ac6008c1d..a27fdac557 100644
---
a/core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java
+++
b/core/src/main/java/org/apache/gravitino/authorization/AuthorizationUtils.java
@@ -570,19 +570,21 @@ public class AuthorizationUtils {
case FILESET:
if ("fileset".equals(catalogObj.provider())) {
- if (schema.properties().containsKey(FILESET_SCHEMA_LOCATION)) {
- String schemaLocation =
schema.properties().get(FILESET_SCHEMA_LOCATION);
- if (StringUtils.isNotBlank(schemaLocation)) {
+ String schemaLocation =
+ schema.properties() == null
+ ? null
+ : schema.properties().get(FILESET_SCHEMA_LOCATION);
+ if (StringUtils.isNotBlank(schemaLocation)) {
+ locations.add(schemaLocation);
+ } else if (catalogObj.properties() != null
+ &&
catalogObj.properties().containsKey(FILESET_CATALOG_LOCATION)) {
+ String catalogLocation =
catalogObj.properties().get(FILESET_CATALOG_LOCATION);
+ if (StringUtils.isNotBlank(catalogLocation)) {
+ schemaLocation = catalogLocation + "/" + schema.name();
locations.add(schemaLocation);
- } else if
(catalogObj.properties().containsKey(FILESET_CATALOG_LOCATION)) {
- String catalogLocation =
catalogObj.properties().get(FILESET_CATALOG_LOCATION);
- if (StringUtils.isNotBlank(catalogLocation)) {
- schemaLocation = catalogLocation + "/" + schema.name();
- locations.add(schemaLocation);
- }
- } else {
- LOG.warn("Schema {} location is not found", ident);
}
+ } else {
+ LOG.warn("Schema {} location is not found", ident);
}
}
break;
diff --git
a/core/src/test/java/org/apache/gravitino/authorization/TestAuthorizationUtils.java
b/core/src/test/java/org/apache/gravitino/authorization/TestAuthorizationUtils.java
index e922449ce6..e568d6f825 100644
---
a/core/src/test/java/org/apache/gravitino/authorization/TestAuthorizationUtils.java
+++
b/core/src/test/java/org/apache/gravitino/authorization/TestAuthorizationUtils.java
@@ -22,6 +22,7 @@ import static org.apache.gravitino.Catalog.Type.FILESET;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
+import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.gravitino.Catalog;
@@ -271,9 +272,7 @@ class TestAuthorizationUtils {
Catalog catalog = Mockito.mock(Catalog.class);
Schema schema = Mockito.mock(Schema.class);
- Mockito.when(schema.properties()).thenReturn(ImmutableMap.of("location",
""));
Mockito.when(schema.name()).thenReturn("testSchema");
- Mockito.when(catalog.properties()).thenReturn(ImmutableMap.of("location",
"catalogLocation"));
Mockito.when(catalog.provider()).thenReturn("fileset");
Mockito.when(catalog.type()).thenReturn(FILESET);
Mockito.when(schemaDispatcher.loadSchema(Mockito.any())).thenReturn(schema);
@@ -286,18 +285,46 @@ class TestAuthorizationUtils {
FieldUtils.writeField(
GravitinoEnv.getInstance(), "internalSchemaDispatcher",
schemaDispatcher, true);
+ // Case 1: Schema has no location property (inherits catalog location)
+ Mockito.when(schema.properties()).thenReturn(Collections.emptyMap());
+ Mockito.when(catalog.properties()).thenReturn(ImmutableMap.of("location",
"catalogLocation"));
List<String> locations =
AuthorizationUtils.getMetadataObjectLocation(
NameIdentifier.of("catalog", "schema", "fileset"),
Entity.EntityType.SCHEMA);
Assertions.assertEquals(1, locations.size());
Assertions.assertEquals("catalogLocation/testSchema", locations.get(0));
+ // Case 2: Schema has null properties (inherits catalog location)
+ Mockito.when(schema.properties()).thenReturn(null);
+ locations =
+ AuthorizationUtils.getMetadataObjectLocation(
+ NameIdentifier.of("catalog", "schema", "fileset"),
Entity.EntityType.SCHEMA);
+ Assertions.assertEquals(1, locations.size());
+ Assertions.assertEquals("catalogLocation/testSchema", locations.get(0));
+
+ // Case 3: Schema location is empty string (falls back to catalog location)
+ Mockito.when(schema.properties()).thenReturn(ImmutableMap.of("location",
""));
+ locations =
+ AuthorizationUtils.getMetadataObjectLocation(
+ NameIdentifier.of("catalog", "schema", "fileset"),
Entity.EntityType.SCHEMA);
+ Assertions.assertEquals(1, locations.size());
+ Assertions.assertEquals("catalogLocation/testSchema", locations.get(0));
+
+ // Case 4: Schema has explicit location (takes precedence over catalog
location)
Mockito.when(schema.properties()).thenReturn(ImmutableMap.of("location",
"schemaLocation"));
locations =
AuthorizationUtils.getMetadataObjectLocation(
NameIdentifier.of("catalog", "schema", "fileset"),
Entity.EntityType.SCHEMA);
Assertions.assertEquals(1, locations.size());
Assertions.assertEquals("schemaLocation", locations.get(0));
+
+ // Case 5: Neither schema nor catalog has location property
+ Mockito.when(schema.properties()).thenReturn(Collections.emptyMap());
+ Mockito.when(catalog.properties()).thenReturn(Collections.emptyMap());
+ locations =
+ AuthorizationUtils.getMetadataObjectLocation(
+ NameIdentifier.of("catalog", "schema", "fileset"),
Entity.EntityType.SCHEMA);
+ Assertions.assertEquals(0, locations.size());
}
@Test