Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#14966] feat(domain): List direct domain members by default (#14967)

Jerry Shao038a5dd7e888
diff --git a/api/src/main/java/org/apache/gravitino/domain/Domain.java b/api/src/main/java/org/apache/gravitino/domain/Domain.java
index aad37563fc..4d3ba65793 100644
--- a/api/src/main/java/org/apache/gravitino/domain/Domain.java
+++ b/api/src/main/java/org/apache/gravitino/domain/Domain.java
@@ -34,10 +34,11 @@ import org.apache.gravitino.tag.TagValue;
/**
* A domain groups metadata objects from any catalog under a business name, such as "Finance". A
* leaf metadata object, of a type in {@link DomainMember#SUPPORTED_TYPES}, is a member of a domain
- * when it carries the domain's backing tag, directly or inherited from its catalog or schema;
- * catalogs and schemas are never members themselves. For the same tag, the assignment nearest to
- * the object wins: a table that carries {@code dept=hr} under a schema that carries {@code
- * dept=finance} is a member of the domain backed by {@code dept=hr} only.
+ * when it carries the domain's backing tag, directly or inherited from its catalog or schema. The
+ * default member listing includes catalogs and schemas that directly carry a backing tag. For a
+ * leaf object, the nearest assignment of the same tag wins: a table that carries {@code dept=hr}
+ * under a schema that carries {@code dept=finance} is a member of the domain backed by {@code
+ * dept=hr} only.
*
* <p>Names have 1 to 64 ASCII letters, digits, underscores or hyphens and may not start with a
* hyphen. The names {@code *} and {@code system} (in any letter case) are reserved.
@@ -266,15 +267,22 @@ public interface Domain extends Auditable {
/**
* Lists the members in the scope of this domain that match the filter. The scope of a top-level
* domain is its own members plus the members of its sub-domains visible to the caller; the scope
- * of a sub-domain is its own members. Only objects of the {@link DomainMember#SUPPORTED_TYPES
- * supported types} are members, and only the members the caller can access are returned.
+ * of a sub-domain is its own members. Only the members the caller can access are returned, and an
+ * object is listed once, with all its {@link DomainMember#relations() relations} to this domain.
*
- * <p>A catalog or schema that carries a backing tag is expanded to the leaf objects under it that
- * Gravitino has recorded, and the catalog or schema itself is not listed. Objects of an external
- * catalog that Gravitino has not recorded yet are not listed. An object is listed once, with all
- * its {@link DomainMember#relations() relations} to this domain. The members of this domain
- * itself are the listed members whose relations include {@link DomainRelation.Type#DIRECT} or
- * {@link DomainRelation.Type#INHERITED}.
+ * <p>By default the direct members are listed: the objects that carry a backing tag in the scope
+ * themselves, which are leaf objects of the {@link DomainMember#SUPPORTED_TYPES supported types},
+ * catalogs and schemas. A directly tagged descendant is listed even when its catalog or schema
+ * also matches. Descendants that match only through inheritance require expansion. The relations
+ * are {@link DomainRelation.Type#DIRECT} for this domain's own assignments and {@link
+ * DomainRelation.Type#VIA_SUBDOMAIN} for those of its sub-domains.
+ *
+ * <p>When the filter {@link DomainMemberFilter#expand() expands} the listing, a catalog or schema
+ * that carries a backing tag is expanded to the leaf objects under it that Gravitino has
+ * recorded, and the catalog or schema itself is not listed. Objects of an external catalog that
+ * Gravitino has not recorded yet are not listed. The members of this domain itself are the listed
+ * members whose relations include {@link DomainRelation.Type#DIRECT} or {@link
+ * DomainRelation.Type#INHERITED}.
*
* @param filter The filter of the members. {@code DomainMemberFilter.builder().build()} lists the
* whole scope of this domain.
diff --git a/api/src/main/java/org/apache/gravitino/domain/DomainMember.java b/api/src/main/java/org/apache/gravitino/domain/DomainMember.java
index d040acf9b0..7104f67e1d 100644
--- a/api/src/main/java/org/apache/gravitino/domain/DomainMember.java
+++ b/api/src/main/java/org/apache/gravitino/domain/DomainMember.java
@@ -24,14 +24,26 @@ import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.annotation.Evolving;
/**
- * A metadata object that is a member of a domain. Only leaf objects, of the {@link #SUPPORTED_TYPES
- * supported types}, are members. Catalogs and schemas are never members: a backing tag on a catalog
- * or schema makes the leaf objects under it members through tag inheritance.
+ * A metadata object that is a member of a domain.
+ *
+ * <p>By default a domain lists its direct members: the objects that carry its backing tag
+ * themselves. A direct member is a leaf object of the {@link #SUPPORTED_TYPES supported types} or a
+ * catalog or schema of the {@link #CONTAINER_TYPES container types}. A catalog or schema member is
+ * listed once and includes its children: the leaf objects under it inherit the backing tag unless a
+ * nearer assignment of the same tag overrides it.
+ *
+ * <p>When the listing is {@link DomainMemberFilter#expand() expanded}, a catalog or schema member
+ * is replaced by the recorded leaf objects under it that inherit the backing tag, so only leaf
+ * objects are listed.
*/
@Evolving
public interface DomainMember {
- /** The metadata object types that can be members of a domain, all of them leaf objects. */
+ /**
+ * The leaf metadata object types that can be members of a domain. These are the only types listed
+ * by an {@link DomainMemberFilter#expand() expanded} listing, and the only types whose domains
+ * can be looked up with {@link SupportsDomains}.
+ */
Set<MetadataObject.Type> SUPPORTED_TYPES =
Sets.immutableEnumSet(
MetadataObject.Type.TABLE,
@@ -41,6 +53,14 @@ public interface DomainMember {
MetadataObject.Type.MODEL,
MetadataObject.Type.SEMANTIC_MODEL);
+ /**
+ * The container metadata object types that can be direct members of a domain. A member of these
+ * types includes its children, and is listed only when the listing is not {@link
+ * DomainMemberFilter#expand() expanded}.
+ */
+ Set<MetadataObject.Type> CONTAINER_TYPES =
+ Sets.immutableEnumSet(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA);
+
/**
* Returns the metadata object that is a member of the domain.
*
@@ -51,14 +71,19 @@ public interface DomainMember {
/**
* Returns how the member relates to the listed domain. The {@link DomainMemberFilter} selects the
* members only: every relation of a listed member to the listed domain is reported, with no
- * precedence among them, whatever domains the filter selects. For example, when schema {@code
- * cat.db} carries the backing tag of "Finance" and table {@code cat.db.trades} carries that of
- * its sub-domain "Trading", listing Finance reports the table as {@link
+ * precedence among them, whatever domains the filter selects. For example, in an expanded listing
+ * when schema {@code cat.db} carries the backing tag of "Finance" and table {@code cat.db.trades}
+ * carries that of its sub-domain "Trading", listing Finance reports the table as {@link
* DomainRelation.Type#INHERITED} from {@code cat.db} and {@link
* DomainRelation.Type#VIA_SUBDOMAIN} Trading. The member belongs to the listed domain itself when
* its relations include {@link DomainRelation.Type#DIRECT} or {@link
* DomainRelation.Type#INHERITED}.
*
+ * <p>Without expansion, a member carries the backing tag itself, so its relations are only {@link
+ * DomainRelation.Type#DIRECT} and {@link DomainRelation.Type#VIA_SUBDOMAIN}. The example above
+ * then lists schema {@code cat.db} as DIRECT and table {@code cat.db.trades} as VIA_SUBDOMAIN
+ * Trading.
+ *
* @return The relations of the member to the listed domain, never empty.
*/
DomainRelation[] relations();
diff --git a/api/src/main/java/org/apache/gravitino/domain/DomainMemberFilter.java b/api/src/main/java/org/apache/gravitino/domain/DomainMemberFilter.java
index e852a7d1f9..89dfca8e14 100644
--- a/api/src/main/java/org/apache/gravitino/domain/DomainMemberFilter.java
+++ b/api/src/main/java/org/apache/gravitino/domain/DomainMemberFilter.java
@@ -46,8 +46,12 @@ import org.apache.gravitino.annotation.Evolving;
* </ul>
*
* <p>The members of the listed domain itself are the listed members whose {@link
- * DomainMember#relations() relations} include {@link DomainRelation.Type#DIRECT} or {@link
- * DomainRelation.Type#INHERITED}; select them to keep only those.
+ * DomainMember#relations() relations} include {@link DomainRelation.Type#DIRECT} or, when the
+ * listing is expanded, {@link DomainRelation.Type#INHERITED}; select them to keep only those.
+ *
+ * <p>The expand option chooses what is listed. Without it, the default, the objects that carry a
+ * backing tag themselves are listed, including catalogs and schemas, each once. With it, a catalog
+ * or schema is replaced by the recorded leaf objects under it that inherit the backing tag.
*/
@Evolving
public final class DomainMemberFilter {
@@ -55,11 +59,13 @@ public final class DomainMemberFilter {
private final Set<MetadataObject.Type> types;
@Nullable private final String nameContains;
private final Set<String> domains;
+ private final boolean expand;
private DomainMemberFilter(Builder builder) {
this.types = builder.types;
this.nameContains = builder.nameContains;
this.domains = builder.domains;
+ this.expand = builder.expand;
}
/**
@@ -74,8 +80,9 @@ public final class DomainMemberFilter {
/**
* Returns the metadata object types of the members to list.
*
- * @return The metadata object types, or an empty set to list members of all {@link
- * DomainMember#SUPPORTED_TYPES supported types}.
+ * @return The metadata object types, or an empty set to list members of all types: the {@link
+ * DomainMember#SUPPORTED_TYPES supported types} and, without expansion, the {@link
+ * DomainMember#CONTAINER_TYPES container types}.
*/
public Set<MetadataObject.Type> types() {
return types;
@@ -100,6 +107,18 @@ public final class DomainMemberFilter {
return domains;
}
+ /**
+ * Returns whether catalog and schema members are expanded to the recorded leaf objects under
+ * them.
+ *
+ * @return {@code true} to list leaf objects only, with {@link DomainRelation.Type#INHERITED}
+ * relations for the leaf objects that inherit a backing tag; {@code false}, the default, to
+ * list the objects that carry a backing tag themselves.
+ */
+ public boolean expand() {
+ return expand;
+ }
+
/**
* Compares this filter with another object.
*
@@ -117,7 +136,8 @@ public final class DomainMemberFilter {
DomainMemberFilter that = (DomainMemberFilter) other;
return types.equals(that.types)
&& Objects.equals(nameContains, that.nameContains)
- && domains.equals(that.domains);
+ && domains.equals(that.domains)
+ && expand == that.expand;
}
/**
@@ -127,7 +147,7 @@ public final class DomainMemberFilter {
*/
@Override
public int hashCode() {
- return Objects.hash(types, nameContains, domains);
+ return Objects.hash(types, nameContains, domains, expand);
}
/**
@@ -144,6 +164,8 @@ public final class DomainMemberFilter {
+ nameContains
+ ", domains="
+ domains
+ + ", expand="
+ + expand
+ "}";
}
@@ -153,27 +175,32 @@ public final class DomainMemberFilter {
private Set<MetadataObject.Type> types = ImmutableSet.of();
@Nullable private String nameContains;
private Set<String> domains = ImmutableSet.of();
+ private boolean expand;
private Builder() {}
/**
- * Sets the metadata object types of the members to list. Defaults to all {@link
- * DomainMember#SUPPORTED_TYPES supported types}.
+ * Sets the metadata object types of the members to list. Defaults to all types. A type is one
+ * of the {@link DomainMember#SUPPORTED_TYPES supported types} or, for a listing that is not
+ * expanded, one of the {@link DomainMember#CONTAINER_TYPES container types}.
*
- * @param types The metadata object types, or none to list members of all supported types.
+ * @param types The metadata object types, or none to list members of all types.
* @return This builder.
* @throws IllegalArgumentException If the types are null, contain null, or contain a type that
- * is not in {@link DomainMember#SUPPORTED_TYPES}.
+ * is in neither {@link DomainMember#SUPPORTED_TYPES} nor {@link
+ * DomainMember#CONTAINER_TYPES}.
*/
public Builder withTypes(MetadataObject.Type... types) {
Preconditions.checkArgument(types != null, "types must not be null");
for (MetadataObject.Type type : types) {
Preconditions.checkArgument(type != null, "types must not contain null");
Preconditions.checkArgument(
- DomainMember.SUPPORTED_TYPES.contains(type),
- "Type %s cannot be a domain member, supported types are %s",
+ DomainMember.SUPPORTED_TYPES.contains(type)
+ || DomainMember.CONTAINER_TYPES.contains(type),
+ "Type %s cannot be a domain member, supported types are %s and %s",
type,
- DomainMember.SUPPORTED_TYPES);
+ DomainMember.SUPPORTED_TYPES,
+ DomainMember.CONTAINER_TYPES);
}
this.types = ImmutableSet.copyOf(types);
return this;
@@ -215,12 +242,31 @@ public final class DomainMemberFilter {
return this;
}
+ /**
+ * Sets whether catalog and schema members are expanded to the recorded leaf objects under them.
+ * Defaults to {@code false}.
+ *
+ * @param expand {@code true} to list leaf objects only, {@code false} to list the objects that
+ * carry a backing tag themselves.
+ * @return This builder.
+ */
+ public Builder withExpand(boolean expand) {
+ this.expand = expand;
+ return this;
+ }
+
/**
* Builds a domain member filter.
*
* @return The immutable domain member filter.
+ * @throws IllegalArgumentException If the listing is expanded and the types include a {@link
+ * DomainMember#CONTAINER_TYPES container type}, which an expanded listing never lists.
*/
public DomainMemberFilter build() {
+ Preconditions.checkArgument(
+ !expand || types.stream().noneMatch(DomainMember.CONTAINER_TYPES::contains),
+ "An expanded listing has only leaf members, types %s are not supported with expand",
+ DomainMember.CONTAINER_TYPES);
return new DomainMemberFilter(this);
}
}
diff --git a/api/src/main/java/org/apache/gravitino/domain/DomainRelation.java b/api/src/main/java/org/apache/gravitino/domain/DomainRelation.java
index f1a2041f28..af0b91cdad 100644
--- a/api/src/main/java/org/apache/gravitino/domain/DomainRelation.java
+++ b/api/src/main/java/org/apache/gravitino/domain/DomainRelation.java
@@ -28,10 +28,10 @@ import org.apache.gravitino.MetadataObjects;
import org.apache.gravitino.annotation.Evolving;
/**
- * How a leaf metadata object relates to a domain, always relative to the listed domain. An object
- * can relate to a domain in several ways at once, and every relation that applies is reported, with
- * no precedence among them. For example, a table whose schema carries the backing tag of "Finance"
- * and which itself carries that of its sub-domain "Trading" relates to Finance as {@link
+ * How a metadata object relates to a domain, always relative to the listed domain. An object can
+ * relate to a domain in several ways at once, and every relation that applies is reported, with no
+ * precedence among them. For example, a table whose schema carries the backing tag of "Finance" and
+ * which itself carries that of its sub-domain "Trading" relates to Finance as {@link
* Type#INHERITED} from the schema and as {@link Type#VIA_SUBDOMAIN} Trading.
*/
@Evolving
diff --git a/api/src/main/java/org/apache/gravitino/domain/SupportsDomains.java b/api/src/main/java/org/apache/gravitino/domain/SupportsDomains.java
index 11e2ed32fe..c29e61d6d6 100644
--- a/api/src/main/java/org/apache/gravitino/domain/SupportsDomains.java
+++ b/api/src/main/java/org/apache/gravitino/domain/SupportsDomains.java
@@ -21,9 +21,9 @@ package org.apache.gravitino.domain;
import org.apache.gravitino.annotation.Evolving;
/**
- * Interface for listing the domains of a leaf metadata object, such as a table, view or fileset.
- * Catalogs and schemas do not support it, since they are never members of a domain; the domain a
- * catalog or schema passes down to the objects under it is visible from its tags.
+ * Interface for listing the domains of a leaf metadata object, such as a table, view or fileset. A
+ * directly tagged catalog or schema appears in the domain's default member listing. This reverse
+ * lookup is available only on leaf objects.
*
* <p>The domains listed are all the domains visible to the caller whose scope contains the object:
* the domains whose backing tag the object's effective tags match, and the parents of those that
diff --git a/api/src/test/java/org/apache/gravitino/domain/TestDomainMemberFilter.java b/api/src/test/java/org/apache/gravitino/domain/TestDomainMemberFilter.java
index ed2b249268..a58c20696a 100644
--- a/api/src/test/java/org/apache/gravitino/domain/TestDomainMemberFilter.java
+++ b/api/src/test/java/org/apache/gravitino/domain/TestDomainMemberFilter.java
@@ -31,6 +31,7 @@ public class TestDomainMemberFilter {
Assertions.assertTrue(filter.types().isEmpty());
Assertions.assertFalse(filter.nameContains().isPresent());
Assertions.assertTrue(filter.domains().isEmpty());
+ Assertions.assertFalse(filter.expand());
Assertions.assertEquals(DomainMemberFilter.builder().build(), filter);
Assertions.assertEquals(DomainMemberFilter.builder().build().hashCode(), filter.hashCode());
@@ -121,10 +122,29 @@ public class TestDomainMemberFilter {
for (MetadataObject.Type type : DomainMember.SUPPORTED_TYPES) {
Assertions.assertEquals(
ImmutableSet.of(type), DomainMemberFilter.builder().withTypes(type).build().types());
+ Assertions.assertEquals(
+ ImmutableSet.of(type),
+ DomainMemberFilter.builder().withTypes(type).withExpand(true).build().types());
+ }
+
+ // Catalogs and schemas are direct members, listed only without expansion.
+ for (MetadataObject.Type type : DomainMember.CONTAINER_TYPES) {
+ Assertions.assertEquals(
+ ImmutableSet.of(type), DomainMemberFilter.builder().withTypes(type).build().types());
+ IllegalArgumentException e =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ DomainMemberFilter.builder()
+ .withTypes(MetadataObject.Type.TABLE, type)
+ .withExpand(true)
+ .build());
+ Assertions.assertTrue(e.getMessage().contains("expand"));
}
for (MetadataObject.Type type : MetadataObject.Type.values()) {
- if (!DomainMember.SUPPORTED_TYPES.contains(type)) {
+ if (!DomainMember.SUPPORTED_TYPES.contains(type)
+ && !DomainMember.CONTAINER_TYPES.contains(type)) {
IllegalArgumentException e =
Assertions.assertThrows(
IllegalArgumentException.class,
@@ -133,7 +153,7 @@ public class TestDomainMemberFilter {
}
}
- // Only leaf objects are members: never catalogs, schemas, columns, functions or domains.
+ // Leaf types stay separate from container types, as reverse lookup accepts only leaves.
Assertions.assertEquals(
ImmutableSet.of(
MetadataObject.Type.TABLE,
@@ -143,12 +163,23 @@ public class TestDomainMemberFilter {
MetadataObject.Type.MODEL,
MetadataObject.Type.SEMANTIC_MODEL),
DomainMember.SUPPORTED_TYPES);
- Assertions.assertThrows(
- IllegalArgumentException.class,
- () -> DomainMemberFilter.builder().withTypes(MetadataObject.Type.CATALOG));
- Assertions.assertThrows(
- IllegalArgumentException.class,
- () -> DomainMemberFilter.builder().withTypes(MetadataObject.Type.SCHEMA));
+ Assertions.assertEquals(
+ ImmutableSet.of(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA),
+ DomainMember.CONTAINER_TYPES);
+ }
+
+ @Test
+ public void testExpand() {
+ DomainMemberFilter expanded = DomainMemberFilter.builder().withExpand(true).build();
+ Assertions.assertTrue(expanded.expand());
+ Assertions.assertNotEquals(DomainMemberFilter.builder().build(), expanded);
+ Assertions.assertEquals(DomainMemberFilter.builder().withExpand(true).build(), expanded);
+ Assertions.assertEquals(
+ DomainMemberFilter.builder().withExpand(true).build().hashCode(), expanded.hashCode());
+ Assertions.assertTrue(expanded.toString().contains("expand=true"));
+ Assertions.assertEquals(
+ DomainMemberFilter.builder().build(),
+ DomainMemberFilter.builder().withExpand(true).withExpand(false).build());
}
@Test
diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericDomain.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericDomain.java
index ec177f48a7..5b24f3e76c 100644
--- a/clients/client-java/src/main/java/org/apache/gravitino/client/GenericDomain.java
+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GenericDomain.java
@@ -234,6 +234,9 @@ class GenericDomain implements Domain {
params.put("types", filter.types().stream().map(Enum::name).collect(Collectors.joining(",")));
}
filter.nameContains().ifPresent(value -> params.put("nameContains", value));
+ if (filter.expand()) {
+ params.put("expand", "true");
+ }
// Send each domain scope as a separate query parameter.
String scopes =
filter.domains().stream()
diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/TestDomainOperations.java b/clients/client-java/src/test/java/org/apache/gravitino/client/TestDomainOperations.java
index 97e980d807..349debfbed 100644
--- a/clients/client-java/src/test/java/org/apache/gravitino/client/TestDomainOperations.java
+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/TestDomainOperations.java
@@ -244,6 +244,83 @@ public class TestDomainOperations extends TestBase {
assertSnapshot(domain.listSubdomainsInfo()[0], child);
}
+ /**
+ * Verifies that direct catalog and schema members deserialize and that expand is sent only when
+ * set.
+ *
+ * @throws Exception if HTTP mock setup fails
+ */
+ @Test
+ public void testDirectContainerMembersAndExpand() throws Exception {
+ Domain domain = domain();
+ MetadataObject catalog = MetadataObjects.parse("cat", MetadataObject.Type.CATALOG);
+ MetadataObject schema = MetadataObjects.parse("cat.db", MetadataObject.Type.SCHEMA);
+ MetadataObject table = MetadataObjects.parse("cat.db.table", MetadataObject.Type.TABLE);
+ DomainMemberListResponse containers =
+ new DomainMemberListResponse(
+ new DomainMemberDTO[] {
+ memberDTO(catalog, DomainRelation.direct()),
+ memberDTO(schema, DomainRelation.viaSubdomain("Tax"))
+ });
+ DomainMemberListResponse leaves =
+ new DomainMemberListResponse(
+ new DomainMemberDTO[] {memberDTO(table, DomainRelation.inherited(catalog))});
+ mockServer
+ .when(
+ HttpRequest.request(PATH + "/objects")
+ .withMethod("GET")
+ .withQueryStringParameters(
+ new Parameter("types", "TABLE"), new Parameter("expand", "true")),
+ Times.exactly(1))
+ .respond(
+ HttpResponse.response()
+ .withStatusCode(200)
+ .withBody(MAPPER.writeValueAsString(leaves)));
+ mockServer
+ .when(
+ HttpRequest.request(PATH + "/objects")
+ .withMethod("GET")
+ .withQueryStringParameters(new Parameter("types", "CATALOG,SCHEMA")),
+ Times.exactly(1))
+ .respond(
+ HttpResponse.response()
+ .withStatusCode(200)
+ .withBody(MAPPER.writeValueAsString(containers)));
+
+ DomainMember[] expanded =
+ domain.listMembers(
+ DomainMemberFilter.builder()
+ .withTypes(MetadataObject.Type.TABLE)
+ .withExpand(true)
+ .build());
+ Assertions.assertEquals(1, expanded.length);
+ Assertions.assertEquals(table, expanded[0].object());
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.inherited(catalog)}, expanded[0].relations());
+
+ DomainMember[] members =
+ domain.listMembers(
+ DomainMemberFilter.builder()
+ .withTypes(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA)
+ .build());
+ Assertions.assertEquals(2, members.length);
+ Assertions.assertEquals(catalog, members[0].object());
+ Assertions.assertTrue(DomainMember.CONTAINER_TYPES.contains(members[0].object().type()));
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct()}, members[0].relations());
+ Assertions.assertEquals(schema, members[1].object());
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Tax")}, members[1].relations());
+
+ HttpRequest[] recorded =
+ mockServer.retrieveRecordedRequests(
+ HttpRequest.request(PATH + "/objects")
+ .withMethod("GET")
+ .withQueryStringParameter("types", "CATALOG,SCHEMA"));
+ Assertions.assertEquals(1, recorded.length);
+ Assertions.assertFalse(recorded[0].getQueryStringParameters().containsEntry("expand", "true"));
+ }
+
/**
* Verifies domain client behavior.
*
@@ -450,4 +527,19 @@ public class TestDomainOperations extends TestBase {
Assertions.assertEquals(expected.getAudit(), actual.auditInfo());
Assertions.assertEquals(0, actual.relations().length);
}
+
+ private static DomainMemberDTO memberDTO(MetadataObject object, DomainRelation... relations) {
+ return DomainMemberDTO.from(
+ new DomainMember() {
+ @Override
+ public MetadataObject object() {
+ return object;
+ }
+
+ @Override
+ public DomainRelation[] relations() {
+ return relations;
+ }
+ });
+ }
}
diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java
index d60cbe06f0..6b579a0ecf 100644
--- a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java
+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainAuthorizationIT.java
@@ -220,7 +220,9 @@ public class DomainAuthorizationIT extends DomainIT {
try (GravitinoAdminClient readerClient = userClient("object_reader")) {
GravitinoMetalake reader = readerClient.loadMetalake(metalake.name());
DomainMember[] visible =
- reader.getDomain(parent.name()).listMembers(DomainMemberFilter.builder().build());
+ reader
+ .getDomain(parent.name())
+ .listMembers(DomainMemberFilter.builder().withExpand(true).build());
assertEquals(1, visible.length);
assertEquals("ice.schema.orders", visible[0].object().fullName());
assertEquals(DomainRelation.Type.INHERITED, visible[0].relations()[0].type());
@@ -233,12 +235,16 @@ public class DomainAuthorizationIT extends DomainIT {
0,
reader
.getDomain(parent.name())
- .listMembers(DomainMemberFilter.builder().withDomains(child.name()).build())
+ .listMembers(
+ DomainMemberFilter.builder().withExpand(true).withDomains(child.name()).build())
.length);
// The draft child must not contribute a roll-up relation before publication.
child.publish();
- visible = reader.getDomain(parent.name()).listMembers(DomainMemberFilter.builder().build());
+ visible =
+ reader
+ .getDomain(parent.name())
+ .listMembers(DomainMemberFilter.builder().withExpand(true).build());
assertEquals(
Set.of(DomainRelation.Type.INHERITED, DomainRelation.Type.VIA_SUBDOMAIN),
Arrays.stream(visible[0].relations())
@@ -255,7 +261,9 @@ public class DomainAuthorizationIT extends DomainIT {
// A visible object's hidden child relation must disappear without hiding parent membership.
grant("object_reader", List.of(scope(child.name(), Privileges.UseDomain.deny())));
DomainMember[] parentOnly =
- reader.getDomain(parent.name()).listMembers(DomainMemberFilter.builder().build());
+ reader
+ .getDomain(parent.name())
+ .listMembers(DomainMemberFilter.builder().withExpand(true).build());
assertEquals(1, parentOnly.length);
assertEquals(1, parentOnly[0].relations().length);
assertEquals(DomainRelation.Type.INHERITED, parentOnly[0].relations()[0].type());
@@ -270,7 +278,10 @@ public class DomainAuthorizationIT extends DomainIT {
schemaScope, "orders", List.of(Privileges.SelectTable.deny()))));
assertEquals(
0,
- reader.getDomain(parent.name()).listMembers(DomainMemberFilter.builder().build()).length);
+ reader
+ .getDomain(parent.name())
+ .listMembers(DomainMemberFilter.builder().withExpand(true).build())
+ .length);
assertThrows(ForbiddenException.class, () -> readerTable.supportsDomains().listDomains());
}
}
@@ -365,7 +376,8 @@ public class DomainAuthorizationIT extends DomainIT {
Domain snapshot = reader.getDomain(child.name());
// USE_DOMAIN keeps reads available even when management is explicitly denied.
assertEquals(child.name(), snapshot.name());
- assertEquals(0, snapshot.listMembers(DomainMemberFilter.builder().build()).length);
+ assertEquals(
+ 0, snapshot.listMembers(DomainMemberFilter.builder().withExpand(true).build()).length);
assertEquals(0, snapshot.listSubdomains().length);
assertEquals(0, snapshot.listSubdomainsInfo().length);
assertThrows(
diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java
index 3241a1f3cd..bde5e560d1 100644
--- a/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java
+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/integration/test/DomainIT.java
@@ -271,6 +271,7 @@ public class DomainIT extends BaseIT {
0,
domain.listMembers(
DomainMemberFilter.builder()
+ .withExpand(true)
.withTypes(MetadataObject.Type.TABLE, MetadataObject.Type.VIEW)
.withDomains("Tax_EU", "Trading_US_East")
.withNameContains("x /?&+%,")
@@ -385,7 +386,7 @@ public class DomainIT extends BaseIT {
// An object can be inherited from Finance and reached through Trading at the same time.
Map<String, DomainMember> members =
- Arrays.stream(finance.listMembers(DomainMemberFilter.builder().build()))
+ Arrays.stream(finance.listMembers(DomainMemberFilter.builder().withExpand(true).build()))
.collect(Collectors.toMap(member -> member.object().fullName(), member -> member));
assertEquals(
Set.of(
@@ -402,6 +403,30 @@ public class DomainIT extends BaseIT {
.collect(Collectors.toSet()));
assertEquals(
DomainRelation.Type.DIRECT, members.get("files.schema.data").relations()[0].type());
+ assertEquals(
+ "ice.schema.hidden",
+ risk.listMembers(DomainMemberFilter.builder().withExpand(true).build())[0]
+ .object()
+ .fullName());
+
+ // By default the objects carrying a backing tag are listed, and the schema is listed once.
+ Map<String, DomainMember> direct =
+ Arrays.stream(finance.listMembers(DomainMemberFilter.builder().build()))
+ .collect(Collectors.toMap(member -> member.object().fullName(), member -> member));
+ assertEquals(
+ Set.of("ice.schema", "ice.schema.orders", "files.schema.data", "models.schema.model"),
+ direct.keySet());
+ assertEquals(MetadataObject.Type.SCHEMA, direct.get("ice.schema").object().type());
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct()}, direct.get("ice.schema").relations());
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain(child.name())},
+ direct.get("ice.schema.orders").relations());
+ assertEquals(
+ 1,
+ finance.listMembers(
+ DomainMemberFilter.builder().withTypes(MetadataObject.Type.SCHEMA).build())
+ .length);
assertEquals(
"ice.schema.hidden",
risk.listMembers(DomainMemberFilter.builder().build())[0].object().fullName());
@@ -417,27 +442,36 @@ public class DomainIT extends BaseIT {
assertEquals(
1,
finance.listMembers(
- DomainMemberFilter.builder().withDomains(child.name(), "unknown_scope").build())
+ DomainMemberFilter.builder()
+ .withExpand(true)
+ .withDomains(child.name(), "unknown_scope")
+ .build())
.length);
assertEquals(
5,
finance.listMembers(
- DomainMemberFilter.builder().withDomains(finance.name(), child.name()).build())
+ DomainMemberFilter.builder()
+ .withExpand(true)
+ .withDomains(finance.name(), child.name())
+ .build())
.length);
assertEquals(
2,
finance.listMembers(
DomainMemberFilter.builder()
+ .withExpand(true)
.withTypes(MetadataObject.Type.VIEW, MetadataObject.Type.MODEL)
.build())
.length);
assertEquals(
2,
- finance.listMembers(DomainMemberFilter.builder().withNameContains("ORDERS").build())
+ finance.listMembers(
+ DomainMemberFilter.builder().withExpand(true).withNameContains("ORDERS").build())
.length);
assertEquals(
0,
- finance.listMembers(DomainMemberFilter.builder().withNameContains("/ ?&+%,").build())
+ finance.listMembers(
+ DomainMemberFilter.builder().withExpand(true).withNameContains("/ ?&+%,").build())
.length);
// Membership roll-ups follow hierarchy changes without retagging the leaf object.
@@ -597,6 +631,7 @@ public class DomainIT extends BaseIT {
DomainMember[] selected =
parent.listMembers(
DomainMemberFilter.builder()
+ .withExpand(true)
.withDomains(first.name(), second.name())
.withTypes(MetadataObject.Type.TABLE)
.withNameContains("ORDERS")
@@ -607,6 +642,7 @@ public class DomainIT extends BaseIT {
0,
parent.listMembers(
DomainMemberFilter.builder()
+ .withExpand(true)
.withDomains(first.name())
.withTypes(MetadataObject.Type.VIEW)
.build())
@@ -615,7 +651,9 @@ public class DomainIT extends BaseIT {
// Child scopes do not include their siblings; detaching changes only the parent's roll-up.
assertEquals(
0,
- first.listMembers(DomainMemberFilter.builder().withDomains(second.name()).build()).length);
+ first.listMembers(
+ DomainMemberFilter.builder().withExpand(true).withDomains(second.name()).build())
+ .length);
table
.supportsTags()
.associateTags(new String[0], new String[] {parent.backingTag().orElseThrow().name()});
@@ -728,7 +766,7 @@ public class DomainIT extends BaseIT {
assertThrows(NoSuchDomainException.class, removed::listSubdomainsInfo);
assertThrows(
NoSuchDomainException.class,
- () -> removed.listMembers(DomainMemberFilter.builder().build()));
+ () -> removed.listMembers(DomainMemberFilter.builder().withExpand(true).build()));
assertThrows(
NoSuchDomainException.class,
() -> removed.createSubdomain("orphan", null, null, TagValue.noValue("orphan-tag"), true));
@@ -830,7 +868,7 @@ public class DomainIT extends BaseIT {
table.supportsTags().associateTags(new String[] {"value-contract-tag"}, new String[0]);
DomainMemberFilter filter =
- DomainMemberFilter.builder().withTypes(MetadataObject.Type.TABLE).build();
+ DomainMemberFilter.builder().withExpand(true).withTypes(MetadataObject.Type.TABLE).build();
DomainMember member = loaded.listMembers(filter)[0];
DomainMember reloaded = loaded.listMembers(filter)[0];
MetadataObject object = MetadataObjects.parse("ice.schema.orders", MetadataObject.Type.TABLE);
@@ -880,6 +918,7 @@ public class DomainIT extends BaseIT {
DomainMember[] members =
domain.listMembers(
DomainMemberFilter.builder()
+ .withExpand(true)
.withTypes(MetadataObject.Type.TABLE)
.withNameContains("ice.schema.orders")
.build());
diff --git a/clients/client-python/gravitino/api/domain/domain.py b/clients/client-python/gravitino/api/domain/domain.py
index 0787265b4a..4e712d4b38 100644
--- a/clients/client-python/gravitino/api/domain/domain.py
+++ b/clients/client-python/gravitino/api/domain/domain.py
@@ -134,5 +134,10 @@ class Domain(Auditable):
@abstractmethod
def list_members(self, member_filter: DomainMemberFilter) -> list[DomainMember]:
- """List accessible leaf objects and their relations in the selected scope."""
+ """List accessible members and their relations in the selected scope.
+
+ By default, members are the objects that carry a backing tag themselves,
+ including catalogs, schemas and their directly tagged descendants. Set
+ ``member_filter.expand`` to include recorded leaves that inherit a matching tag.
+ """
raise NotImplementedError
diff --git a/clients/client-python/gravitino/api/domain/domain_member.py b/clients/client-python/gravitino/api/domain/domain_member.py
index 02f495234b..92c92c7466 100644
--- a/clients/client-python/gravitino/api/domain/domain_member.py
+++ b/clients/client-python/gravitino/api/domain/domain_member.py
@@ -24,7 +24,13 @@ from gravitino.api.domain.domain_relation import DomainRelation
@dataclass(frozen=True)
class DomainMember:
- """A leaf object and every applicable relation to the listed domain."""
+ """An object and every applicable relation to the listed domain.
+
+ By default a listing returns direct members: objects that carry a backing tag
+ themselves, including catalogs and schemas (``CONTAINER_TYPES``). A directly tagged descendant
+ is listed even when its catalog or schema also matches. An expanded listing returns only leaf
+ objects (``SUPPORTED_TYPES``).
+ """
SUPPORTED_TYPES: ClassVar[frozenset[MetadataObject.Type]] = frozenset(
{
@@ -36,6 +42,9 @@ class DomainMember:
MetadataObject.Type.SEMANTIC_MODEL,
}
)
+ CONTAINER_TYPES: ClassVar[frozenset[MetadataObject.Type]] = frozenset(
+ {MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA}
+ )
_object: MetadataObject
_relations: tuple[DomainRelation, ...]
diff --git a/clients/client-python/gravitino/api/domain/domain_member_filter.py b/clients/client-python/gravitino/api/domain/domain_member_filter.py
index c6178fdc91..0f9a6deee7 100644
--- a/clients/client-python/gravitino/api/domain/domain_member_filter.py
+++ b/clients/client-python/gravitino/api/domain/domain_member_filter.py
@@ -31,14 +31,25 @@ class DomainMemberFilter:
Empty options do not narrow the result. Domains select the union of the named
scopes: the listed domain itself (including visible children), or its children.
Unknown or invisible scope names are ignored by the server.
+
+ By default, objects that carry a backing tag themselves are listed, including
+ catalogs and schemas, each once. With ``expand=True``, a catalog or schema is
+ replaced by the recorded leaf objects under it that inherit the backing tag, and
+ ``types`` must then name leaf types only.
"""
types: tuple[MetadataObject.Type, ...] = ()
name_contains: Optional[str] = None
domains: Sequence[str] = ()
+ expand: bool = False
def _criteria(self) -> tuple:
- return frozenset(self.types), self.name_contains, frozenset(self.domains)
+ return (
+ frozenset(self.types),
+ self.name_contains,
+ frozenset(self.domains),
+ self.expand,
+ )
def __eq__(self, other: object) -> bool:
if not isinstance(other, DomainMemberFilter):
@@ -49,6 +60,9 @@ class DomainMemberFilter:
return hash(self._criteria())
def __post_init__(self) -> None:
+ Precondition.check_argument(
+ isinstance(self.expand, bool), "expand must be a boolean"
+ )
Precondition.check_argument(self.types is not None, "types must not be None")
Precondition.check_argument(
self.domains is not None, "domains must not be None"
@@ -57,8 +71,17 @@ class DomainMemberFilter:
domains = (self.domains,) if isinstance(self.domains, str) else self.domains
object.__setattr__(self, "domains", tuple(dict.fromkeys(domains)))
Precondition.check_argument(
- all(t in DomainMember.SUPPORTED_TYPES for t in self.types),
- "Only leaf metadata types can be domain members",
+ all(
+ t in DomainMember.SUPPORTED_TYPES or t in DomainMember.CONTAINER_TYPES
+ for t in self.types
+ ),
+ "Only leaf, catalog and schema metadata types can be domain members",
+ )
+ Precondition.check_argument(
+ not self.expand
+ or all(t not in DomainMember.CONTAINER_TYPES for t in self.types),
+ "An expanded listing has only leaf members, catalog and schema types "
+ "are not supported with expand",
)
Precondition.check_argument(
self.name_contains is None
diff --git a/clients/client-python/gravitino/client/generic_domain.py b/clients/client-python/gravitino/client/generic_domain.py
index 4aa991a282..a776d19e05 100644
--- a/clients/client-python/gravitino/client/generic_domain.py
+++ b/clients/client-python/gravitino/client/generic_domain.py
@@ -218,6 +218,8 @@ class GenericDomain(Domain):
if member_filter.domains:
# Send each domain scope as a separate query parameter.
params["domains"] = list(member_filter.domains)
+ if member_filter.expand:
+ params["expand"] = "true"
response = self._client.get(
self._path + "/objects", params=params, error_handler=DOMAIN_ERROR_HANDLER
)
diff --git a/clients/client-python/tests/integration/domain_api_edges_mixin.py b/clients/client-python/tests/integration/domain_api_edges_mixin.py
index e9fcbb6944..851c416df4 100644
--- a/clients/client-python/tests/integration/domain_api_edges_mixin.py
+++ b/clients/client-python/tests/integration/domain_api_edges_mixin.py
@@ -79,7 +79,7 @@ class DomainApiEdgesMixin:
)
snapshot = reader.get_domain(child.name())
# Read permission remains effective despite an explicit management deny.
- self.assertEqual([], snapshot.list_members(DomainMemberFilter()))
+ self.assertEqual([], snapshot.list_members(DomainMemberFilter(expand=True)))
self.assertEqual([], snapshot.list_subdomains())
self.assertEqual([], snapshot.list_subdomains_info())
writes = {
@@ -245,7 +245,9 @@ class DomainApiEdgesMixin:
self.assertEqual({"key": "value"}, loaded.properties())
table.supports_tags().assign_tags(["value-contract-tag"])
- member_filter = DomainMemberFilter(types=[MetadataObject.Type.TABLE])
+ member_filter = DomainMemberFilter(
+ expand=True, types=[MetadataObject.Type.TABLE]
+ )
member = loaded.list_members(member_filter)[0]
reloaded = loaded.list_members(member_filter)[0]
metadata_object = MetadataObjects.parse(
@@ -300,7 +302,7 @@ class DomainApiEdgesMixin:
"backing_tag": lambda: removed.update_backing_tag(None),
"subdomains": removed.list_subdomains,
"subdomains_info": removed.list_subdomains_info,
- "members": lambda: removed.list_members(DomainMemberFilter()),
+ "members": lambda: removed.list_members(DomainMemberFilter(expand=True)),
"create_subdomain": lambda: removed.create_subdomain(
"orphan", None, {}, TagValue("orphan-tag"), True
),
diff --git a/clients/client-python/tests/integration/test_domain.py b/clients/client-python/tests/integration/test_domain.py
index bbdadfff9e..1e0a95bccb 100644
--- a/clients/client-python/tests/integration/test_domain.py
+++ b/clients/client-python/tests/integration/test_domain.py
@@ -275,6 +275,32 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
with self.assertRaises(DomainAlreadyExistsException):
self.lake.create_domain(parent.name(), None, {}, TagValue("unused"), True)
+ def _assert_direct_members(self, finance):
+ direct = {
+ m.object().full_name(): m
+ for m in finance.list_members(DomainMemberFilter())
+ }
+ self.assertEqual(
+ {
+ "ice.schema",
+ "ice.schema.orders",
+ "files.schema.data",
+ "models.schema.model",
+ },
+ set(direct),
+ )
+ self.assertEqual(
+ MetadataObject.Type.SCHEMA, direct["ice.schema"].object().type()
+ )
+ self.assertEqual(
+ [DomainRelation.Type.DIRECT],
+ [r.type() for r in direct["ice.schema"].relations()],
+ )
+ self.assertEqual(
+ [DomainRelation.Type.VIA_SUBDOMAIN],
+ [r.type() for r in direct["ice.schema.orders"].relations()],
+ )
+
def test_members_relations_filters_and_nearest_assignment(self):
catalog, table, hidden, view, semantic, fileset, model = self._catalogs()
self.lake.create_tag("department", None, {}, ["finance", "risk"])
@@ -302,7 +328,7 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
# The same table has both inherited and subdomain relations, with no precedence.
members = {
m.object().full_name(): m
- for m in finance.list_members(DomainMemberFilter())
+ for m in finance.list_members(DomainMemberFilter(expand=True))
}
self.assertEqual(
{
@@ -330,9 +356,14 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
)
self.assertEqual(
["ice.schema.hidden"],
- [m.object().full_name() for m in risk.list_members(DomainMemberFilter())],
+ [
+ m.object().full_name()
+ for m in risk.list_members(DomainMemberFilter(expand=True))
+ ],
)
+ self._assert_direct_members(finance)
+
# Reverse lookup must expose the same domain on every supported leaf resource.
for resource in (table, view, semantic, fileset, model):
self.assertIn(finance.name(), resource.supports_domains().list_domains())
@@ -347,7 +378,9 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
[
m.object().full_name()
for m in finance.list_members(
- DomainMemberFilter(domains=[child.name(), "unknown_scope"])
+ DomainMemberFilter(
+ expand=True, domains=[child.name(), "unknown_scope"]
+ )
)
],
)
@@ -355,7 +388,9 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
5,
len(
finance.list_members(
- DomainMemberFilter(domains=[finance.name(), child.name()])
+ DomainMemberFilter(
+ expand=True, domains=[finance.name(), child.name()]
+ )
)
),
)
@@ -365,19 +400,31 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
m.object().type()
for m in finance.list_members(
DomainMemberFilter(
- types=[MetadataObject.Type.VIEW, MetadataObject.Type.MODEL]
+ expand=True,
+ types=[MetadataObject.Type.VIEW, MetadataObject.Type.MODEL],
)
)
},
)
self.assertEqual(
- 2, len(finance.list_members(DomainMemberFilter(name_contains="ORDERS")))
+ 2,
+ len(
+ finance.list_members(
+ DomainMemberFilter(expand=True, name_contains="ORDERS")
+ )
+ ),
)
self.assertEqual(
- [], finance.list_members(DomainMemberFilter(name_contains="/ ?&+%,"))
+ [],
+ finance.list_members(
+ DomainMemberFilter(expand=True, name_contains="/ ?&+%,")
+ ),
)
self.assertEqual(
- [], finance.list_members(DomainMemberFilter(domains=["unknown_scope"]))
+ [],
+ finance.list_members(
+ DomainMemberFilter(expand=True, domains=["unknown_scope"])
+ ),
)
# Hierarchy and domain-name changes must appear without retagging any object.
@@ -553,7 +600,9 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
],
)
- visible = reader.get_domain(parent.name()).list_members(DomainMemberFilter())
+ visible = reader.get_domain(parent.name()).list_members(
+ DomainMemberFilter(expand=True)
+ )
self.assertEqual(
["ice.schema.orders"], [m.object().full_name() for m in visible]
)
@@ -570,13 +619,15 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
self.assertEqual(
[],
reader.get_domain(parent.name()).list_members(
- DomainMemberFilter(domains=[child.name()])
+ DomainMemberFilter(expand=True, domains=[child.name()])
),
)
# A hidden child contributes no roll-up relation until it is published.
child.publish()
- visible = reader.get_domain(parent.name()).list_members(DomainMemberFilter())
+ visible = reader.get_domain(parent.name()).list_members(
+ DomainMemberFilter(expand=True)
+ )
self.assertEqual(
{DomainRelation.Type.INHERITED, DomainRelation.Type.VIA_SUBDOMAIN},
{r.type() for r in visible[0].relations()},
@@ -594,7 +645,7 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
[self._scope(child.name(), [Privileges.deny("USE_DOMAIN")])],
)
parent_only = reader.get_domain(parent.name()).list_members(
- DomainMemberFilter()
+ DomainMemberFilter(expand=True)
)
self.assertEqual(1, len(parent_only))
self.assertEqual(
@@ -614,7 +665,10 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
],
)
self.assertEqual(
- [], reader.get_domain(parent.name()).list_members(DomainMemberFilter())
+ [],
+ reader.get_domain(parent.name()).list_members(
+ DomainMemberFilter(expand=True)
+ ),
)
with self.assertRaises(ForbiddenException):
lookup.list_domains()
@@ -686,7 +740,9 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
def _assert_table_relations(self, domain, table, expected):
members = domain.list_members(
DomainMemberFilter(
- types=[MetadataObject.Type.TABLE], name_contains="ice.schema.orders"
+ expand=True,
+ types=[MetadataObject.Type.TABLE],
+ name_contains="ice.schema.orders",
)
)
reverse = [
@@ -851,6 +907,7 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
self._assert_table_relations(second, table, {inherited_schema})
selected = parent.list_members(
DomainMemberFilter(
+ expand=True,
domains=[first.name(), second.name()],
types=[MetadataObject.Type.TABLE],
name_contains="ORDERS",
@@ -865,12 +922,17 @@ class TestDomain(DomainApiEdgesMixin, IntegrationTestEnv):
[],
parent.list_members(
DomainMemberFilter(
- domains=[first.name()], types=[MetadataObject.Type.VIEW]
+ expand=True,
+ domains=[first.name()],
+ types=[MetadataObject.Type.VIEW],
)
),
)
self.assertEqual(
- [], first.list_members(DomainMemberFilter(domains=[second.name()]))
+ [],
+ first.list_members(
+ DomainMemberFilter(expand=True, domains=[second.name()])
+ ),
)
# Removing one route must preserve the other routes and the member's own child scope.
diff --git a/clients/client-python/tests/unittests/test_domain_client.py b/clients/client-python/tests/unittests/test_domain_client.py
index 3aff77b70d..51bc8cf68e 100644
--- a/clients/client-python/tests/unittests/test_domain_client.py
+++ b/clients/client-python/tests/unittests/test_domain_client.py
@@ -31,6 +31,7 @@ from gravitino.api.semantic.semantic_model import SemanticModel
from gravitino.api.domain import (
Domain,
DomainChange,
+ DomainMember,
DomainMemberFilter,
DomainRelation,
SupportsDomains,
@@ -451,6 +452,57 @@ class TestDomainClient(unittest.TestCase):
query={"domains": ["Tax"]},
)
+ def test_direct_and_expanded_members(self):
+ self._respond(
+ {
+ "code": 0,
+ "members": [
+ {
+ "object": {"fullName": "cat", "type": "catalog"},
+ "relations": [{"relation": "direct"}],
+ },
+ {
+ "object": {"fullName": "cat.db", "type": "schema"},
+ "relations": [
+ {
+ "relation": "via_subdomain",
+ "source": {"fullName": "Tax", "type": "domain"},
+ }
+ ],
+ },
+ ],
+ }
+ )
+ member_filter = DomainMemberFilter(
+ types=(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA)
+ )
+ self.assertFalse(member_filter.expand)
+ members = self._domain().list_members(member_filter)
+ self._request(
+ "GET",
+ self.path + "/" + encode_string(self.NAME) + "/objects",
+ query={"types": ["CATALOG,SCHEMA"]},
+ )
+ self.assertEqual(
+ [MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA],
+ [m.object().type() for m in members],
+ )
+ self.assertTrue(
+ all(m.object().type() in DomainMember.CONTAINER_TYPES for m in members)
+ )
+ self.assertEqual(DomainRelation.Type.DIRECT, members[0].relations()[0].type())
+ self.assertEqual("Tax", members[1].relations()[0].source().name())
+
+ self._respond({"code": 0, "members": []})
+ expanded = DomainMemberFilter(types=(MetadataObject.Type.TABLE,), expand=True)
+ self.assertNotEqual(DomainMemberFilter(types=expanded.types), expanded)
+ self._domain().list_members(expanded)
+ self._request(
+ "GET",
+ self.path + "/" + encode_string(self.NAME) + "/objects",
+ query={"types": ["TABLE"], "expand": ["true"]},
+ )
+
def test_domain_identifier_parent(self):
for parent in ("Finance", ""):
with self.subTest(parent=parent), self.assertRaises(
@@ -682,9 +734,18 @@ class TestDomainClient(unittest.TestCase):
with self.assertRaises(IllegalArgumentException):
TagValue(name, value)
for kwargs in (
+ {"expand": "false"},
+ {"expand": 1},
+ {"expand": None},
{"types": None},
{"types": [None]},
- {"types": [MetadataObject.Type.CATALOG]},
+ {"types": [MetadataObject.Type.FUNCTION]},
+ {"types": [MetadataObject.Type.COLUMN]},
+ {"types": [MetadataObject.Type.CATALOG], "expand": True},
+ {
+ "types": [MetadataObject.Type.TABLE, MetadataObject.Type.SCHEMA],
+ "expand": True,
+ },
{"domains": None},
{"domains": [None]},
{"domains": [" "]},
diff --git a/common/src/main/java/org/apache/gravitino/dto/domain/DomainMemberDTO.java b/common/src/main/java/org/apache/gravitino/dto/domain/DomainMemberDTO.java
index fc03802f63..5fe57a337e 100644
--- a/common/src/main/java/org/apache/gravitino/dto/domain/DomainMemberDTO.java
+++ b/common/src/main/java/org/apache/gravitino/dto/domain/DomainMemberDTO.java
@@ -27,7 +27,7 @@ import org.apache.gravitino.domain.DomainMember;
import org.apache.gravitino.dto.tag.MetadataObjectDTO;
import org.apache.gravitino.dto.util.DTOConverters;
-/** A recorded leaf member and all its relations to the queried domain. */
+/** A recorded member and all its relations to the queried domain. */
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DomainMemberDTO {
diff --git a/core/src/main/java/org/apache/gravitino/SupportsDomainOperations.java b/core/src/main/java/org/apache/gravitino/SupportsDomainOperations.java
index 258e584c04..691d0ff57f 100644
--- a/core/src/main/java/org/apache/gravitino/SupportsDomainOperations.java
+++ b/core/src/main/java/org/apache/gravitino/SupportsDomainOperations.java
@@ -22,7 +22,9 @@ import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import org.apache.gravitino.domain.Domain;
@@ -32,6 +34,7 @@ import org.apache.gravitino.exceptions.OptimisticLockException;
import org.apache.gravitino.exceptions.TagAlreadyExistsException;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.DomainEntity;
+import org.apache.gravitino.meta.GenericEntity;
import org.apache.gravitino.meta.TagEntity;
import org.apache.gravitino.tag.TagValue;
@@ -56,6 +59,12 @@ import org.apache.gravitino.tag.TagValue;
*/
public interface SupportsDomainOperations {
+ /** Number of domain or object IDs per direct membership lookup batch. */
+ int MEMBERSHIP_LOOKUP_BATCH_SIZE = 500;
+
+ /** Maximum visible domain IDs per candidate-restricted membership join. */
+ int JOINED_DOMAIN_BATCH_SIZE = 5_000;
+
/**
* Deletes a domain after checking its current state under the domain row lock.
*
@@ -241,6 +250,36 @@ public interface SupportsDomainOperations {
List<DomainEntity> listDomainsByBackingTagIds(String metalake, List<Long> backingTagIds)
throws IOException;
+ /**
+ * Lists live directly assigned objects for the selected domain bindings and object types.
+ *
+ * @param metalake The metalake containing the domains.
+ * @param domains Selected domains with backing tags.
+ * @param types The candidate metadata object types.
+ * @param selectedAssignments Previously resolved objects by selected domain ID. An empty map
+ * resolves names; otherwise only these objects can match, and their names are reused.
+ * @return Assigned objects keyed by domain ID.
+ * @throws IOException If the assignments cannot be read.
+ */
+ Map<Long, List<GenericEntity>> listDomainAssignments(
+ String metalake,
+ List<DomainEntity> domains,
+ Set<MetadataObject.Type> types,
+ Map<Long, List<GenericEntity>> selectedAssignments)
+ throws IOException;
+
+ /**
+ * Reads direct tag assignments for recorded domain member candidates of one type.
+ *
+ * @param metalake The metalake containing the objects.
+ * @param type The metadata object type.
+ * @param objectIds The stable IDs returned by the assignment lookup.
+ * @return Directly assigned tags and their values keyed by object ID.
+ * @throws IOException If the assignments cannot be read.
+ */
+ Map<Long, List<TagEntity>> listDirectTagsByObjectIds(
+ String metalake, MetadataObject.Type type, List<Long> objectIds) throws IOException;
+
/** The domains involved in a change, as read under the change's row locks. */
final class LockedDomainState {
diff --git a/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java b/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java
index 55a0dd0c51..243c2b7998 100644
--- a/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/domain/DomainDispatcher.java
@@ -276,13 +276,12 @@ public interface DomainDispatcher {
DomainEntity[] listSubdomainInfos(String metalake, String name) throws NoSuchDomainException;
/**
- * Lists recorded leaf objects in a domain's scope, with every applicable relation. Results are
- * unfiltered; server callers apply domain visibility and metadata access checks.
+ * Lists members in a domain's scope, with every applicable relation. Server callers apply domain
+ * visibility and metadata access checks.
*
- * <p>This operation is unpaginated. Catalog and schema assignments enumerate recorded leaf
- * objects, and each candidate requires effective-tag resolution, including ancestor lookups and
- * object existence checks. Query work grows with the candidate count and schema depth; type and
- * name filters do not impose a bound on the number of objects enumerated.
+ * <p>The default listing returns directly tagged objects, including catalogs and schemas. With
+ * expansion enabled, catalog and schema assignments enumerate recorded leaves and resolve their
+ * effective tags. Both modes return an unpaginated result.
*
* @param metalake The metalake name.
* @param name The listed domain.
diff --git a/core/src/main/java/org/apache/gravitino/domain/DomainMemberInfo.java b/core/src/main/java/org/apache/gravitino/domain/DomainMemberInfo.java
index e3ffaf6f2b..83bf096195 100644
--- a/core/src/main/java/org/apache/gravitino/domain/DomainMemberInfo.java
+++ b/core/src/main/java/org/apache/gravitino/domain/DomainMemberInfo.java
@@ -29,7 +29,7 @@ public final class DomainMemberInfo implements DomainMember {
/**
* Creates a member query result.
*
- * @param object The leaf metadata object.
+ * @param object The member metadata object.
* @param relations All relations to the queried domain.
*/
public DomainMemberInfo(MetadataObject object, DomainRelation[] relations) {
diff --git a/core/src/main/java/org/apache/gravitino/domain/DomainMembershipResolver.java b/core/src/main/java/org/apache/gravitino/domain/DomainMembershipResolver.java
index 4018947ceb..94384947f6 100644
--- a/core/src/main/java/org/apache/gravitino/domain/DomainMembershipResolver.java
+++ b/core/src/main/java/org/apache/gravitino/domain/DomainMembershipResolver.java
@@ -18,11 +18,22 @@
*/
package org.apache.gravitino.domain;
+import static org.apache.gravitino.SupportsDomainOperations.JOINED_DOMAIN_BATCH_SIZE;
+import static org.apache.gravitino.SupportsDomainOperations.MEMBERSHIP_LOOKUP_BATCH_SIZE;
+
import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -30,6 +41,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.gravitino.Entity;
@@ -39,7 +51,6 @@ import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.MetadataObjects;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
-import org.apache.gravitino.RelationQuery;
import org.apache.gravitino.exceptions.NoSuchEntityException;
import org.apache.gravitino.exceptions.NoSuchMetadataObjectException;
import org.apache.gravitino.meta.DomainEntity;
@@ -62,6 +73,8 @@ import org.slf4j.LoggerFactory;
/** Resolves domain scope from effective tag assignments without authorization filtering. */
final class DomainMembershipResolver {
private static final Logger LOG = LoggerFactory.getLogger(DomainMembershipResolver.class);
+ private static final Set<MetadataObject.Type> DIRECT_MEMBER_TYPES =
+ Sets.immutableEnumSet(Sets.union(DomainMember.SUPPORTED_TYPES, DomainMember.CONTAINER_TYPES));
private final EntityStore store;
private final EffectiveTagResolver tags;
@@ -89,60 +102,196 @@ final class DomainMembershipResolver {
|| filter.domains().contains(d.name()))
.collect(Collectors.toList());
- // Expand explicit tag assignments into recorded leaf objects that may inherit the tag.
- Set<MetadataObject> candidates = new LinkedHashSet<>();
+ List<DomainMember> members =
+ filter.expand()
+ ? listExpandedMembers(metalake, queriedDomain, scopeDomains, selectedDomains, filter)
+ : listDirectMembers(metalake, queriedDomain, scopeDomains, selectedDomains, filter);
+
+ members.sort(
+ Comparator.comparing((DomainMember m) -> m.object().type().name())
+ .thenComparing(m -> m.object().fullName()));
+ return members.toArray(new DomainMember[0]);
+ }
+
+ /**
+ * Lists the objects that carry a backing tag themselves, including catalogs and schemas, without
+ * expanding them or resolving effective tags.
+ */
+ private List<DomainMember> listDirectMembers(
+ String metalake,
+ DomainEntity queriedDomain,
+ List<DomainEntity> scopeDomains,
+ List<DomainEntity> selectedDomains,
+ DomainMemberFilter filter) {
+ Set<Long> selectedIds =
+ selectedDomains.stream().map(DomainEntity::id).collect(Collectors.toSet());
+ boolean needsOtherBindings =
+ scopeDomains.stream()
+ .anyMatch(d -> d.backingTagId() != null && !selectedIds.contains(d.id()));
+ // Bound the selected-domain IN list in the candidate semijoin.
+ boolean joinPaths =
+ needsOtherBindings
+ && !selectedIds.isEmpty()
+ && selectedIds.size() <= MEMBERSHIP_LOOKUP_BATCH_SIZE;
+ Map<MetadataObject.Type, Map<Long, MetadataObject>> candidates =
+ new EnumMap<>(MetadataObject.Type.class);
+ Table<MetadataObject.Type, Long, DirectMemberPaths> relations = HashBasedTable.create();
+ List<DomainMember> members = new ArrayList<>();
try {
- for (DomainEntity selectedDomain : selectedDomains) {
- if (selectedDomain.backingTagId() == null) {
+ Set<MetadataObject.Type> types =
+ filter.types().isEmpty() ? DIRECT_MEMBER_TYPES : filter.types();
+ List<DomainEntity> lookupDomains = selectedDomains;
+ Map<Long, List<GenericEntity>> assigned =
+ listAssignments(metalake, selectedDomains, types, Collections.emptyMap());
+ if (assigned.values().stream().allMatch(List::isEmpty)) {
+ return members;
+ }
+ if (joinPaths) {
+ List<DomainEntity> remaining =
+ scopeDomains.stream()
+ .filter(d -> d.backingTagId() != null && !selectedIds.contains(d.id()))
+ .collect(Collectors.toList());
+ // The semijoin restricts by selected domain, so use it only if every name matches.
+ joinPaths =
+ fewerDomainBatches(assigned, remaining.size())
+ && (!filter.nameContains().isPresent()
+ || assigned.values().stream()
+ .flatMap(List::stream)
+ .allMatch(row -> matchesFilter(assignedObject(row), filter)));
+ if (joinPaths) {
+ Map<Long, List<GenericEntity>> otherAssignments =
+ listAssignments(metalake, remaining, types, assigned);
+ assigned = new HashMap<>(assigned);
+ assigned.putAll(otherAssignments);
+ lookupDomains = scopeDomains;
+ }
+ }
+ for (DomainEntity domain : lookupDomains) {
+ if (domain.backingTagId() == null) {
continue;
}
- // Query by stable ID so a recreated tag with the same name cannot take over the binding.
- List<GenericEntity> assigned =
- store
- .relationOperations()
- .listEntitiesByRelation(
- RelationQuery.forTagId(
- metalake, selectedDomain.backingTagId(), selectedDomain.backingTagValue()));
- for (GenericEntity assignment : assigned) {
- collectCandidates(
- metalake,
- MetadataObjects.parse(
- assignment.name(), MetadataObject.Type.valueOf(assignment.type().name())),
- filter,
- candidates);
+ DomainRelation relation =
+ Objects.equals(queriedDomain.id(), domain.id())
+ ? DomainRelation.direct()
+ : DomainRelation.viaSubdomain(domain.name());
+ for (GenericEntity assignment :
+ assigned.getOrDefault(domain.id(), Collections.emptyList())) {
+ MetadataObject object = assignedObject(assignment);
+ if (DIRECT_MEMBER_TYPES.contains(object.type())) {
+ if (needsOtherBindings && !joinPaths) {
+ if (!matchesFilter(object, filter)) {
+ continue;
+ }
+ candidates
+ .computeIfAbsent(object.type(), t -> new LinkedHashMap<>())
+ .put(assignment.id(), object);
+ } else {
+ DirectMemberPaths paths =
+ relations
+ .row(object.type())
+ .computeIfAbsent(assignment.id(), ignored -> new DirectMemberPaths());
+ paths.relations.add(relation);
+ if (paths.selectedObject == null && selectedIds.contains(domain.id())) {
+ paths.selectedObject = object;
+ }
+ }
+ }
+ }
+ }
+
+ for (DirectMemberPaths paths : relations.values()) {
+ if (paths.selectedObject != null && matchesFilter(paths.selectedObject, filter)) {
+ members.add(
+ new DomainMemberInfo(
+ paths.selectedObject, paths.relations.toArray(new DomainRelation[0])));
}
}
+ if (candidates.isEmpty()) {
+ return members;
+ }
+ BindingIndex bindings = new BindingIndex(scopeDomains, selectedIds);
+ for (Map.Entry<MetadataObject.Type, Map<Long, MetadataObject>> group :
+ candidates.entrySet()) {
+ Map<Long, MetadataObject> objects = group.getValue();
+ Map<Long, List<TagEntity>> directTags =
+ store
+ .domainOperations()
+ .listDirectTagsByObjectIds(
+ metalake, group.getKey(), new ArrayList<>(objects.keySet()));
+ directTags.forEach(
+ (id, tags) -> {
+ MetadataObject object = objects.get(id);
+ ResolvedTag[] assignments =
+ tags.stream()
+ .map(tag -> new ResolvedTag(tag, object))
+ .toArray(ResolvedTag[]::new);
+ bindings.addMember(members, object, assignments);
+ });
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to list members of domain " + queriedDomain.name(), e);
+ }
+
+ return members;
+ }
+
+ /**
+ * Expands catalogs and schemas that carry a backing tag into the recorded leaf objects under
+ * them, and keeps the leaf objects whose effective tags make them members.
+ */
+ private List<DomainMember> listExpandedMembers(
+ String metalake,
+ DomainEntity queriedDomain,
+ List<DomainEntity> scopeDomains,
+ List<DomainEntity> selectedDomains,
+ DomainMemberFilter filter) {
+ // Expand explicit tag assignments into recorded leaf objects that may inherit the tag.
+ Set<MetadataObject> candidates = new LinkedHashSet<>();
+ try {
+ Set<MetadataObject.Type> types =
+ filter.types().isEmpty()
+ ? DIRECT_MEMBER_TYPES
+ : Sets.union(filter.types(), DomainMember.CONTAINER_TYPES);
+ Map<Long, List<GenericEntity>> assigned =
+ listAssignments(metalake, selectedDomains, types, Collections.emptyMap());
+ // A container assigned to several selected domains needs to be expanded only once.
+ Set<MetadataObject> roots = new LinkedHashSet<>();
+ assigned
+ .values()
+ .forEach(objects -> objects.forEach(entity -> roots.add(assignedObject(entity))));
+ for (MetadataObject root : roots) {
+ collectCandidates(metalake, root, filter, candidates);
+ }
} catch (IOException e) {
throw new RuntimeException("Failed to list members of domain " + queriedDomain.name(), e);
}
// A nearer assignment can override an ancestor tag, so candidates need effective-tag checks.
List<DomainMember> members = new ArrayList<>();
- for (MetadataObject object : candidates) {
- try {
- ResolvedTag[] effective = tags.resolveWithSources(metalake, object);
- if (selectedDomains.stream()
- .noneMatch(d -> resolveOwnRelation(d, object, effective) != null)) {
+ BindingIndex bindings =
+ new BindingIndex(
+ scopeDomains,
+ selectedDomains.stream().map(DomainEntity::id).collect(Collectors.toSet()));
+ for (List<MetadataObject> batch : Lists.partition(new ArrayList<>(candidates), 500)) {
+ if (batch.size() > 1) {
+ try {
+ tags.resolveWithSources(metalake, batch)
+ .forEach((object, effective) -> bindings.addMember(members, object, effective));
continue;
+ } catch (NoSuchMetadataObjectException e) {
+ // Retry this batch individually if a candidate disappeared during enumeration.
}
-
- // Include every applicable relation, even when the filter selected only one subdomain.
- DomainRelation[] relations =
- resolveRelations(queriedDomain, scopeDomains, object, effective);
- if (relations.length > 0) {
- members.add(new DomainMemberInfo(object, relations));
+ }
+ for (MetadataObject object : batch) {
+ try {
+ bindings.addMember(members, object, tags.resolveWithSources(metalake, object));
+ } catch (NoSuchMetadataObjectException e) {
+ LOG.debug("Skipping missing member candidate {} in metalake {}", object, metalake, e);
}
- } catch (NoSuchMetadataObjectException e) {
- // An object or its ancestor may have been dropped after candidate enumeration.
- LOG.debug("Skipping missing member candidate {} in metalake {}", object, metalake, e);
}
}
-
- members.sort(
- Comparator.comparing((DomainMember m) -> m.object().type().name())
- .thenComparing(m -> m.object().fullName()));
- return members.toArray(new DomainMember[0]);
+ return members;
}
DomainEntity[] listDomains(String metalake, MetadataObject object) {
@@ -232,23 +381,99 @@ final class DomainMembershipResolver {
return scopeDomains;
}
- private static DomainRelation[] resolveRelations(
- DomainEntity queriedDomain,
- List<DomainEntity> scopeDomains,
- MetadataObject object,
- ResolvedTag[] effective) {
- Set<DomainRelation> relations = new LinkedHashSet<>();
- for (DomainEntity memberDomain : scopeDomains) {
- DomainRelation own = resolveOwnRelation(memberDomain, object, effective);
- if (own != null) {
- relations.add(
- Objects.equals(queriedDomain.id(), memberDomain.id())
- ? own
- : DomainRelation.viaSubdomain(memberDomain.name()));
+ // A name can change between domain batches. Group paths by (type, ID) and use the
+ // first name observed in a selected domain for display.
+ private static final class DirectMemberPaths {
+ private final Set<DomainRelation> relations = new LinkedHashSet<>();
+ @Nullable private MetadataObject selectedObject;
+ }
+
+ private static boolean fewerDomainBatches(
+ Map<Long, List<GenericEntity>> selected, int remainingDomains) {
+ long domainBatches =
+ (remainingDomains + (long) JOINED_DOMAIN_BATCH_SIZE - 1) / JOINED_DOMAIN_BATCH_SIZE;
+ Map<Entity.EntityType, Set<Long>> idsByType = new EnumMap<>(Entity.EntityType.class);
+ int distinctObjects = 0;
+ long objectBatches = 0;
+ for (List<GenericEntity> assignments : selected.values()) {
+ for (GenericEntity assignment : assignments) {
+ Set<Long> ids = idsByType.computeIfAbsent(assignment.type(), ignored -> new HashSet<>());
+ if (!ids.add(assignment.id())) {
+ continue;
+ }
+ distinctObjects++;
+ if ((ids.size() - 1) % MEMBERSHIP_LOOKUP_BATCH_SIZE == 0) {
+ objectBatches++;
+ }
+ // A semijoin may scan unrelated assignments. Prefer indexed lookups for small
+ // selections, even when several object types would require separate statements.
+ if (distinctObjects > MEMBERSHIP_LOOKUP_BATCH_SIZE && objectBatches > domainBatches) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /** Matches tag IDs and exact assignment values, preserving the visible scope's relation order. */
+ private static final class BindingIndex {
+ private final List<DomainEntity> scope;
+ private final Set<Long> selected;
+ private final Map<Long, Map<String, Integer>> positions = new HashMap<>();
+
+ private BindingIndex(List<DomainEntity> scope, Set<Long> selected) {
+ this.scope = scope;
+ this.selected = selected;
+ for (int i = 0; i < scope.size(); i++) {
+ DomainEntity domain = scope.get(i);
+ if (domain.backingTagId() != null) {
+ positions
+ .computeIfAbsent(domain.backingTagId(), ignored -> new HashMap<>())
+ .put(domain.backingTagValue(), i);
+ }
}
}
- return relations.toArray(new DomainRelation[0]);
+ private void addMember(
+ List<DomainMember> members, MetadataObject object, ResolvedTag[] assignments) {
+ Map<Integer, DomainRelation> matches = new TreeMap<>();
+ for (ResolvedTag assignment : assignments) {
+ Map<String, Integer> byValue = positions.get(assignment.tag().id());
+ if (byValue == null) {
+ continue;
+ }
+ addMatch(matches, byValue.get(null), object, assignment.source());
+ assignment
+ .tag()
+ .assignment()
+ .ifPresent(
+ tag -> {
+ for (String value : tag.values()) {
+ addMatch(matches, byValue.get(value), object, assignment.source());
+ }
+ });
+ }
+ if (matches.keySet().stream().anyMatch(i -> selected.contains(scope.get(i).id()))) {
+ members.add(new DomainMemberInfo(object, matches.values().toArray(new DomainRelation[0])));
+ }
+ }
+
+ private void addMatch(
+ Map<Integer, DomainRelation> matches,
+ @Nullable Integer position,
+ MetadataObject object,
+ MetadataObject source) {
+ if (position == null) {
+ return;
+ }
+ if (position == 0) {
+ matches.put(
+ position,
+ source.equals(object) ? DomainRelation.direct() : DomainRelation.inherited(source));
+ } else {
+ matches.put(position, DomainRelation.viaSubdomain(scope.get(position).name()));
+ }
+ }
}
@Nullable
@@ -274,6 +499,39 @@ final class DomainMembershipResolver {
return null;
}
+ private Map<Long, List<GenericEntity>> listAssignments(
+ String metalake,
+ List<DomainEntity> domains,
+ Set<MetadataObject.Type> types,
+ Map<Long, List<GenericEntity>> selectedAssignments)
+ throws IOException {
+ List<DomainEntity> bound =
+ domains.stream().filter(d -> d.backingTagId() != null).collect(Collectors.toList());
+ return bound.isEmpty()
+ ? Collections.emptyMap()
+ : store
+ .domainOperations()
+ .listDomainAssignments(metalake, bound, types, selectedAssignments);
+ }
+
+ private static MetadataObject assignedObject(GenericEntity assignment) {
+ return MetadataObjects.parse(
+ assignment.name(), MetadataObject.Type.valueOf(assignment.type().name()));
+ }
+
+ private static boolean matchesFilter(MetadataObject object, DomainMemberFilter filter) {
+ return (filter.types().isEmpty() || filter.types().contains(object.type()))
+ && filter
+ .nameContains()
+ .map(
+ text ->
+ object
+ .fullName()
+ .toLowerCase(Locale.ROOT)
+ .contains(text.toLowerCase(Locale.ROOT)))
+ .orElse(true);
+ }
+
private void collectCandidates(
String metalake,
MetadataObject object,
@@ -281,16 +539,7 @@ final class DomainMembershipResolver {
Set<MetadataObject> candidates)
throws IOException {
if (DomainMember.SUPPORTED_TYPES.contains(object.type())) {
- if ((filter.types().isEmpty() || filter.types().contains(object.type()))
- && filter
- .nameContains()
- .map(
- text ->
- object
- .fullName()
- .toLowerCase(Locale.ROOT)
- .contains(text.toLowerCase(Locale.ROOT)))
- .orElse(true)) {
+ if (matchesFilter(object, filter)) {
candidates.add(object);
}
return;
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
index bf48871f46..dcdb2c4621 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/JDBCBackend.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -835,6 +836,23 @@ public class JDBCBackend implements RelationalBackend, SupportsOrphanedRelationC
return DomainRelService.getInstance().updateDomainStatusAndGet(ident, status, auditInfo, check);
}
+ @Override
+ public Map<Long, List<GenericEntity>> listDomainAssignments(
+ String metalake,
+ List<DomainEntity> domains,
+ Set<MetadataObject.Type> types,
+ Map<Long, List<GenericEntity>> selectedAssignments)
+ throws IOException {
+ return TagMetaService.getInstance()
+ .listDomainAssignments(metalake, domains, types, selectedAssignments);
+ }
+
+ @Override
+ public Map<Long, List<TagEntity>> listDirectTagsByObjectIds(
+ String metalake, MetadataObject.Type type, List<Long> objectIds) throws IOException {
+ return TagMetaService.getInstance().listDirectTagsByObjectIds(metalake, type, objectIds);
+ }
+
@Override
public List<DomainEntity> listDomainsByBackingTagIds(String metalake, List<Long> backingTagIds)
throws IOException {
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java b/core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java
index 59e592766d..8c73c653cd 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java
@@ -28,7 +28,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
@@ -42,6 +44,7 @@ import org.apache.gravitino.EntityAlreadyExistsException;
import org.apache.gravitino.EntityStore;
import org.apache.gravitino.GravitinoEnv;
import org.apache.gravitino.HasIdentifier;
+import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.RelationEdgeTarget;
@@ -62,6 +65,7 @@ import org.apache.gravitino.exceptions.NoSuchEntityException;
import org.apache.gravitino.exceptions.OptimisticLockException;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.DomainEntity;
+import org.apache.gravitino.meta.GenericEntity;
import org.apache.gravitino.meta.SchemaEntity;
import org.apache.gravitino.meta.TagEntity;
import org.apache.gravitino.metrics.MetricsSystem;
@@ -549,6 +553,22 @@ public class RelationalEntityStore
}
}
+ @Override
+ public Map<Long, List<GenericEntity>> listDomainAssignments(
+ String metalake,
+ List<DomainEntity> domains,
+ Set<MetadataObject.Type> types,
+ Map<Long, List<GenericEntity>> selectedAssignments)
+ throws IOException {
+ return backend.listDomainAssignments(metalake, domains, types, selectedAssignments);
+ }
+
+ @Override
+ public Map<Long, List<TagEntity>> listDirectTagsByObjectIds(
+ String metalake, MetadataObject.Type type, List<Long> objectIds) throws IOException {
+ return backend.listDirectTagsByObjectIds(metalake, type, objectIds);
+ }
+
@Override
public List<DomainEntity> listDomainsByBackingTagIds(String metalake, List<Long> backingTagIds)
throws IOException {
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaMapper.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaMapper.java
index 722f4d3493..92b32de7c4 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaMapper.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TableMetaMapper.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.storage.relational.mapper;
import java.util.List;
import javax.annotation.Nullable;
+import org.apache.gravitino.storage.relational.po.TableNamePO;
import org.apache.gravitino.storage.relational.po.TablePO;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
@@ -29,6 +30,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
+import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
@@ -43,6 +45,24 @@ import org.apache.ibatis.annotations.UpdateProvider;
public interface TableMetaMapper {
String TABLE_NAME = "table_meta";
+ /**
+ * Looks up table and ancestor names in one statement. An absent parent has a null name.
+ *
+ * @param ids Stable table IDs.
+ * @return Name components of the live tables.
+ */
+ @Select({
+ "<script>",
+ "SELECT t.table_id AS tableId, t.table_name AS tableName, s.schema_name AS schemaName,",
+ "c.catalog_name AS catalogName FROM table_meta t",
+ "LEFT JOIN schema_meta s ON s.schema_id = t.schema_id AND s.deleted_at = 0",
+ "LEFT JOIN catalog_meta c ON c.catalog_id = s.catalog_id AND c.deleted_at = 0",
+ "WHERE t.deleted_at = 0 AND t.table_id IN",
+ "<foreach collection='ids' item='id' open='(' separator=',' close=')'>#{id}</foreach>",
+ "</script>"
+ })
+ List<TableNamePO> listTableNamesByIds(@Param("ids") List<Long> ids);
+
/**
* Reads table metadata, its current version, and columns from one database statement snapshot.
*
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelMapper.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelMapper.java
index bd81497732..2cb20bdfea 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelMapper.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/TagMetadataObjectRelMapper.java
@@ -19,19 +19,62 @@
package org.apache.gravitino.storage.relational.mapper;
import java.util.List;
+import java.util.Set;
import javax.annotation.Nullable;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.storage.relational.po.DomainAssignmentPO;
import org.apache.gravitino.storage.relational.po.TagMetadataObjectRelPO;
import org.apache.gravitino.storage.relational.po.TagPO;
import org.apache.gravitino.storage.relational.po.TagRelationTagPO;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
public interface TagMetadataObjectRelMapper {
String TAG_METADATA_OBJECT_RELATION_TABLE_NAME = "tag_relation_meta";
+ /**
+ * Reads selected domain assignments before resolving object names.
+ *
+ * @param metalake The containing metalake.
+ * @param domainIds Selected domain IDs.
+ * @param types Selected object types.
+ * @param candidateDomainIds Domains supplying the candidate objects, or empty for all.
+ * @return Assignment rows with the matching domain ID.
+ */
+ @Select({
+ "<script>",
+ "SELECT d.domain_id AS domainId, r.tag_id AS tagId, r.tag_value AS tagValue,",
+ "r.metadata_object_id AS metadataObjectId, r.metadata_object_type AS metadataObjectType",
+ "FROM domain_meta d JOIN metalake_meta m ON m.metalake_id = d.metalake_id",
+ "JOIN tag_meta t ON t.tag_id = d.backing_tag_id AND t.metalake_id = m.metalake_id",
+ "JOIN tag_relation_meta r ON r.tag_id = t.tag_id",
+ "WHERE m.metalake_name = #{metalake} AND m.deleted_at = 0 AND d.deleted_at = 0",
+ "AND t.deleted_at = 0 AND r.deleted_at = 0",
+ "AND (d.backing_tag_value IS NULL OR d.backing_tag_value = r.tag_value)",
+ "AND d.domain_id IN",
+ "<foreach collection='domainIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>",
+ "AND r.metadata_object_type IN",
+ "<foreach collection='types' item='type' open='(' separator=',' close=')'>#{type}</foreach>",
+ "<if test='candidateDomainIds.size > 0'>",
+ "AND EXISTS (SELECT 1 FROM domain_meta sd JOIN tag_relation_meta sr ON sr.tag_id = sd.backing_tag_id",
+ "WHERE sd.metalake_id = m.metalake_id AND sd.deleted_at = 0 AND sr.deleted_at = 0",
+ "AND sr.metadata_object_id = r.metadata_object_id AND sr.metadata_object_type = r.metadata_object_type",
+ "AND (sd.backing_tag_value IS NULL OR sd.backing_tag_value = sr.tag_value)",
+ "AND sd.domain_id IN",
+ "<foreach collection='candidateDomainIds' item='id' open='(' separator=',' close=')'>#{id}</foreach>)",
+ "</if>",
+ "</script>"
+ })
+ List<DomainAssignmentPO> listDomainAssignments(
+ @Param("metalake") String metalake,
+ @Param("domainIds") Set<Long> domainIds,
+ @Param("types") Set<MetadataObject.Type> types,
+ @Param("candidateDomainIds") Set<Long> candidateDomainIds);
+
@SelectProvider(
type = TagMetadataObjectRelSQLProviderFactory.class,
method = "listTagPOsByMetadataObjectIdAndType")
@@ -42,6 +85,7 @@ public interface TagMetadataObjectRelMapper {
/**
* Selects tag assignment rows for multiple objects of one type.
*
+ * @param metalakeName the metalake containing the objects
* @param metadataObjectIds the source object IDs
* @param metadataObjectType the source object type
* @return the tag rows with source IDs
@@ -50,6 +94,7 @@ public interface TagMetadataObjectRelMapper {
type = TagMetadataObjectRelSQLProviderFactory.class,
method = "listTagPOsByMetadataObjectIdsAndType")
List<TagRelationTagPO> listTagPOsByMetadataObjectIdsAndType(
+ @Param("metalakeName") String metalakeName,
@Param("metadataObjectIds") List<Long> metadataObjectIds,
@Param("metadataObjectType") String metadataObjectType);
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TagMetadataObjectRelBaseSQLProvider.java b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TagMetadataObjectRelBaseSQLProvider.java
index bbf26fb078..4c66033324 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TagMetadataObjectRelBaseSQLProvider.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/TagMetadataObjectRelBaseSQLProvider.java
@@ -75,7 +75,10 @@ public class TagMetadataObjectRelBaseSQLProvider {
+ " tm JOIN "
+ TagMetadataObjectRelMapper.TAG_METADATA_OBJECT_RELATION_TABLE_NAME
+ " te ON tm.tag_id = te.tag_id"
- + " WHERE te.metadata_object_id IN "
+ + " JOIN "
+ + MetalakeMetaMapper.TABLE_NAME
+ + " mm ON tm.metalake_id = mm.metalake_id"
+ + " WHERE mm.metalake_name = #{metalakeName} AND mm.deleted_at = 0 AND te.metadata_object_id IN "
+ "<foreach collection='metadataObjectIds' item='id' open='(' separator=',' close=')'>"
+ "#{id}</foreach>"
+ " AND te.metadata_object_type = #{metadataObjectType}"
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/po/DomainAssignmentPO.java b/core/src/main/java/org/apache/gravitino/storage/relational/po/DomainAssignmentPO.java
new file mode 100644
index 0000000000..1646b87d26
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/po/DomainAssignmentPO.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.storage.relational.po;
+
+import lombok.Getter;
+
+/** A tag assignment matched to a domain in a batched member lookup. */
+@Getter
+public class DomainAssignmentPO extends TagMetadataObjectRelPO {
+ private Long domainId;
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/po/TableNamePO.java b/core/src/main/java/org/apache/gravitino/storage/relational/po/TableNamePO.java
new file mode 100644
index 0000000000..c4f9da9602
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/po/TableNamePO.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.storage.relational.po;
+
+import lombok.Getter;
+
+/** Names of a recorded table and its live ancestors. */
+@Getter
+public class TableNamePO {
+ private Long tableId;
+ private String tableName;
+ private String schemaName;
+ private String catalogName;
+}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java
index 55e3dc20ad..a108e73933 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/MetadataObjectService.java
@@ -61,11 +61,12 @@ import org.apache.gravitino.storage.relational.po.ModelPO;
import org.apache.gravitino.storage.relational.po.PolicyPO;
import org.apache.gravitino.storage.relational.po.SchemaPO;
import org.apache.gravitino.storage.relational.po.SemanticModelPO;
-import org.apache.gravitino.storage.relational.po.TablePO;
+import org.apache.gravitino.storage.relational.po.TableNamePO;
import org.apache.gravitino.storage.relational.po.TagPO;
import org.apache.gravitino.storage.relational.po.TopicPO;
import org.apache.gravitino.storage.relational.po.ViewPO;
import org.apache.gravitino.storage.relational.utils.SessionUtils;
+import org.apache.gravitino.utils.HierarchicalSchemaUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -107,7 +108,6 @@ public class MetadataObjectService {
static final Map<MetadataObject.Type, BasePOStorageOps<?, ?>> TYPE_TO_STORAGE_OPS_MAP =
ImmutableMap.<MetadataObject.Type, BasePOStorageOps<?, ?>>builder()
.put(MetadataObject.Type.SCHEMA, SchemaMetaService.getInstance().ops())
- .put(MetadataObject.Type.TABLE, TableMetaService.getInstance().ops())
.put(MetadataObject.Type.VIEW, ViewMetaService.getInstance().ops())
.put(MetadataObject.Type.FUNCTION, FunctionMetaService.getInstance().ops())
.build();
@@ -432,40 +432,19 @@ public class MetadataObjectService {
return Maps.newHashMap();
}
- @SuppressWarnings("unchecked")
- BasePOStorageOps<TablePO, TableMetaMapper> ops =
- (BasePOStorageOps<TablePO, TableMetaMapper>)
- TYPE_TO_STORAGE_OPS_MAP.get(MetadataObject.Type.TABLE);
- List<TablePO> tablePOs =
+ List<TableNamePO> tables =
SessionUtils.getWithoutCommit(
- TableMetaMapper.class, mapper -> ops.listPOs(mapper, tableIds));
-
- if (tablePOs == null || tablePOs.isEmpty()) {
- return Maps.newHashMap();
+ TableMetaMapper.class, mapper -> mapper.listTableNamesByIds(tableIds));
+ Map<Long, String> tableIdAndNameMap = new HashMap<>();
+ String separator = HierarchicalSchemaUtil.schemaSeparator();
+ for (TableNamePO table : tables) {
+ String fullName = null;
+ if (table.getCatalogName() != null && table.getSchemaName() != null) {
+ String schema = HierarchicalSchemaUtil.physicalToLogical(table.getSchemaName(), separator);
+ fullName = DOT_JOINER.join(table.getCatalogName(), schema, table.getTableName());
+ }
+ tableIdAndNameMap.put(table.getTableId(), fullName);
}
-
- List<Long> schemaIds = tablePOs.stream().map(TablePO::getSchemaId).collect(Collectors.toList());
-
- Map<Long, String> schemaIdAndNameMap = getSchemaObjectsFullName(schemaIds);
-
- HashMap<Long, String> tableIdAndNameMap = new HashMap<>();
-
- tablePOs.forEach(
- tablePO -> {
- // since the schema can be deleted, we need to check the null value,
- // and when schema is deleted, we will set fullName of tablePO to
- // null
- String schemaName = schemaIdAndNameMap.getOrDefault(tablePO.getSchemaId(), null);
- if (schemaName == null) {
- LOG.warn("The schema of table {} may be deleted", tablePO.getTableId());
- tableIdAndNameMap.put(tablePO.getTableId(), null);
- return;
- }
-
- String fullName = DOT_JOINER.join(schemaName, tablePO.getTableName());
- tableIdAndNameMap.put(tablePO.getTableId(), fullName);
- });
-
return tableIdAndNameMap;
}
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java b/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
index e3d915619a..b5a0c99172 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/service/TagMetaService.java
@@ -18,12 +18,16 @@
*/
package org.apache.gravitino.storage.relational.service;
+import static org.apache.gravitino.SupportsDomainOperations.JOINED_DOMAIN_BATCH_SIZE;
+import static org.apache.gravitino.SupportsDomainOperations.MEMBERSHIP_LOOKUP_BATCH_SIZE;
import static org.apache.gravitino.metrics.source.MetricsSource.GRAVITINO_RELATIONAL_STORE_METRIC_NAME;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
+import com.google.common.collect.Table;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.ArrayList;
@@ -53,6 +57,7 @@ import org.apache.gravitino.exceptions.NoSuchEntityException;
import org.apache.gravitino.exceptions.NoSuchTagException;
import org.apache.gravitino.exceptions.TagAlreadyExistsException;
import org.apache.gravitino.json.JsonUtils;
+import org.apache.gravitino.meta.DomainEntity;
import org.apache.gravitino.meta.GenericEntity;
import org.apache.gravitino.meta.NamespacedEntityId;
import org.apache.gravitino.meta.TagEntity;
@@ -63,6 +68,7 @@ import org.apache.gravitino.storage.relational.mapper.PolicyTagRelMapper;
import org.apache.gravitino.storage.relational.mapper.SecurableObjectMapper;
import org.apache.gravitino.storage.relational.mapper.TagMetaMapper;
import org.apache.gravitino.storage.relational.mapper.TagMetadataObjectRelMapper;
+import org.apache.gravitino.storage.relational.po.DomainAssignmentPO;
import org.apache.gravitino.storage.relational.po.MetalakePO;
import org.apache.gravitino.storage.relational.po.TagMetadataObjectRelPO;
import org.apache.gravitino.storage.relational.po.TagPO;
@@ -77,6 +83,8 @@ import org.apache.gravitino.utils.NamespaceUtil;
public class TagMetaService {
+ // One domain batch can contribute many more object IDs than domains.
+ private static final int NAME_LOOKUP_BATCH_SIZE = 10_000;
private static final TagMetaService INSTANCE = new TagMetaService();
public static TagMetaService getInstance() {
@@ -249,28 +257,13 @@ public class TagMetaService {
columns.stream().map(NameIdentifier::name).collect(Collectors.toList()));
columns.forEach(column -> identifiersById.put(ids.get(column.name()), column));
});
- List<TagRelationTagPO> rows = new ArrayList<>();
- String metadataObjectType =
- NameIdentifierUtil.toMetadataObjectForRead(objectIdentifiers.get(0), objectType)
- .type()
- .toString();
- for (List<Long> batch : Lists.partition(new ArrayList<>(identifiersById.keySet()), 500)) {
- rows.addAll(
- SessionUtils.getWithoutCommit(
- TagMetadataObjectRelMapper.class,
- mapper -> mapper.listTagPOsByMetadataObjectIdsAndType(batch, metadataObjectType)));
- }
- Map<Long, List<TagPO>> rowsByObject = new LinkedHashMap<>();
- rows.forEach(
- row ->
- rowsByObject
- .computeIfAbsent(row.getMetadataObjectId(), ignored -> new ArrayList<>())
- .add(row));
+ MetadataObject.Type type =
+ NameIdentifierUtil.toMetadataObjectForRead(objectIdentifiers.get(0), objectType).type();
List<RelationalEntity<?>> result = new ArrayList<>();
- rowsByObject.forEach(
- (id, tagRows) ->
- tagPOsToTagEntities(tagRows, NamespaceUtil.ofTag(metalake))
- .forEach(
+ listDirectTagsByObjectIds(metalake, type, new ArrayList<>(identifiersById.keySet()))
+ .forEach(
+ (id, tags) ->
+ tags.forEach(
tag ->
result.add(
new RelationalEntity<>(
@@ -281,6 +274,105 @@ public class TagMetaService {
return result;
}
+ /**
+ * Lists live directly assigned objects for the selected domain bindings and object types.
+ *
+ * @param metalake The metalake containing the domains.
+ * @param domains Selected domains with backing tags.
+ * @param types The candidate metadata object types.
+ * @param selectedAssignments Previously resolved objects by selected domain ID. An empty map
+ * resolves names; otherwise only these objects can match, and their names are reused.
+ * @return Assigned objects keyed by domain ID.
+ * @throws IOException If the assignments cannot be read.
+ */
+ public Map<Long, List<GenericEntity>> listDomainAssignments(
+ String metalake,
+ List<DomainEntity> domains,
+ Set<MetadataObject.Type> types,
+ Map<Long, List<GenericEntity>> selectedAssignments)
+ throws IOException {
+ Map<Long, List<GenericEntity>> result = new LinkedHashMap<>();
+ if (types.isEmpty()) {
+ return result;
+ }
+ Table<String, Long, GenericEntity> knownObjects = HashBasedTable.create();
+ for (List<GenericEntity> assignments : selectedAssignments.values()) {
+ for (GenericEntity object : assignments) {
+ knownObjects.put(object.type().name(), object.id(), object);
+ }
+ }
+ // The candidate semijoin limits the returned objects even for a wide domain batch.
+ int domainBatchSize =
+ selectedAssignments.isEmpty() ? MEMBERSHIP_LOOKUP_BATCH_SIZE : JOINED_DOMAIN_BATCH_SIZE;
+ for (List<DomainEntity> batch : Lists.partition(domains, domainBatchSize)) {
+ Map<Long, DomainEntity> selected =
+ batch.stream().collect(Collectors.toMap(DomainEntity::id, Function.identity()));
+ List<DomainAssignmentPO> rows =
+ SessionUtils.getWithoutCommit(
+ TagMetadataObjectRelMapper.class,
+ mapper ->
+ mapper.listDomainAssignments(
+ metalake, selected.keySet(), types, selectedAssignments.keySet()));
+ // Compare with the caller's stable binding and enforce case-sensitive value matching
+ // independently of the database collation.
+ List<DomainAssignmentPO> matching =
+ rows.stream()
+ .filter(
+ row -> {
+ DomainEntity domain = selected.get(row.getDomainId());
+ return Objects.equals(domain.backingTagId(), row.getTagId())
+ && (domain.backingTagValue() == null
+ || domain.backingTagValue().equals(row.getTagValue()));
+ })
+ .collect(Collectors.toList());
+ Table<String, Long, GenericEntity> objects = knownObjects;
+ if (selectedAssignments.isEmpty()) {
+ objects = HashBasedTable.create();
+ for (GenericEntity object : metadataObjectsForRelations(matching)) {
+ objects.put(object.type().name(), object.id(), object);
+ }
+ }
+ Map<Long, Set<GenericEntity>> byDomain = new LinkedHashMap<>();
+ for (DomainAssignmentPO row : matching) {
+ GenericEntity object = objects.get(row.getMetadataObjectType(), row.getMetadataObjectId());
+ if (object != null) {
+ byDomain.computeIfAbsent(row.getDomainId(), ignored -> new LinkedHashSet<>()).add(object);
+ }
+ }
+ byDomain.forEach((id, assigned) -> result.put(id, new ArrayList<>(assigned)));
+ }
+ return result;
+ }
+
+ /**
+ * Reads direct tag assignments in bounded batches without resolving object names to IDs.
+ *
+ * @param metalake The metalake containing the objects.
+ * @param type The metadata object type.
+ * @param objectIds Stable metadata object IDs.
+ * @return Tags with assignment values keyed by object ID.
+ */
+ public Map<Long, List<TagEntity>> listDirectTagsByObjectIds(
+ String metalake, MetadataObject.Type type, List<Long> objectIds) {
+ Map<Long, List<TagEntity>> result = new LinkedHashMap<>();
+ for (List<Long> batch : Lists.partition(objectIds, MEMBERSHIP_LOOKUP_BATCH_SIZE)) {
+ List<TagRelationTagPO> rows =
+ SessionUtils.getWithoutCommit(
+ TagMetadataObjectRelMapper.class,
+ mapper -> mapper.listTagPOsByMetadataObjectIdsAndType(metalake, batch, type.name()));
+ Map<Long, List<TagPO>> rowsByObject = new LinkedHashMap<>();
+ rows.forEach(
+ row ->
+ rowsByObject
+ .computeIfAbsent(row.getMetadataObjectId(), ignored -> new ArrayList<>())
+ .add(row));
+ rowsByObject.forEach(
+ (id, tagRows) ->
+ result.put(id, tagPOsToTagEntities(tagRows, NamespaceUtil.ofTag(metalake))));
+ }
+ return result;
+ }
+
@Monitored(
metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME,
baseMetricName = "getTagForMetadataObject")
@@ -1098,7 +1190,7 @@ public class TagMetaService {
}
private List<GenericEntity> metadataObjectsForRelations(
- List<TagMetadataObjectRelPO> tagMetadataObjectRelPOs) {
+ List<? extends TagMetadataObjectRelPO> tagMetadataObjectRelPOs) {
List<GenericEntity> metadataObjects = Lists.newArrayList();
Map<String, List<TagMetadataObjectRelPO>> tagMetadataObjectRelPOsByType =
tagMetadataObjectRelPOs.stream()
@@ -1114,23 +1206,25 @@ public class TagMetaService {
.map(TagMetadataObjectRelPO::getMetadataObjectId)
.distinct()
.collect(Collectors.toList());
- Map<Long, String> metadataObjectNames =
- MetadataObjectService.TYPE_TO_FULLNAME_FUNCTION_MAP
- .get(MetadataObject.Type.valueOf(metadataObjectType))
- .apply(metadataObjectIds);
-
- for (Map.Entry<Long, String> metadataObjectName : metadataObjectNames.entrySet()) {
- String fullName = metadataObjectName.getValue();
-
- // Metadata object may be deleted asynchronously when we query the name, so it will
- // return null, we should skip this metadata object.
- if (fullName != null) {
- metadataObjects.add(
- GenericEntity.builder()
- .withName(fullName)
- .withEntityType(Entity.EntityType.valueOf(metadataObjectType))
- .withId(metadataObjectName.getKey())
- .build());
+ for (List<Long> batch : Lists.partition(metadataObjectIds, NAME_LOOKUP_BATCH_SIZE)) {
+ Map<Long, String> metadataObjectNames =
+ MetadataObjectService.TYPE_TO_FULLNAME_FUNCTION_MAP
+ .get(MetadataObject.Type.valueOf(metadataObjectType))
+ .apply(batch);
+
+ for (Map.Entry<Long, String> metadataObjectName : metadataObjectNames.entrySet()) {
+ String fullName = metadataObjectName.getValue();
+
+ // Metadata object may be deleted asynchronously when we query the name, so it will
+ // return null, we should skip this metadata object.
+ if (fullName != null) {
+ metadataObjects.add(
+ GenericEntity.builder()
+ .withName(fullName)
+ .withEntityType(Entity.EntityType.valueOf(metadataObjectType))
+ .withId(metadataObjectName.getKey())
+ .build());
+ }
}
}
}
diff --git a/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java b/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java
index 5793c3acbe..00af56208d 100644
--- a/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java
+++ b/core/src/test/java/org/apache/gravitino/domain/TestDomainManager.java
@@ -240,7 +240,10 @@ public class TestDomainManager {
.when(() -> MetadataObjectUtil.checkMetadataObject(METALAKE, leaf))
.thenAnswer(call -> null);
DomainMemberFilter filter =
- DomainMemberFilter.builder().withTypes(MetadataObject.Type.TABLE).build();
+ DomainMemberFilter.builder()
+ .withExpand(true)
+ .withTypes(MetadataObject.Type.TABLE)
+ .build();
DomainMember[] members = domainManager.listMembers(METALAKE, "Finance", filter);
Assertions.assertEquals(1, members.length);
Assertions.assertEquals(leaf, members[0].object());
@@ -399,7 +402,8 @@ public class TestDomainManager {
.when(() -> MetadataObjectUtil.checkMetadataObject(METALAKE, leaf))
.thenAnswer(call -> null);
DomainMember[] members =
- domainManager.listMembers(METALAKE, "Finance", DomainMemberFilter.builder().build());
+ domainManager.listMembers(
+ METALAKE, "Finance", DomainMemberFilter.builder().withExpand(true).build());
Assertions.assertEquals(1, members.length);
Assertions.assertArrayEquals(
new DomainRelation[] {
@@ -410,17 +414,73 @@ public class TestDomainManager {
members[0].relations());
Assertions.assertEquals(
2, domainManager.listDomainsForMetadataObject(METALAKE, leaf).length);
+
+ // Without expansion the tagged catalog is listed once, and the valued HR binding does
+ // not match the catalog's finance assignment.
+ MetadataObject catalogObject =
+ MetadataObjects.parse(catalogName, MetadataObject.Type.CATALOG);
+ DomainMember[] direct =
+ domainManager.listMembers(METALAKE, "Finance", DomainMemberFilter.builder().build());
+ Assertions.assertArrayEquals(
+ new MetadataObject[] {catalogObject, leaf},
+ Arrays.stream(direct).map(DomainMember::object).toArray(MetadataObject[]::new));
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct()}, direct[0].relations());
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Trading")}, direct[1].relations());
+ Assertions.assertEquals(
+ 0,
+ domainManager.listMembers(METALAKE, "HR", DomainMemberFilter.builder().build()).length);
+ // The direct query filters out the catalog, while expansion still needs it as a source.
+ DomainMemberFilter modelsOnly =
+ DomainMemberFilter.builder().withTypes(MetadataObject.Type.MODEL).build();
+ Assertions.assertEquals(
+ 0, domainManager.listMembers(METALAKE, "Finance", modelsOnly).length);
+ DomainMemberFilter tablesOnly =
+ DomainMemberFilter.builder().withTypes(MetadataObject.Type.TABLE).build();
+ DomainMember[] tables = domainManager.listMembers(METALAKE, "Finance", tablesOnly);
+ Assertions.assertEquals(1, tables.length);
+ Assertions.assertEquals(leaf, tables[0].object());
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Trading")}, tables[0].relations());
+ DomainMember[] expandedTables =
+ domainManager.listMembers(
+ METALAKE,
+ "Finance",
+ DomainMemberFilter.builder()
+ .withTypes(MetadataObject.Type.TABLE)
+ .withExpand(true)
+ .build());
+ Assertions.assertEquals(1, expandedTables.length);
+ Assertions.assertArrayEquals(members[0].relations(), expandedTables[0].relations());
assignMembershipTag(table.nameIdentifier(), Entity.EntityType.TABLE, "dept", "hr");
+ DomainMember[] tradingMembers =
+ domainManager.listMembers(
+ METALAKE, "Finance", DomainMemberFilter.builder().withDomains("Trading").build());
+ Assertions.assertEquals(1, tradingMembers.length);
+ Assertions.assertEquals(leaf, tradingMembers[0].object());
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Trading")},
+ tradingMembers[0].relations());
+ DomainMember[] hrMembers =
+ domainManager.listMembers(METALAKE, "HR", DomainMemberFilter.builder().build());
+ Assertions.assertEquals(1, hrMembers.length);
+ Assertions.assertEquals(leaf, hrMembers[0].object());
+ Assertions.assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct()}, hrMembers[0].relations());
Assertions.assertArrayEquals(
new DomainRelation[] {DomainRelation.viaSubdomain("Trading")},
- domainManager.listMembers(METALAKE, "Finance", DomainMemberFilter.builder().build())[0]
+ domainManager
+ .listMembers(
+ METALAKE, "Finance", DomainMemberFilter.builder().withExpand(true).build())[0]
.relations());
Assertions.assertEquals(
3, domainManager.listDomainsForMetadataObject(METALAKE, leaf).length);
domainManager.detachDomain(METALAKE, "Trading");
Assertions.assertEquals(
0,
- domainManager.listMembers(METALAKE, "Finance", DomainMemberFilter.builder().build())
+ domainManager.listMembers(
+ METALAKE, "Finance", DomainMemberFilter.builder().withExpand(true).build())
.length);
Assertions.assertEquals(
2, domainManager.listDomainsForMetadataObject(METALAKE, leaf).length);
@@ -435,7 +495,8 @@ public class TestDomainManager {
0, domainManager.listDomainsForMetadataObject(METALAKE, leaf).length);
Assertions.assertEquals(
0,
- domainManager.listMembers(METALAKE, "Finance", DomainMemberFilter.builder().build())
+ domainManager.listMembers(
+ METALAKE, "Finance", DomainMemberFilter.builder().withExpand(true).build())
.length);
// The original binding survives a tag deletion but never follows a recreated name.
Assertions.assertEquals(
diff --git a/core/src/test/java/org/apache/gravitino/domain/TestDomainMembershipResolver.java b/core/src/test/java/org/apache/gravitino/domain/TestDomainMembershipResolver.java
index 328e8fd858..67031817a7 100644
--- a/core/src/test/java/org/apache/gravitino/domain/TestDomainMembershipResolver.java
+++ b/core/src/test/java/org/apache/gravitino/domain/TestDomainMembershipResolver.java
@@ -22,15 +22,16 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@@ -43,6 +44,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.gravitino.Entity;
@@ -52,7 +54,7 @@ import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.MetadataObjects;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
-import org.apache.gravitino.RelationQuery;
+import org.apache.gravitino.RelationalEntity;
import org.apache.gravitino.SupportsDomainOperations;
import org.apache.gravitino.SupportsRelationOperations;
import org.apache.gravitino.catalog.CatalogManager;
@@ -91,8 +93,11 @@ class TestDomainMembershipResolver {
private DomainMembershipResolver resolver;
private SupportsDomainOperations domainOperations;
private MockedStatic<MetadataObjectUtil> metadataObjects;
+ private final Map<MetadataObject, Long> objectIds = new HashMap<>();
+ private final Map<Long, MetadataObject> candidateObjects = new HashMap<>();
private final Map<String, List<TagEntity>> assignments = new HashMap<>();
private final Map<Long, List<GenericEntity>> candidates = new HashMap<>();
+ private final Map<String, List<GenericEntity>> valuedCandidates = new HashMap<>();
@BeforeEach
void setUp() throws Exception {
@@ -108,18 +113,63 @@ class TestDomainMembershipResolver {
when(store.relationOperations()).thenReturn(relations);
domainOperations = mock(SupportsDomainOperations.class);
when(store.domainOperations()).thenReturn(domainOperations);
+ when(domainOperations.listDirectTagsByObjectIds(eq(METALAKE), any(), anyList()))
+ .thenAnswer(
+ call -> {
+ Map<Long, List<TagEntity>> result = new HashMap<>();
+ for (long id : call.<List<Long>>getArgument(2)) {
+ MetadataObject object = candidateObjects.get(id);
+ assertEquals(object.type(), call.getArgument(1));
+ List<TagEntity> tags =
+ assignments.get(MetadataObjectUtil.toEntityIdent(METALAKE, object).toString());
+ if (tags != null) {
+ result.put(id, tags);
+ }
+ }
+ return result;
+ });
resolver = new DomainMembershipResolver(store);
metadataObjects = mockStatic(MetadataObjectUtil.class, CALLS_REAL_METHODS);
metadataObjects
.when(() -> MetadataObjectUtil.checkMetadataObject(anyString(), any()))
.thenAnswer(call -> null);
- when(relations.listEntitiesByRelation(any(RelationQuery.class)))
+ when(domainOperations.listDomainAssignments(eq(METALAKE), anyList(), any(), any()))
+ .thenAnswer(
+ call -> {
+ Map<Long, List<GenericEntity>> result = new HashMap<>();
+ for (DomainEntity domain : call.<List<DomainEntity>>getArgument(1)) {
+ List<GenericEntity> rows =
+ valuedCandidates.getOrDefault(
+ domain.backingTagId() + "=" + domain.backingTagValue(),
+ candidates.getOrDefault(domain.backingTagId(), Collections.emptyList()));
+ result.put(
+ domain.id(),
+ rows.stream()
+ .filter(
+ row ->
+ call.<Set<MetadataObject.Type>>getArgument(2)
+ .contains(MetadataObject.Type.valueOf(row.type().name())))
+ .collect(Collectors.toList()));
+ }
+ return result;
+ });
+ when(relations.batchListEntitiesByRelation(
+ eq(SupportsRelationOperations.Type.TAG_METADATA_OBJECT_REL), anyList(), any()))
.thenAnswer(
call -> {
- RelationQuery query = call.getArgument(0);
- assertEquals(Entity.EntityType.TAG, query.anchorEntityType());
- assertTrue(query.anchorId().isPresent());
- return candidates.getOrDefault(query.anchorId().get(), Collections.emptyList());
+ List<RelationalEntity<?>> result = new ArrayList<>();
+ for (NameIdentifier ident : call.<List<NameIdentifier>>getArgument(1)) {
+ for (TagEntity tag :
+ assignments.getOrDefault(ident.toString(), Collections.emptyList())) {
+ result.add(
+ new RelationalEntity<>(
+ SupportsRelationOperations.Type.TAG_METADATA_OBJECT_REL,
+ ident,
+ call.getArgument(2),
+ tag));
+ }
+ }
+ return result;
});
when(relations.listEntitiesByRelation(
eq(SupportsRelationOperations.Type.TAG_METADATA_OBJECT_REL),
@@ -138,6 +188,355 @@ class TestDomainMembershipResolver {
metadataObjects.close();
}
+ @Test
+ void testDirectMembersListContainersOnceWithoutExpansion() throws Exception {
+ DomainEntity finance = domain(1, "Finance", null, 10L, null);
+ DomainEntity trading = domain(2, "Trading", "Finance", 20L, null);
+ DomainEntity tax = domain(3, "Tax", "Finance", 30L, "tax");
+ DomainEntity[] domains = {finance, trading, tax};
+ MetadataObject view = object("cat.db.positions", MetadataObject.Type.VIEW);
+ MetadataObject otherValue = object("cat.db.files", MetadataObject.Type.FILESET);
+ // Finance tags the catalog and a leaf; Trading tags the schema and the same leaf.
+ candidate(
+ 10,
+ CATALOG,
+ TABLE,
+ object("cat.db.trades.column", MetadataObject.Type.COLUMN),
+ object("cat.db.func", MetadataObject.Type.FUNCTION));
+ candidate(20, SCHEMA, TABLE);
+ // The valued binding of Tax matches only the assignments with its exact value.
+ valuedCandidate(30, "tax", view);
+ valuedCandidate(30, "other", otherValue);
+
+ DomainMember[] members = resolver.listMembers(METALAKE, finance, domains, direct().build());
+ assertArrayEquals(
+ new MetadataObject[] {CATALOG, SCHEMA, TABLE, view},
+ Arrays.stream(members).map(DomainMember::object).toArray(MetadataObject[]::new));
+ assertArrayEquals(new DomainRelation[] {DomainRelation.direct()}, members[0].relations());
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Trading")}, members[1].relations());
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct(), DomainRelation.viaSubdomain("Trading")},
+ members[2].relations());
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Tax")}, members[3].relations());
+
+ // Neither catalog nor schema is expanded, and no effective tag is resolved.
+ verify(store, never()).list(any(), any(), any());
+ verify(store, never()).listDescendantSchemas(any());
+ verify(relations, never())
+ .listEntitiesByRelation(
+ eq(SupportsRelationOperations.Type.TAG_METADATA_OBJECT_REL),
+ any(NameIdentifier.class),
+ any(Entity.EntityType.class));
+ verify(domainOperations)
+ .listDomainAssignments(
+ eq(METALAKE),
+ eq(Arrays.asList(finance, tax, trading)),
+ any(),
+ eq(Collections.emptyMap()));
+
+ // A sub-domain lists its own assignments as direct.
+ DomainMember[] tradingMembers =
+ resolver.listMembers(METALAKE, trading, domains, direct().build());
+ assertArrayEquals(
+ new MetadataObject[] {SCHEMA, TABLE},
+ Arrays.stream(tradingMembers).map(DomainMember::object).toArray(MetadataObject[]::new));
+ for (DomainMember member : tradingMembers) {
+ assertArrayEquals(new DomainRelation[] {DomainRelation.direct()}, member.relations());
+ }
+ }
+
+ @Test
+ void testDirectMemberFilters() {
+ DomainEntity finance = domain(1, "Finance", null, 10L, null);
+ DomainEntity trading = domain(2, "Trading", "Finance", 20L, null);
+ DomainEntity[] domains = {finance, trading};
+ candidate(10, CATALOG, TABLE);
+ candidate(20, SCHEMA, TABLE);
+
+ assertArrayEquals(
+ new MetadataObject[] {CATALOG, SCHEMA},
+ objects(
+ resolver.listMembers(
+ METALAKE,
+ finance,
+ domains,
+ direct()
+ .withTypes(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA)
+ .build())));
+ assertArrayEquals(
+ new MetadataObject[] {TABLE},
+ objects(
+ resolver.listMembers(
+ METALAKE,
+ finance,
+ domains,
+ direct().withTypes(MetadataObject.Type.TABLE).build())));
+ assertArrayEquals(
+ new MetadataObject[] {SCHEMA, TABLE},
+ objects(
+ resolver.listMembers(
+ METALAKE, finance, domains, direct().withNameContains("CAT.DB").build())));
+
+ assign(SCHEMA, tag(20, "trading"));
+ assign(TABLE, tag(10, "finance"), tag(20, "trading"));
+ // Selecting a sub-domain selects its members but keeps all their relations.
+ DomainMember[] selected =
+ resolver.listMembers(METALAKE, finance, domains, direct().withDomains("Trading").build());
+ assertArrayEquals(new MetadataObject[] {SCHEMA, TABLE}, objects(selected));
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct(), DomainRelation.viaSubdomain("Trading")},
+ selected[1].relations());
+ assertEquals(
+ 3,
+ resolver.listMembers(METALAKE, finance, domains, direct().withDomains("Finance").build())
+ .length);
+ assertEquals(
+ 0,
+ resolver.listMembers(METALAKE, finance, domains, direct().withDomains("missing").build())
+ .length);
+ }
+
+ @Test
+ void testFilteredListingKeepsAllPathsOnlyForSelectedObjects() throws Exception {
+ DomainEntity parent = domain(1, "Finance", null, 10L, null);
+ DomainEntity trading = domain(2, "Trading", "Finance", 20L, null);
+ DomainEntity tax = domain(3, "Tax", "Finance", 30L, "tax");
+ candidate(20, TABLE);
+ valuedCandidate(30, "tax", TABLE, SCHEMA);
+ assign(TABLE, tag(20, "trading"), tag(30, "dept", "tax"));
+ DomainMember[] members =
+ resolver.listMembers(
+ METALAKE,
+ parent,
+ new DomainEntity[] {trading, tax},
+ direct().withDomains("Trading").build());
+ assertArrayEquals(new MetadataObject[] {TABLE}, objects(members));
+ assertArrayEquals(
+ new DomainRelation[] {
+ DomainRelation.viaSubdomain("Tax"), DomainRelation.viaSubdomain("Trading")
+ },
+ members[0].relations());
+ verify(domainOperations)
+ .listDomainAssignments(
+ eq(METALAKE), eq(List.of(trading)), any(), eq(Collections.emptyMap()));
+ verify(domainOperations)
+ .listDirectTagsByObjectIds(
+ METALAKE, MetadataObject.Type.TABLE, List.of(objectIds.get(TABLE)));
+ }
+
+ @Test
+ void testWideScopeUsesCandidateCountToChooseLookup() throws Exception {
+ DomainEntity parent = domain(1, "Finance", null, 1L, null);
+ DomainEntity[] children = new DomainEntity[1000];
+ for (int i = 0; i < children.length; i++) {
+ children[i] = domain(i + 2, "Child" + i, "Finance", (long) i + 2, null);
+ }
+ DomainMemberFilter filter = direct().withDomains("Child0").build();
+ assertEquals(0, resolver.listMembers(METALAKE, parent, children, filter).length);
+ candidate(2, CATALOG, SCHEMA);
+ assign(CATALOG, tag(2, "selected"));
+ assign(SCHEMA, tag(2, "selected"));
+ assertArrayEquals(
+ new MetadataObject[] {CATALOG, SCHEMA},
+ objects(resolver.listMembers(METALAKE, parent, children, filter)));
+ verify(domainOperations)
+ .listDirectTagsByObjectIds(
+ METALAKE, MetadataObject.Type.CATALOG, List.of(objectIds.get(CATALOG)));
+ verify(domainOperations)
+ .listDirectTagsByObjectIds(
+ METALAKE, MetadataObject.Type.SCHEMA, List.of(objectIds.get(SCHEMA)));
+
+ MetadataObject[] tables = new MetadataObject[1001];
+ for (int i = 0; i < tables.length; i++) {
+ tables[i] = object("cat.db.table" + i, MetadataObject.Type.TABLE);
+ }
+ candidate(2, tables);
+ // The second query observes a rename of the same stable table ID.
+ MetadataObject renamed = object("cat.db.renamed", MetadataObject.Type.TABLE);
+ objectIds.put(renamed, objectIds.get(tables[0]));
+ candidate(children[999].backingTagId(), renamed);
+ DomainMember[] members = resolver.listMembers(METALAKE, parent, children, filter);
+ assertEquals(tables.length, members.length);
+ assertArrayEquals(
+ new DomainRelation[] {
+ DomainRelation.viaSubdomain("Child0"), DomainRelation.viaSubdomain("Child999")
+ },
+ members[0].relations());
+ DomainMember[] filtered =
+ resolver.listMembers(
+ METALAKE, parent, children, direct().withNameContains("table0").build());
+ assertArrayEquals(new MetadataObject[] {tables[0]}, objects(filtered));
+ assertArrayEquals(members[0].relations(), filtered[0].relations());
+ assertEquals(
+ 0,
+ resolver.listMembers(
+ METALAKE, parent, children, direct().withNameContains("renamed").build())
+ .length);
+ verify(domainOperations, times(3))
+ .listDomainAssignments(
+ eq(METALAKE), eq(List.of(children[0])), any(), eq(Collections.emptyMap()));
+ verify(domainOperations)
+ .listDomainAssignments(eq(METALAKE), anyList(), any(), eq(Map.of(2L, candidates.get(2L))));
+ }
+
+ @Test
+ void testNameFilterAllowsJoinOnlyWhenEveryCandidateMatches() throws Exception {
+ DomainEntity parent = domain(1, "Finance", null, 10L, null);
+ DomainEntity child = domain(2, "Trading", "Finance", 20L, null);
+ DomainEntity[] children = {child};
+ MetadataObject[] tables = new MetadataObject[502];
+ for (int i = 0; i < tables.length; i++) {
+ String prefix = i == 501 ? "other" : "subset";
+ tables[i] = object("cat.sales." + prefix + i, MetadataObject.Type.TABLE);
+ assign(tables[i], tag(20, "trading"));
+ }
+ candidate(20, tables);
+ candidate(10, tables[0]);
+ assign(tables[0], tag(10, "finance"), tag(20, "trading"));
+ DomainMember[] all =
+ resolver.listMembers(
+ METALAKE,
+ parent,
+ children,
+ direct().withDomains("Trading").withNameContains("CAT.SALES").build());
+ assertEquals(502, all.length);
+ verify(domainOperations)
+ .listDomainAssignments(
+ eq(METALAKE), eq(List.of(parent)), any(), eq(Map.of(child.id(), candidates.get(20L))));
+ verify(domainOperations, never()).listDirectTagsByObjectIds(anyString(), any(), anyList());
+
+ DomainMember[] subset =
+ resolver.listMembers(
+ METALAKE,
+ parent,
+ children,
+ direct().withDomains("Trading").withNameContains("subset").build());
+ assertEquals(501, subset.length);
+ verify(domainOperations)
+ .listDirectTagsByObjectIds(
+ eq(METALAKE), eq(MetadataObject.Type.TABLE), argThat(ids -> ids.size() == 501));
+ assertEquals(tables[0], subset[0].object());
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.direct(), DomainRelation.viaSubdomain("Trading")},
+ subset[0].relations());
+ assertArrayEquals(subset[0].relations(), all[1].relations());
+ }
+
+ @Test
+ void testFilteredListingOnlyEnumeratesSelectedDomain() throws Exception {
+ DomainEntity finance = domain(1, "Finance", null, 10L, null);
+ DomainEntity trading = domain(2, "Trading", "Finance", 20L, null);
+ DomainEntity tax = domain(3, "Tax", "Finance", 30L, "tax");
+ DomainEntity[] children = {trading, tax};
+ DomainMemberFilter filter = direct().withDomains("Trading").withNameContains("cat.db").build();
+ assertEquals(0, resolver.listMembers(METALAKE, finance, children, filter).length);
+ verify(relations, never())
+ .listEntitiesByRelation(
+ eq(SupportsRelationOperations.Type.TAG_METADATA_OBJECT_REL),
+ any(NameIdentifier.class),
+ any(Entity.EntityType.class));
+
+ verify(domainOperations, never()).listDirectTagsByObjectIds(anyString(), any(), anyList());
+ MetadataObject second = object("cat.db.volumes", MetadataObject.Type.TABLE);
+ MetadataObject removed = object("cat.db.removed", MetadataObject.Type.TABLE);
+ candidate(20, TABLE, second, removed);
+ assign(TABLE, tag(20, "trading"), tag(30, "dept", "tax"));
+ assign(second, tag(20, "trading"));
+ assign(removed, tag(30, "dept", "tax"));
+ DomainMember[] members = resolver.listMembers(METALAKE, finance, children, filter);
+ verify(domainOperations)
+ .listDirectTagsByObjectIds(
+ METALAKE,
+ MetadataObject.Type.TABLE,
+ Arrays.asList(objectIds.get(TABLE), objectIds.get(second), objectIds.get(removed)));
+ assertArrayEquals(new MetadataObject[] {TABLE, second}, objects(members));
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Trading")}, members[1].relations());
+ assertArrayEquals(
+ new DomainRelation[] {
+ DomainRelation.viaSubdomain("Tax"), DomainRelation.viaSubdomain("Trading")
+ },
+ members[0].relations());
+ verify(domainOperations, times(2))
+ .listDomainAssignments(
+ eq(METALAKE), eq(List.of(trading)), any(), eq(Collections.emptyMap()));
+ }
+
+ @Test
+ void testFilteredListingSkipsTagLookupWhenOtherDomainsAreUnbound() throws Exception {
+ DomainEntity finance = domain(1, "Finance", null, null, null);
+ DomainEntity trading = domain(2, "Trading", "Finance", 20L, null);
+ DomainEntity tax = domain(3, "Tax", "Finance", null, null);
+ candidate(20, TABLE);
+ DomainMember[] members =
+ resolver.listMembers(
+ METALAKE,
+ finance,
+ new DomainEntity[] {trading, tax},
+ direct().withDomains("Trading").build());
+ assertArrayEquals(new MetadataObject[] {TABLE}, objects(members));
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.viaSubdomain("Trading")}, members[0].relations());
+ verify(domainOperations, never()).listDirectTagsByObjectIds(anyString(), any(), anyList());
+ }
+
+ @Test
+ void testDirectAndExpandedModesOnTheSameAssignments() throws Exception {
+ DomainEntity finance = domain(1, "Finance", null, 10L, "finance");
+ DomainEntity[] domains = {finance};
+ candidate(10, SCHEMA);
+ assign(SCHEMA, tag(10, "dept", "finance"));
+ when(store.list(
+ Namespace.of(METALAKE, "cat", "db"), TableEntity.class, Entity.EntityType.TABLE))
+ .thenReturn(
+ Collections.singletonList(
+ TableEntity.builder()
+ .withId(6L)
+ .withName("trades")
+ .withNamespace(Namespace.of(METALAKE, "cat", "db"))
+ .withAuditInfo(AUDIT)
+ .withColumns(Collections.emptyList())
+ .build()));
+
+ DomainMember[] directMembers =
+ resolver.listMembers(METALAKE, finance, domains, direct().build());
+ assertArrayEquals(new MetadataObject[] {SCHEMA}, objects(directMembers));
+ assertArrayEquals(new DomainRelation[] {DomainRelation.direct()}, directMembers[0].relations());
+
+ DomainMember[] expanded = resolver.listMembers(METALAKE, finance, domains, all());
+ assertArrayEquals(new MetadataObject[] {TABLE}, objects(expanded));
+ assertArrayEquals(
+ new DomainRelation[] {DomainRelation.inherited(SCHEMA)}, expanded[0].relations());
+ }
+
+ @Test
+ void testDirectMembersStorageFailureAndUnknownScopes() throws Exception {
+ DomainEntity finance = domain(1, "Finance", null, 10L, null);
+ DomainEntity unbound = domain(2, "Unbound", null, null, null);
+ assertEquals(
+ 0,
+ resolver.listMembers(METALAKE, unbound, new DomainEntity[] {unbound}, direct().build())
+ .length);
+ assertEquals(
+ 0,
+ resolver.listMembers(
+ METALAKE, finance, new DomainEntity[0], direct().withDomains("unknown").build())
+ .length);
+ verifyNoInteractions(relations);
+ when(domainOperations.listDomainAssignments(anyString(), anyList(), any(), any()))
+ .thenThrow(new IOException("storage"));
+ assertInstanceOf(
+ IOException.class,
+ assertThrows(
+ RuntimeException.class,
+ () ->
+ resolver.listMembers(
+ METALAKE, finance, new DomainEntity[] {finance}, direct().build()))
+ .getCause());
+ }
+
@Test
void testAllRelationsAndScopeFilters() {
DomainEntity parent = domain(1, "Finance", null, 10L, null);
@@ -157,9 +556,9 @@ class TestDomainMembershipResolver {
for (DomainMemberFilter filter :
Arrays.asList(
all(),
- DomainMemberFilter.builder().withDomains("Finance").build(),
- DomainMemberFilter.builder().withDomains("Trading").build(),
- DomainMemberFilter.builder().withDomains("Tax", "Trading").build())) {
+ DomainMemberFilter.builder().withExpand(true).withDomains("Finance").build(),
+ DomainMemberFilter.builder().withExpand(true).withDomains("Trading").build(),
+ DomainMemberFilter.builder().withExpand(true).withDomains("Tax", "Trading").build())) {
DomainMember[] members = resolver.listMembers(METALAKE, parent, domains, filter);
assertEquals(1, members.length);
assertEquals(TABLE, members[0].object());
@@ -171,7 +570,7 @@ class TestDomainMembershipResolver {
METALAKE,
parent,
domains,
- DomainMemberFilter.builder().withDomains("missing").build())
+ DomainMemberFilter.builder().withExpand(true).withDomains("missing").build())
.length);
assertArrayEquals(
new DomainRelation[] {DomainRelation.direct()},
@@ -261,6 +660,7 @@ class TestDomainMembershipResolver {
domain,
domains,
DomainMemberFilter.builder()
+ .withExpand(true)
.withTypes(MetadataObject.Type.TABLE)
.withNameContains("CAT.DB.TRA")
.build());
@@ -273,7 +673,7 @@ class TestDomainMembershipResolver {
METALAKE,
domain,
domains,
- DomainMemberFilter.builder().withNameContains("absent").build())
+ DomainMemberFilter.builder().withExpand(true).withNameContains("absent").build())
.length);
assertEquals(
0,
@@ -281,7 +681,10 @@ class TestDomainMembershipResolver {
METALAKE,
domain,
domains,
- DomainMemberFilter.builder().withTypes(MetadataObject.Type.MODEL).build())
+ DomainMemberFilter.builder()
+ .withExpand(true)
+ .withTypes(MetadataObject.Type.MODEL)
+ .build())
.length);
}
@@ -321,7 +724,10 @@ class TestDomainMembershipResolver {
candidate(10, ancestor);
assign(ancestor, tag(10, "dept", "finance"));
DomainMemberFilter filter =
- DomainMemberFilter.builder().withTypes(MetadataObject.Type.TABLE).build();
+ DomainMemberFilter.builder()
+ .withExpand(true)
+ .withTypes(MetadataObject.Type.TABLE)
+ .build();
DomainMember[] members = resolver.listMembers(METALAKE, finance, new DomainEntity[0], filter);
assertEquals(1, members.length);
assertEquals(childTable, members[0].object());
@@ -338,7 +744,7 @@ class TestDomainMembershipResolver {
void testUnknownScopesReturnEmptyWithoutEnumeratingMembers() {
DomainEntity finance = domain(1, "Finance", null, 10L, "finance");
DomainMemberFilter filter =
- DomainMemberFilter.builder().withDomains("unknown", "Secret").build();
+ DomainMemberFilter.builder().withExpand(true).withDomains("unknown", "Secret").build();
assertEquals(0, resolver.listMembers(METALAKE, finance, new DomainEntity[0], filter).length);
verifyNoInteractions(relations);
}
@@ -365,6 +771,29 @@ class TestDomainMembershipResolver {
assertThrows(IllegalArgumentException.class, () -> listDomains(METALAKE, null, domains));
}
+ @Test
+ void testExpandedMembersShareAncestorReadsAndSkipDroppedCandidates() throws Exception {
+ DomainEntity domain = domain(1, "Finance", null, 10L, null);
+ MetadataObject second = object("cat.db.volumes", MetadataObject.Type.TABLE);
+ candidate(10, TABLE, second);
+ assign(SCHEMA, tag(10, "finance"));
+ DomainEntity[] children = {};
+ assertArrayEquals(
+ new MetadataObject[] {TABLE, second},
+ objects(resolver.listMembers(METALAKE, domain, children, all())));
+ verify(relations)
+ .batchListEntitiesByRelation(
+ SupportsRelationOperations.Type.TAG_METADATA_OBJECT_REL,
+ List.of(NameIdentifier.of(METALAKE, "cat", "db")),
+ Entity.EntityType.SCHEMA);
+ metadataObjects
+ .when(() -> MetadataObjectUtil.checkMetadataObject(METALAKE, second))
+ .thenThrow(new NoSuchMetadataObjectException("dropped"));
+ assertArrayEquals(
+ new MetadataObject[] {TABLE},
+ objects(resolver.listMembers(METALAKE, domain, children, all())));
+ }
+
@Test
void testDroppedCandidateAndStorageFailure() throws Exception {
DomainEntity domain = domain(1, "Finance", null, 10L, null);
@@ -377,7 +806,7 @@ class TestDomainMembershipResolver {
assertThrows(
NoSuchMetadataObjectException.class,
() -> listDomains(METALAKE, TABLE, new DomainEntity[] {domain}));
- when(relations.listEntitiesByRelation(any(RelationQuery.class)))
+ when(domainOperations.listDomainAssignments(anyString(), anyList(), any(), any()))
.thenThrow(new IOException("storage"));
assertInstanceOf(
IOException.class,
@@ -462,20 +891,39 @@ class TestDomainMembershipResolver {
}
private void candidate(long tagId, MetadataObject... objects) {
+ candidates.put(tagId, entities(objects));
+ }
+
+ private void valuedCandidate(long tagId, String value, MetadataObject... objects) {
+ valuedCandidates.put(tagId + "=" + value, entities(objects));
+ }
+
+ private List<GenericEntity> entities(MetadataObject... objects) {
List<GenericEntity> entities = new ArrayList<>();
for (MetadataObject object : objects) {
+ long id = objectIds.computeIfAbsent(object, ignored -> 100L + objectIds.size());
+ candidateObjects.put(id, object);
entities.add(
GenericEntity.builder()
- .withId(100L + entities.size())
+ .withId(id)
.withName(object.fullName())
.withEntityType(Entity.EntityType.valueOf(object.type().name()))
.build());
}
- candidates.put(tagId, entities);
+ return entities;
}
+ /** Lists expanded members, the behavior these tests cover unless they say otherwise. */
private static DomainMemberFilter all() {
- return DomainMemberFilter.builder().build();
+ return DomainMemberFilter.builder().withExpand(true).build();
+ }
+
+ private static DomainMemberFilter.Builder direct() {
+ return DomainMemberFilter.builder();
+ }
+
+ private static MetadataObject[] objects(DomainMember[] members) {
+ return Arrays.stream(members).map(DomainMember::object).toArray(MetadataObject[]::new);
}
private static MetadataObject object(String name, MetadataObject.Type type) {
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java
index 0b58369548..4d32a5956c 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestDomainMetaService.java
@@ -30,6 +30,7 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -41,6 +42,7 @@ import org.apache.gravitino.Entity;
import org.apache.gravitino.EntityAlreadyExistsException;
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.MetadataObjects;
+import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.SupportsDomainOperations.LockedDomainState;
import org.apache.gravitino.authorization.AuthorizationUtils;
import org.apache.gravitino.domain.Domain;
@@ -51,7 +53,9 @@ import org.apache.gravitino.exceptions.OptimisticLockException;
import org.apache.gravitino.exceptions.TagAlreadyExistsException;
import org.apache.gravitino.meta.AuditInfo;
import org.apache.gravitino.meta.BaseMetalake;
+import org.apache.gravitino.meta.CatalogEntity;
import org.apache.gravitino.meta.DomainEntity;
+import org.apache.gravitino.meta.GenericEntity;
import org.apache.gravitino.meta.NamespacedEntityId;
import org.apache.gravitino.meta.TagEntity;
import org.apache.gravitino.meta.UserEntity;
@@ -606,6 +610,56 @@ public class TestDomainMetaService extends TestJDBCBackend {
Assertions.assertFalse(domainMetaService.deleteDomain(treasury.nameIdentifier(), stalePO));
}
+ @TestTemplate
+ void testSharedMemberAcrossDomainBatches() throws IOException {
+ createAndInsertMakeLake(METALAKE_NAME);
+ CatalogEntity catalog = createAndInsertCatalog(METALAKE_NAME, "shared");
+ TagEntity firstTag = newTag("first");
+ TagEntity lastTag = newTag("last");
+ backend.insert(firstTag, false);
+ backend.insert(lastTag, false);
+ DomainEntity first =
+ newDomain(METALAKE_NAME, "First", null).toBuilder().withBackingTagId(firstTag.id()).build();
+ DomainEntity last =
+ newDomain(METALAKE_NAME, "Last", null).toBuilder().withBackingTagId(lastTag.id()).build();
+ backend.insert(first, false);
+ backend.insert(last, false);
+ TagMetaService tags = TagMetaService.getInstance();
+ tags.associateTagsWithMetadataObject(
+ catalog.nameIdentifier(),
+ catalog.type(),
+ new NameIdentifier[] {firstTag.nameIdentifier(), lastTag.nameIdentifier()},
+ new NameIdentifier[0]);
+ List<DomainEntity> scope = new ArrayList<>();
+ scope.add(first);
+ // Intervening IDs no longer present in the database put the two live domains in separate
+ // batches.
+ for (int i = 1; i < 5_000; i++) {
+ scope.add(
+ newDomain(METALAKE_NAME, "Removed" + i, null).toBuilder()
+ .withBackingTagId(firstTag.id())
+ .build());
+ }
+ scope.add(last);
+ GenericEntity selectedObject =
+ GenericEntity.builder()
+ .withId(catalog.id())
+ .withName("name-from-first-read")
+ .withEntityType(Entity.EntityType.CATALOG)
+ .build();
+ Map<Long, List<GenericEntity>> assignments =
+ tags.listDomainAssignments(
+ METALAKE_NAME,
+ scope,
+ Set.of(MetadataObject.Type.CATALOG),
+ Map.of(first.id(), List.of(selectedObject)));
+ Assertions.assertEquals(Set.of(first.id(), last.id()), assignments.keySet());
+ Assertions.assertEquals(
+ List.of(catalog.id()),
+ assignments.get(first.id()).stream().map(GenericEntity::id).collect(Collectors.toList()));
+ Assertions.assertSame(selectedObject, assignments.get(last.id()).get(0));
+ }
+
@TestTemplate
public void testBackingTagIsStoredOnDomainRow() throws IOException {
createAndInsertMakeLake(METALAKE_NAME);
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestMetadataObjectService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestMetadataObjectService.java
index f077a9641a..52f399b788 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestMetadataObjectService.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestMetadataObjectService.java
@@ -30,6 +30,7 @@ import java.sql.Statement;
import java.time.Instant;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.gravitino.Entity;
@@ -303,6 +304,14 @@ public class TestMetadataObjectService extends TestJDBCBackend {
// Verify all are TABLE type
assertTrue(metadataObjects.stream().allMatch(obj -> obj.type() == MetadataObject.Type.TABLE));
+ Long schemaId =
+ EntityIdService.getEntityId(
+ NameIdentifier.of(METALAKE_NAME, catalogName, schemaName), Entity.EntityType.SCHEMA);
+ softDeleteSchemaMeta(schemaId);
+ Map<Long, String> missingParents =
+ MetadataObjectService.getTableObjectsFullName(List.of(table1.id(), table2.id()));
+ assertEquals(Set.of(table1.id(), table2.id()), missingParents.keySet());
+ assertTrue(missingParents.values().stream().allMatch(Objects::isNull));
}
@TestTemplate
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
index 7ba6567e5c..d52b3afd7b 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/service/TestTagMetaService.java
@@ -145,6 +145,24 @@ public class TestTagMetaService extends TestJDBCBackend {
List<GenericEntity> objects =
backend.listEntitiesByRelation(RelationQuery.forTagId(METALAKE_NAME, tag.id(), null));
assertEquals(catalog.id(), objects.get(0).id());
+ // Put the live ID in the second batch alongside IDs that no longer resolve.
+ List<Long> ids = new ArrayList<>();
+ for (long missing = -500; missing < 0; missing++) {
+ ids.add(missing);
+ }
+ ids.add(catalog.id());
+ List<TagEntity> directTags =
+ backend
+ .listDirectTagsByObjectIds(METALAKE_NAME, MetadataObject.Type.CATALOG, ids)
+ .get(catalog.id());
+ assertEquals(1, directTags.size());
+ assertEquals(tag.id(), directTags.get(0).id());
+ assertEquals(
+ Set.of("Finance", "finance"), Set.of(directTags.get(0).assignment().get().values()));
+ assertTrue(
+ backend.listDirectTagsByObjectIds("other", MetadataObject.Type.CATALOG, ids).isEmpty());
+ assertTrue(
+ backend.listDirectTagsByObjectIds(METALAKE_NAME, MetadataObject.Type.TABLE, ids).isEmpty());
backend.delete(tag.nameIdentifier(), Entity.EntityType.TAG, false);
TagEntity recreated =
TagEntity.builder()
diff --git a/design-docs/domain-design.md b/design-docs/domain-design.md
index 5788fae178..d2637cce80 100644
--- a/design-docs/domain-design.md
+++ b/design-docs/domain-design.md
@@ -137,8 +137,8 @@ Domain operations use the store's existing locking primitives, in one global ord
- **Rule**: an object's effective tags are its own plus its schema's and catalog's; for the same tag the nearest level wins, and different tags accumulate. A leaf object (see Member types) is a member of domain D when its effective tags match D's backing (tag, value). Membership reuses core's `EffectiveTagResolver`, which applies no tag-privilege filtering: domain visibility and object access are applied afterwards, so a caller needs no tag privilege.
- **Different tags accumulate**: with schema `finance` and table `sales`, the table is in both Finance and Sales, and a child cannot leave a domain it inherits.
- **Values of one tag** backing different domains override each other: with schema `dept=finance` and table `dept=hr`, the table is only in the `dept=hr` domain, unless it uses `dept=[finance, hr]`. This is the one case where a child can leave an inherited domain, and only for bindings with a value; a binding without a value matches every value.
-- **Member types**: leaf objects only: tables, views, filesets, topics, models and semantic models (`DomainMember.SUPPORTED_TYPES`). Catalogs and schemas are never members: one that carries a backing tag passes membership to the leaf objects under it through tag inheritance. Columns and functions are not members either: a column or function carrying a backing tag is not listed. A type that becomes taggable later joins only when it is added to this list. Metrics belong through their semantic model.
-- **Relations**: a leaf object relates to a domain in one of three ways, reported with its source by member listing and by domains of an object:
+- **Member types**: the default listing returns directly tagged catalogs, schemas and leaves. The leaf types are tables, views, filesets, topics, models and semantic models. Expanded listing and object-to-domain lookup support these leaf types. Columns and functions are excluded.
+- **Relations**: expanded listing and object-to-domain lookup report the following relations for a leaf. Direct listing reports Direct and Via subdomain for assignments on the object itself:
| Relation | Meaning | Source |
| :------------ | :------------------------------------------------------------- | :---------------------------------------- |
@@ -146,22 +146,21 @@ Domain operations use the store's existing locking primitives, in one global ord
| Inherited | the object inherits the backing tag from its catalog or schema | the nearest catalog or schema carrying it |
| Via subdomain | a visible subdomain of the domain has the object in its scope | that subdomain |
- Every relation that applies is reported, as a list of (relation, source) pairs, with no precedence: a table whose schema carries `finance` and which itself carries `trading` gets `[Inherited from cat.db, Via subdomain Trading]` under Finance, and an object in two subdomains gets one Via subdomain pair for each. Clients decide how to display them. Relations are always relative to the listed domain. An object is a member of the domain itself when its relations include Direct or Inherited. The relation is an enum; the exact field shape is an implementation choice.
-- **Domains of an object**: for a leaf object, every domain the caller can see whose scope contains the object, each with its relations. An object tagged only `trading` gets Trading (Direct) and Finance (Via subdomain Trading). Catalogs and schemas do not support this lookup, since they are never members; the domain a catalog or schema passes down is visible from its tags.
+ In an expanded listing, every relation that applies is reported, as a list of (relation, source) pairs, with no precedence: a table whose schema carries `finance` and which itself carries `trading` gets `[Inherited from cat.db, Via subdomain Trading]` under Finance, and an object in two subdomains gets one Via subdomain pair for each. Clients decide how to display them. Relations are always relative to the listed domain. An object is a member of the domain itself when its relations include Direct or Inherited. The relation is an enum; the exact field shape is an implementation choice.
+- **Domains of an object**: for a leaf object, every domain the caller can see whose scope contains the object, each with its relations. An object tagged only `trading` gets Trading (Direct) and Finance (Via subdomain Trading). This reverse lookup remains limited to leaves even though forward listing can return catalogs and schemas.
- **Removing a member**: membership ends when the object no longer carries the backing tag, by the tag rules. To take an object out of a domain backed by a tag without a value, remove the tag by name (v1 association request), which removes all its values on the object; a v2 request removes one (tag, value) pair. An inherited membership can only be removed on the catalog or schema.
- **Domain filters**: Phase 1 adds no domain filter to other list APIs. When one is added, it matches scope, consistent with member listing.
### Member listing
-`GET /domains/{domain}/objects` lists leaf objects, expanding catalogs and schemas:
+`GET /domains/{domain}/objects` defaults to direct assignments. Look up the selected domains' backing tags by stable ID and optional assignment value. A recreated tag with the same name has a different ID and cannot take over the binding.
-1. Resolve the backing tags of the domains in the selected scopes (by default the listed domain's whole scope: itself and its visible subdomains).
-2. List the objects carrying them by the bound tag ID and value. The existing lookup by tag name (`listMetadataObjectsForTag`) is not reused, since a tag deleted and recreated with the same name between steps would contribute its objects; this applies to bindings without a value too. Leaf objects are candidates as they are; a tagged catalog or schema is replaced by the leaf objects under it, from Gravitino's store.
-3. Keep the candidates whose effective tags match a selected backing tag by tag ID (the matching rules above, nearest level wins), so a leaf object that overrides an inherited value drops out. Only bindings with a value need this check.
-4. Drop objects the caller cannot access (`filterMetadataObject`), de-duplicate, and record each member's relations and sources.
+Return each accessible matching object once with its relations to the queried domain and its visible subdomains. If a schema and a table under it both carry matching assignments, both appear. A leaf that matches solely through inheritance appears only with `expand=true`.
+
+With `expand=true`, enumerate recorded leaves under each tagged container and check each leaf's effective tags against the selected bindings. A nearer assignment can override an inherited value.
- **A view of recorded objects**: membership is defined by the rule above; the listing shows the objects recorded in Gravitino's store. Objects in an external catalog that Gravitino has not recorded yet are not listed, so an empty listing does not mean an object is not a member.
-- **Cost**: a domain backed by a tag on a large catalog lists every recorded leaf object under it (see Open Questions).
+- **Cost**: expanding a domain backed by a tag on a large catalog visits every recorded leaf object under it (see Open Questions).
- **Per caller**: the listing depends on the subdomains and objects the caller can see, so its length is not a property of the domain. Paging and counts come in Phase 2; counts follow the listing and depend on the caller too, so they never reveal assets the caller cannot see.
### Access control
@@ -241,7 +240,8 @@ DomainMemberDTO { object: MetadataObjectDTO, relations: [{relation, source?}] }
- **Concurrency**: changes apply to the current state on the server and the last write wins, as for other Gravitino metadata operations; there is no version check. Detach removes the current parent edge and removing the backing tag removes the current one, whatever the caller's snapshot shows; detaching a top-level domain is a no-op, not an error. Domains are addressed by name, so if a domain is renamed and a new one takes its old name, later calls with that name act on the new domain.
- **Member listing parameters**:
- `domains` (repeatable, `?domains=Tax&domains=Trading`; not comma-separated, since domain names may contain `,`): each name, the listed domain itself or one of its visible subdomains, selects that domain's scope, and the result is the union. On Finance with subdomains Tax and Trading, not setting it or `domains=Finance` lists the whole scope (Finance, Tax and Trading), `domains=Tax` lists only Tax's members, and `domains=Tax&domains=Trading` lists Tax's and Trading's. Names that are neither the domain nor a subdomain visible to the caller are ignored; if all given names are ignored, the result is empty rather than everything, so a typo cannot widen it.
- - `types` (comma-separated, each a leaf member type) and `nameContains` (case-insensitive, on the full name). Filters apply to the expanded leaf list, so `types=TABLE` finds the tables under a tagged catalog.
+ - `expand` defaults to false. Set it to true to enumerate recorded leaves through inheritance.
+ - `types` accepts comma-separated leaf types and, for direct listing, CATALOG and SCHEMA. With `types=TABLE`, direct listing returns directly tagged tables. Add `expand=true` to include tables that inherit a matching tag. `nameContains` matches the full name case-insensitively.
- The listed domain's own members are those whose relations include Direct or Inherited.
- No paging in Phase 1, like the other core list APIs; paging and counts come in Phase 2.
- **Errors**:
@@ -265,7 +265,7 @@ A new read-only `domain` tool category in `mcp-server/`, added to `SUPPORTED_TOO
| :-------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `list_domains` | `GET /domains?details=true`; returns name, comment, parent, status and backing tag, so an agent can pick a domain |
| `get_domain_by_name` | `GET /domains/{domain}` |
-| `list_metadata_by_domain` | `GET /domains/{domain}/objects`, with `domains` (a list of scopes to include, the domain itself or its subdomains; default the whole scope), `types`, `name_contains`; lets an agent look within a domain by type and name |
+| `list_domain_members` | `GET /domains/{domain}/objects`, with `domains` (a list of scopes to include, the domain itself or its subdomains; default the whole scope), `types`, `name_contains`, and `expand`; lets an agent look within a domain by type and name |
| `list_domains_for_metadata` | `GET /objects/{type}/{fullName}/domains`, for leaf objects |
Adding members uses the existing `associate_tag_with_metadata` tool. It keeps removing tags by name (v1, all values) and is extended to accept (name, value) pairs and send the v2 request, so value-backed domains work. The MCP server forwards the caller's `Authorization` header, so the server's visibility rules apply; with OAuth client-credentials, the agent sees what that service identity sees.
@@ -293,7 +293,7 @@ Unity Catalog domains ([Domains and subdomains](https://docs.databricks.com/aws/
## Open Questions
-1. **Cost of expanding large catalogs**: member listing expands a tagged catalog or schema to every recorded leaf object under it. Paging (Phase 2) bounds the response, not the work; is a cheaper strategy needed for very large catalogs?
+1. **Cost of expanding large catalogs**: with `expand=true`, member listing expands a tagged catalog or schema to every recorded leaf object under it. Paging (Phase 2) bounds the response, not the work; is a cheaper strategy needed for very large catalogs?
2. **Data-access grants on domains**, if wanted later: deny-only grants (tagging can only tighten access), or allow grants that also require grant authority on the asset when tagging. Either works only where Gravitino enforces authorization itself and adds a membership lookup to every check.
## Task Breakdown
@@ -316,7 +316,7 @@ Unity Catalog domains ([Domains and subdomains](https://docs.databricks.com/aws/
- [ ] Membership resolution in `core/` on `EffectiveTagResolver`, returning the inherited source and matching by tag ID
- [ ] Lookup of tag relations by tag ID and value (the existing lookup is by tag name)
-- [ ] Member listing: expansion to leaf objects, relation lists, filters; domains of a leaf object
+- [ ] Member listing: direct objects and opt-in expansion to leaves, relation lists, filters; domains of a leaf object
- [ ] REST endpoints and tests
### Phase 1c: Clients, MCP and documentation
diff --git a/docs/domains.md b/docs/domains.md
index e3317af9fd..27248b83a1 100644
--- a/docs/domains.md
+++ b/docs/domains.md
@@ -31,10 +31,21 @@ existing [tag assignments and inheritance](./tags.md), rather than maintained in
Use the [tag API](./manage-tags-in-gravitino.md) to assign/remove a backing tag on a leaf, schema or
catalog. There is no Domain add-member or remove-member API.
-Only these leaf types are members: **table, view, fileset, topic, model and semantic model**.
-Tagged catalogs and schemas contribute their recorded leaves; they are never members themselves.
-Only objects already recorded by Gravitino are enumerated: a tag on an external catalog is not a
-request to crawl its backend. Empty results do not establish that external objects are absent.
+A member query has two modes:
+
+- **Direct members** (the default) are the objects that carry the backing tag themselves: leaves
+ (**table, view, fileset, topic, model and semantic model**) as well as **catalogs and schemas**.
+ A tagged schema and a directly tagged table under it are both listed. Descendants that match
+ only through inheritance appear in expanded listings. This mode reads only tag assignments and does not resolve each leaf's effective tags.
+- **Expanded members** (`expand=true`) are leaves only. A tagged catalog or schema is replaced by the
+ recorded leaves under it whose effective tags match the binding, following the inheritance rules
+ below. Only objects already recorded by Gravitino are enumerated: a tag on an external catalog is
+ not a request to crawl its backend. Empty results do not establish that external objects are
+ absent.
+
+Clients identify a member that includes its children by its `catalog` or `schema` type. Such a
+member stands for the objects under it, except those where a nearer assignment of the same tag
+overrides it as described below; use `expand=true` or object-to-domain lookup to resolve them.
For the same tag, the assignment nearest the leaf wins: leaf before schema before catalog.
Assignments are replaced as a whole at each nearer level, not combined with ancestor values.
@@ -54,18 +65,21 @@ cannot exclude the leaf from that domain.
## Relations and sources
A member query lists each object once, with **all** applicable relations relative to the queried
-domain. The same relations appear on detailed object-to-domain lookup. Relations have no precedence;
-clients must preserve their whole array.
+domain. Expanded members report the same relations as detailed object-to-domain lookup. Relations
+have no precedence; clients must preserve their whole array.
| SDK relation | REST `relation` | `source` |
| --- | --- | --- |
-| `DIRECT` | `direct` | Omitted: the leaf itself carries the backing tag. |
+| `DIRECT` | `direct` | Omitted: the object itself carries the backing tag. |
| `INHERITED` | `inherited` | The nearest assigned catalog or schema, with its complete `fullName` and `type`. |
| `VIA_SUBDOMAIN` | `via_subdomain` | The contributing child's literal name as `fullName`, with `type: domain`. |
-For example, a schema `ice.sales` carries Finance's backing tag and its table
+Direct members have only `direct` and `via_subdomain` relations; `inherited` appears only with
+`expand=true`. For example, a schema `ice.sales` carries Finance's backing tag and its table
`ice.sales.forecast` carries Planning's separate backing tag. Querying Finance, whose child is
-Planning, returns the table with both `inherited` from `ice.sales` and `via_subdomain` from Planning.
+Planning, returns the schema as `direct` and the table as `via_subdomain` from Planning. With
+`expand=true` it returns the table with both `inherited` from `ice.sales` and `via_subdomain` from
+Planning, and does not return the schema.
A direct assignment of Finance's tag masks its inherited assignment of that same tag, but the
independent Planning relation remains. Multiple contributing children produce multiple
`via_subdomain` relations. A child scope selected by a filter still reports relations relative to
@@ -86,16 +100,17 @@ All supplied options intersect; an unset option does not narrow the result.
| Option | Meaning |
| --- | --- |
-| `types` | Union of supported leaf types; REST accepts comma-separated, case-insensitive names with whitespace trimmed. Omit for all six types. |
+| `types` | Union of member types: the six leaf types, plus `CATALOG` and `SCHEMA` for direct members. REST accepts comma-separated, case-insensitive names with whitespace trimmed. Omit for all types. `CATALOG` or `SCHEMA` with `expand=true` is invalid. |
| `nameContains` (Python `name_contains`) | Case-insensitive substring of the full object name, including catalog/schema text. No wildcard or regex interpretation. Omit for any name; blank text is invalid. |
| `domains` | Union of selected scopes within the queried domain. Omit or use an empty SDK collection for its whole scope. |
+| `expand` | `false` (default) lists direct members; `true` expands catalogs and schemas into recorded leaves. Java `withExpand(true)`, Python `expand=True`, REST `expand=true`. |
For Finance with children Tax and Planning:
- Unset `domains`, or selecting `Finance`, includes Finance, Tax and Planning (subject to visibility).
- Selecting `Tax` includes only Tax's scope; selecting Tax and Planning includes their union.
- Selecting Finance does **not** mean only Finance's own members. To retain those, inspect relations
- for `DIRECT` or `INHERITED` in the returned members.
+ for `DIRECT` (or, with `expand=true`, `INHERITED`) in the returned members.
- Well-formed unknown names, unrelated domains and invisible children are ignored. If every supplied name is
ignored, the result is empty. Duplicate names do not duplicate members.
diff --git a/docs/gravitino-mcp-server.md b/docs/gravitino-mcp-server.md
index 7b8ab6e18e..330a3b3954 100644
--- a/docs/gravitino-mcp-server.md
+++ b/docs/gravitino-mcp-server.md
@@ -253,7 +253,7 @@ All are annotated as read-only and idempotent and issue only GET requests.
| `list_of_domains` | `details=true` | Domain snapshots, or names when false |
| `get_domain_by_name` | `domain_name` | A complete domain snapshot |
| `list_subdomains` | `domain_name`, `details=true` | Immediate subdomain snapshots or names |
-| `list_domain_members` | `domain_name`, optional `types`, `domains`, `name_contains` | Recorded leaf members with all applicable relations |
+| `list_domain_members` | `domain_name`, optional `types`, `domains`, `name_contains`, `expand` | Directly tagged objects, including catalogs and schemas. Use `expand=true` for accessible recorded leaves whose effective tags match |
| `list_domains_for_metadata` | `metadata_type`, `metadata_full_name`, `details=true` | Domains of a leaf object, including all relations when details is true |
Results follow the existing MCP JSON-string convention; empty lists return `[]`.
@@ -273,7 +273,8 @@ For example, call `list_domain_members` with:
}
```
-`types` is a list of leaf object types; `domains` selects the union of named scopes using repeated query parameters.
+`types` accepts leaf object types and, in the default listing, `CATALOG` and `SCHEMA`. With `expand=true`, only leaf types are valid.
+`domains` selects the union of named scopes using repeated query parameters.
Selecting the requested domain includes its visible children. Well-formed names outside that scope are ignored.
`name_contains` matches a case-insensitive substring of the full metadata object name.
If `name_contains` is omitted, empty, or contains only whitespace, MCP omits the
diff --git a/docs/manage-domains-in-gravitino.md b/docs/manage-domains-in-gravitino.md
index 0b09ffa39a..2d0baf42f7 100644
--- a/docs/manage-domains-in-gravitino.md
+++ b/docs/manage-domains-in-gravitino.md
@@ -611,7 +611,8 @@ for creating constrained tags and assigning them to catalogs or schemas.
### Assign a Backing Tag to an Object
Assign the Finance backing-tag value to the model using normal tag permissions. The same API
-works for leaf, schema and catalog assignments; the latter contribute recorded leaf members.
+works for leaf, schema and catalog assignments. A tagged container and its directly tagged descendants
+appear separately. Use `expand=true` to include recorded leaves that inherit the binding.
Tag-value requests use `application/vnd.gravitino.v2+json`; Domain endpoints use the v1 API.
<Tabs groupId='language' queryString>
@@ -681,8 +682,9 @@ model.supports_tags().assign_tags(
### List Domain Members
-List accessible recorded leaves in the domain and its visible children. Each object occurs once
-with all applicable relations and complete sources. An empty query returns an empty member array.
+List the accessible objects that directly carry the backing tag of the domain or its visible
+children. A directly tagged schema and a directly tagged table under it both appear. Each matching
+object occurs once with all applicable direct and subdomain relations.
<Tabs groupId='language' queryString>
<TabItem value="shell" label="REST">
@@ -709,6 +711,36 @@ members = domain.list_members(DomainMemberFilter())
</TabItem>
</Tabs>
+### List Expanded Domain Members
+
+Set `expand` to replace each tagged catalog or schema by the accessible recorded leaves under it
+that inherit the backing tag. Only leaves are returned, with `inherited` relations where they apply.
+
+<Tabs groupId='language' queryString>
+<TabItem value="shell" label="REST">
+
+```shell
+curl --fail-with-body -u anonymous:dummy \
+ "http://127.0.0.1:8090/api/metalakes/test/domains/Finance/objects?expand=true"
+```
+
+</TabItem>
+<TabItem value="java" label="Java">
+
+```java
+DomainMember[] leaves = domain.listMembers(DomainMemberFilter.builder().withExpand(true).build());
+```
+
+</TabItem>
+<TabItem value="python" label="Python">
+
+```python
+leaves = domain.list_members(DomainMemberFilter(expand=True))
+```
+
+</TabItem>
+</Tabs>
+
### Filter Domain Members
Filters intersect. `domains` selects the union of scopes, using one REST parameter per domain name. Selecting a child filters members but retains their full relations relative
diff --git a/docs/open-api/domains.yaml b/docs/open-api/domains.yaml
index 4de33cd026..e35a5f02dd 100644
--- a/docs/open-api/domains.yaml
+++ b/docs/open-api/domains.yaml
@@ -461,12 +461,16 @@ paths:
- $ref: "#/components/parameters/domain"
get:
tags: [domain]
- summary: List recorded domain members
+ summary: List domain members
operationId: listDomainMembers
description: >-
- Lists recorded leaf objects in the domain's scope, including subdomains, once each with
- all applicable relations. Tagged catalogs and schemas expand to recorded leaves; an empty
- result does not imply that unrecorded external objects are not members. Filters intersect.
+ Lists members in the domain's scope, including subdomains, once each with all applicable
+ relations. By default, lists the objects that directly carry the backing tag of the domain
+ or a visible subdomain, including catalogs and schemas. Directly tagged descendants appear
+ even when their container matches. Relations are DIRECT or VIA_SUBDOMAIN. With
+ expand=true, tagged catalogs and schemas expand to the recorded leaves that inherit the tag,
+ with INHERITED relations where they apply; an empty result does not imply that unrecorded
+ external objects are not members. Filters intersect.
No paging or counts are provided. Only visible domains and objects accessible to the caller are returned. Hidden drafts return 404, and hidden subdomain relations are omitted. No tag privilege is required.
parameters:
- name: domains
@@ -484,22 +488,28 @@ paths:
$ref: "#/components/schemas/DomainName"
- name: types
in: query
- description: Comma-separated leaf types, case-insensitive, with whitespace around each token trimmed. Omit to include all supported types. Blank tokens and unsupported types return 400.
+ description: Comma-separated member types, case-insensitive, with whitespace around each token trimmed. Omit to include all types. Blank tokens, unsupported types, and CATALOG or SCHEMA with expand=true return 400.
style: form
explode: false
schema:
type: array
items:
- $ref: "#/components/schemas/MemberType"
+ $ref: "#/components/schemas/ListedMemberType"
- name: nameContains
in: query
description: Nonblank substring of the member's complete full name, matched case-insensitively; no wildcard or regex interpretation. Omit for any name. Blank text returns 400.
schema:
type: string
minLength: 1
+ - name: expand
+ in: query
+ description: Whether to expand tagged catalogs and schemas into the recorded leaves under them that inherit the backing tag. Defaults to false, which lists the objects that carry the backing tag themselves.
+ schema:
+ type: boolean
+ default: false
responses:
"200":
- description: The matching recorded members.
+ description: The matching members.
content:
application/vnd.gravitino.v1+json:
schema:
@@ -533,7 +543,7 @@ paths:
- name: type
in: path
required: true
- description: Leaf metadata object type, case-insensitive. Catalogs and schemas are not members.
+ description: Leaf metadata object type, case-insensitive. Catalogs and schemas are not supported for object-to-domain lookup.
schema:
$ref: "#/components/schemas/MemberType"
- name: fullName
@@ -637,6 +647,11 @@ components:
description: A supported leaf domain member type.
enum: [TABLE, VIEW, FILESET, TOPIC, MODEL, SEMANTIC_MODEL]
+ ListedMemberType:
+ type: string
+ description: A type of listed domain member. CATALOG and SCHEMA are listed only without expand.
+ enum: [CATALOG, SCHEMA, TABLE, VIEW, FILESET, TOPIC, MODEL, SEMANTIC_MODEL]
+
DomainRelation:
type: object
description: One applicable membership relation relative to the queried domain, with no precedence over other relations. All applicable relations are returned; a direct assignment masks inheritance of the same tag.
@@ -664,14 +679,14 @@ components:
MemberObject:
type: object
- description: A leaf metadata object serialized by the server.
+ description: A member metadata object serialized by the server. Direct listings can include a catalog or schema alongside its directly tagged descendants.
required: [fullName, type]
properties:
fullName:
type: string
type:
type: string
- enum: [table, view, fileset, topic, model, semantic_model]
+ enum: [catalog, schema, table, view, fileset, topic, model, semantic_model]
DomainMember:
type: object
@@ -731,17 +746,21 @@ components:
$ref: "#/components/schemas/DomainRelation"
DomainMemberListResponse:
+ description: >-
+ The example is a default (direct) listing. With expand=true, the schema is replaced by its
+ leaves, which report inherited relations.
example:
code: 0
members:
+ - object:
+ fullName: cat.schema
+ type: schema
+ relations:
+ - relation: direct
- object:
fullName: cat.schema.table
type: table
relations:
- - relation: inherited
- source:
- fullName: cat.schema
- type: schema
- relation: via_subdomain
source:
fullName: Finance_US
diff --git a/mcp-server/mcp_server/client/domain_operation.py b/mcp-server/mcp_server/client/domain_operation.py
index c0c5967a65..d4ed2c2ada 100644
--- a/mcp-server/mcp_server/client/domain_operation.py
+++ b/mcp-server/mcp_server/client/domain_operation.py
@@ -42,10 +42,18 @@ class DomainOperation(ABC):
types: list[str] | None = None,
domains: list[str] | None = None,
name_contains: str | None = None,
+ *,
+ expand: bool = False,
) -> str:
- """List recorded leaf members and all applicable relations.
+ """List domain members and all applicable relations.
- types filters leaf object types (for example TABLE and TOPIC).
+ By default, lists objects directly assigned the backing tag of the domain
+ or a visible subdomain. A tagged catalog or schema appears once. A nearer
+ assignment of the same tag can override the inherited value and exclude a
+ descendant. Set expand=true to list accessible recorded leaves whose
+ effective tags match, with INHERITED relations where applicable.
+ types filters object types (for example TABLE, TOPIC, CATALOG or SCHEMA;
+ CATALOG and SCHEMA are not allowed with expand=true).
domains filters source domain names. name_contains matches a case-insensitive
substring of the full metadata object name. Blank values omit this filter.
"""
diff --git a/mcp-server/mcp_server/client/plain/plain_rest_client_domain_operation.py b/mcp-server/mcp_server/client/plain/plain_rest_client_domain_operation.py
index 6298df34cf..1580f23099 100644
--- a/mcp-server/mcp_server/client/plain/plain_rest_client_domain_operation.py
+++ b/mcp-server/mcp_server/client/plain/plain_rest_client_domain_operation.py
@@ -66,6 +66,8 @@ class PlainRESTClientDomainOperation(DomainOperation):
types: list[str] | None = None,
domains: list[str] | None = None,
name_contains: str | None = None,
+ *,
+ expand: bool = False,
) -> str:
params = []
if types:
@@ -74,6 +76,8 @@ class PlainRESTClientDomainOperation(DomainOperation):
params.extend(("domains", domain) for domain in domains)
if name_contains and name_contains.strip():
params.append(("nameContains", name_contains))
+ if expand:
+ params.append(("expand", "true"))
response = await self._rest_client.get(
f"{self._metalake_path}/domains/{encode_path_segment(domain_name)}/objects",
diff --git a/mcp-server/mcp_server/tools/domain.py b/mcp-server/mcp_server/tools/domain.py
index b53480f638..a5f0ce377e 100644
--- a/mcp-server/mcp_server/tools/domain.py
+++ b/mcp-server/mcp_server/tools/domain.py
@@ -82,10 +82,18 @@ def load_domain_tools(mcp: FastMCP):
types: list[str] | None = None,
domains: list[str] | None = None,
name_contains: str | None = None,
+ *,
+ expand: bool = False,
) -> str:
- """List recorded leaf members and all applicable relations.
-
- types filters leaf object types (for example TABLE and TOPIC).
+ """List domain members and all applicable relations.
+
+ By default, lists objects directly assigned the backing tag of the domain
+ or a visible subdomain. A tagged catalog or schema appears once. A nearer
+ assignment of the same tag can override the inherited value and exclude a
+ descendant. Set expand=true to list accessible recorded leaves whose
+ effective tags match, with INHERITED relations where applicable.
+ types filters object types (for example TABLE, TOPIC, CATALOG or SCHEMA;
+ CATALOG and SCHEMA are not allowed with expand=true).
domains filters source domain names. name_contains matches a case-insensitive
substring of the full metadata object name. Blank values omit this filter.
@@ -94,7 +102,7 @@ def load_domain_tools(mcp: FastMCP):
"""
client = ctx.request_context.lifespan_context.rest_client()
return await client.as_domain_operation().list_domain_members(
- domain_name, types, domains, name_contains
+ domain_name, types, domains, name_contains, expand=expand
)
@mcp.tool(
diff --git a/mcp-server/tests/unit/tools/mock_operation.py b/mcp-server/tests/unit/tools/mock_operation.py
index ae5501aeec..0021751269 100644
--- a/mcp-server/tests/unit/tools/mock_operation.py
+++ b/mcp-server/tests/unit/tools/mock_operation.py
@@ -570,6 +570,8 @@ class MockDomainOperation(DomainOperation):
types: list[str] | None = None,
domains: list[str] | None = None,
name_contains: str | None = None,
+ *,
+ expand: bool = False,
) -> str:
return "[]"
diff --git a/mcp-server/tests/unit/tools/test_domain.py b/mcp-server/tests/unit/tools/test_domain.py
index 43ee94a535..409ba8059d 100644
--- a/mcp-server/tests/unit/tools/test_domain.py
+++ b/mcp-server/tests/unit/tools/test_domain.py
@@ -179,6 +179,15 @@ class TestDomainTool(unittest.IsolatedAsyncioTestCase):
self.assertEqual(query["types"], "TABLE,TOPIC")
self.assertEqual(query.get_list("domains"), ["child,one", "child & 二"])
self.assertEqual(query["nameContains"], "a&b + %/?")
+ self.assertNotIn("expand", query)
+
+ await self._call(
+ "list_domain_members",
+ {"domain_name": "sales", "types": ["TABLE"], "expand": True},
+ )
+ query = self.requests[-1].url.params
+ self.assertEqual(query["types"], "TABLE")
+ self.assertEqual(query["expand"], "true")
async def test_encoded_paths_and_authorization(self):
value = "a/b ?#%,二"
diff --git a/server-common/src/main/java/org/apache/gravitino/server/authorization/DomainAuthzHelper.java b/server-common/src/main/java/org/apache/gravitino/server/authorization/DomainAuthzHelper.java
index 1227c3a8df..79240816ba 100644
--- a/server-common/src/main/java/org/apache/gravitino/server/authorization/DomainAuthzHelper.java
+++ b/server-common/src/main/java/org/apache/gravitino/server/authorization/DomainAuthzHelper.java
@@ -332,6 +332,7 @@ public final class DomainAuthzHelper {
.withDomains(selected.toArray(new String[0]))
.withTypes(filter.types().toArray(new MetadataObject.Type[0]))
.withNameContains(filter.nameContains().orElse(null))
+ .withExpand(filter.expand())
.build();
}
}
diff --git a/server-common/src/test/java/org/apache/gravitino/server/authorization/TestDomainMembershipAuthorization.java b/server-common/src/test/java/org/apache/gravitino/server/authorization/TestDomainMembershipAuthorization.java
index 8f7c5b45c5..f046580a55 100644
--- a/server-common/src/test/java/org/apache/gravitino/server/authorization/TestDomainMembershipAuthorization.java
+++ b/server-common/src/test/java/org/apache/gravitino/server/authorization/TestDomainMembershipAuthorization.java
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.time.Instant;
+import java.util.Arrays;
import java.util.Collections;
import org.apache.gravitino.Config;
import org.apache.gravitino.Configs;
@@ -149,6 +150,78 @@ class TestDomainMembershipAuthorization {
assertEquals("trades", filter.getValue().nameContains().get());
}
+ @Test
+ void expandSurvivesVisibleScopeSelection() {
+ DomainEntity visible = domain("Tax", "Finance", Domain.Status.PUBLISHED);
+ when(dispatcher.listSubdomainInfos("lake", "Finance"))
+ .thenReturn(new DomainEntity[] {hidden, visible});
+ when(dispatcher.listMembers(eq("lake"), eq(parent), any(DomainEntity[].class), any()))
+ .thenReturn(new DomainMember[0]);
+ DomainAuthzHelper.listMembers(
+ dispatcher,
+ "lake",
+ "Finance",
+ DomainMemberFilter.builder().withDomains("Trading", "Tax").withExpand(true).build());
+ ArgumentCaptor<DomainMemberFilter> filter = ArgumentCaptor.forClass(DomainMemberFilter.class);
+ verify(dispatcher)
+ .listMembers(eq("lake"), eq(parent), any(DomainEntity[].class), filter.capture());
+ assertEquals(
+ DomainMemberFilter.builder().withDomains("Tax").withExpand(true).build(),
+ filter.getValue());
+ }
+
+ @Test
+ void catalogAndSchemaMembersAreFilteredByObjectAccess() {
+ MetadataObject catalog = MetadataObjects.parse("cat", MetadataObject.Type.CATALOG);
+ MetadataObject schema = MetadataObjects.parse("cat.db", MetadataObject.Type.SCHEMA);
+ MetadataObject secretCatalog = MetadataObjects.parse("secret", MetadataObject.Type.CATALOG);
+ MetadataObject secretSchema = MetadataObjects.parse("cat.hidden", MetadataObject.Type.SCHEMA);
+ DomainRelation[] direct = {DomainRelation.direct()};
+ when(dispatcher.listMembers(eq("lake"), eq(parent), any(DomainEntity[].class), any()))
+ .thenReturn(
+ new DomainMember[] {
+ new DomainMemberInfo(catalog, direct),
+ new DomainMemberInfo(schema, direct),
+ new DomainMemberInfo(secretCatalog, direct),
+ new DomainMemberInfo(secretSchema, direct)
+ });
+ when(authorizer.deny(
+ any(), anyString(), eq(secretCatalog), eq(Privilege.Name.USE_CATALOG), any()))
+ .thenReturn(true);
+ when(authorizer.deny(
+ any(), anyString(), eq(secretSchema), eq(Privilege.Name.USE_SCHEMA), any()))
+ .thenReturn(true);
+ DomainMember[] members =
+ DomainAuthzHelper.listMembers(
+ dispatcher, "lake", "Finance", DomainMemberFilter.builder().build());
+ assertArrayEquals(
+ new MetadataObject[] {catalog, schema},
+ Arrays.stream(members).map(DomainMember::object).toArray(MetadataObject[]::new));
+ }
+
+ @Test
+ void containerTaggedOnlyByHiddenChildIsRemoved() {
+ MetadataObject schema = MetadataObjects.parse("cat.db", MetadataObject.Type.SCHEMA);
+ MetadataObject catalog = MetadataObjects.parse("cat", MetadataObject.Type.CATALOG);
+ when(dispatcher.listMembers(eq("lake"), eq(parent), any(DomainEntity[].class), any()))
+ .thenReturn(
+ new DomainMember[] {
+ new DomainMemberInfo(
+ schema, new DomainRelation[] {DomainRelation.viaSubdomain("Trading")}),
+ new DomainMemberInfo(
+ catalog,
+ new DomainRelation[] {
+ DomainRelation.direct(), DomainRelation.viaSubdomain("Trading")
+ })
+ });
+ DomainMember[] members =
+ DomainAuthzHelper.listMembers(
+ dispatcher, "lake", "Finance", DomainMemberFilter.builder().build());
+ assertEquals(1, members.length);
+ assertEquals(catalog, members[0].object());
+ assertArrayEquals(new DomainRelation[] {DomainRelation.direct()}, members[0].relations());
+ }
+
@Test
void objectAccessIsCheckedWithoutTagPrivileges() {
when(dispatcher.listMembers(eq("lake"), eq(parent), any(DomainEntity[].class), any()))
diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/DomainMembershipOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/DomainMembershipOperations.java
index aa49bfa8d7..25ec8737ee 100644
--- a/server/src/main/java/org/apache/gravitino/server/web/rest/DomainMembershipOperations.java
+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/DomainMembershipOperations.java
@@ -26,6 +26,7 @@ import java.util.Locale;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -49,7 +50,7 @@ import org.apache.gravitino.utils.NameValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/** REST queries for the recorded leaf members in a domain's scope. */
+/** REST queries for the members in a domain's scope. */
@Path("/metalakes/{metalake}/domains/{domain}/objects")
public class DomainMembershipOperations {
@@ -72,10 +73,11 @@ public class DomainMembershipOperations {
*
* @param metalake The metalake name.
* @param domain The domain name.
- * @param types Comma-separated leaf types, or null for all supported types.
+ * @param types Comma-separated member types, or null for all types.
* @param nameContains Case-insensitive full-name substring, or null for any name.
* @param domains Repeated domain names selecting the union of their scopes.
- * @return The matching recorded members with all applicable relations.
+ * @param expand Whether to expand catalogs and schemas into the recorded leaf objects under them.
+ * @return The matching members with all applicable relations.
*/
@GET
@Produces("application/vnd.gravitino.v1+json")
@@ -88,14 +90,15 @@ public class DomainMembershipOperations {
@PathParam("domain") String domain,
@QueryParam("types") @Nullable String types,
@QueryParam("nameContains") @Nullable String nameContains,
- @QueryParam("domains") List<String> domains) {
+ @QueryParam("domains") List<String> domains,
+ @QueryParam("expand") @DefaultValue("false") boolean expand) {
LOG.info("Received list members request for domain {} under metalake {}", domain, metalake);
try {
return Utils.doAs(
httpRequest,
() -> {
DomainMemberFilter.Builder filter =
- DomainMemberFilter.builder().withNameContains(nameContains);
+ DomainMemberFilter.builder().withNameContains(nameContains).withExpand(expand);
if (types != null) {
filter.withTypes(
Arrays.stream(types.split(",", -1))
@@ -122,7 +125,8 @@ public class DomainMembershipOperations {
private static MetadataObject.Type parseMemberType(String value) {
try {
MetadataObject.Type type = MetadataObject.Type.valueOf(value.trim().toUpperCase(Locale.ROOT));
- if (DomainMember.SUPPORTED_TYPES.contains(type)) {
+ if (DomainMember.SUPPORTED_TYPES.contains(type)
+ || DomainMember.CONTAINER_TYPES.contains(type)) {
return type;
}
} catch (IllegalArgumentException ignored) {
@@ -132,6 +136,8 @@ public class DomainMembershipOperations {
"Unsupported domain member type '"
+ value
+ "'. Supported types: "
- + DomainMember.SUPPORTED_TYPES);
+ + DomainMember.SUPPORTED_TYPES
+ + " and, without expand, "
+ + DomainMember.CONTAINER_TYPES);
}
}
diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java
index 6fe13fd831..2f4647fd61 100644
--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java
+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainAuthorizationOperations.java
@@ -370,7 +370,8 @@ public class TestDomainAuthorizationOperations extends BaseOperationsTest {
mock(HttpServletResponse.class),
(req, response) -> {
try (Response result =
- operations.listMembers("lake", "missing", null, null, Collections.emptyList())) {
+ operations.listMembers(
+ "lake", "missing", null, null, Collections.emptyList(), false)) {
assertEquals(404, result.getStatus());
((HttpServletResponse) response).setStatus(result.getStatus());
}
diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainMembershipOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainMembershipOperations.java
index 779faa4c08..2affe6b941 100644
--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainMembershipOperations.java
+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestDomainMembershipOperations.java
@@ -168,6 +168,59 @@ public class TestDomainMembershipOperations extends BaseOperationsTest {
}
}
+ @Test
+ public void testDirectContainerMembersAndExpand() {
+ MetadataObject catalog = MetadataObjects.parse("cat", MetadataObject.Type.CATALOG);
+ MetadataObject schema = MetadataObjects.parse("cat.schema", MetadataObject.Type.SCHEMA);
+ when(dispatcher.listMembers(eq("test"), eq("Finance"), any()))
+ .thenReturn(
+ new DomainMember[] {
+ new DomainMemberInfo(catalog, new DomainRelation[] {DomainRelation.direct()}),
+ new DomainMemberInfo(
+ schema, new DomainRelation[] {DomainRelation.viaSubdomain("Tax_Trading")})
+ });
+ try (Response response =
+ target(MEMBERS).queryParam("types", "catalog, SCHEMA").request().get()) {
+ assertEquals(200, response.getStatus());
+ DomainMemberListResponse result = response.readEntity(DomainMemberListResponse.class);
+ result.validate();
+ assertEquals(2, result.getMembers().length);
+ assertEquals(MetadataObject.Type.CATALOG, result.getMembers()[0].getObject().type());
+ assertEquals("cat", result.getMembers()[0].getObject().fullName());
+ assertEquals(MetadataObject.Type.SCHEMA, result.getMembers()[1].getObject().type());
+ assertEquals(
+ DomainRelation.Type.VIA_SUBDOMAIN,
+ result.getMembers()[1].getRelations()[0].getRelation());
+ }
+ try (Response response =
+ target(MEMBERS).queryParam("types", "TABLE").queryParam("expand", true).request().get()) {
+ assertEquals(200, response.getStatus());
+ }
+ ArgumentCaptor<DomainMemberFilter> filter = ArgumentCaptor.forClass(DomainMemberFilter.class);
+ verify(dispatcher, times(2)).listMembers(eq("test"), eq("Finance"), filter.capture());
+ assertEquals(
+ DomainMemberFilter.builder()
+ .withTypes(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA)
+ .build(),
+ filter.getAllValues().get(0));
+ assertEquals(
+ DomainMemberFilter.builder().withTypes(MetadataObject.Type.TABLE).withExpand(true).build(),
+ filter.getAllValues().get(1));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"CATALOG", "SCHEMA", "TABLE,schema"})
+ public void testContainerTypesRejectedWithExpand(String types) {
+ try (Response response =
+ target(MEMBERS).queryParam("types", types).queryParam("expand", "true").request().get()) {
+ assertEquals(400, response.getStatus());
+ ErrorResponse error = response.readEntity(ErrorResponse.class);
+ assertEquals("IllegalArgumentException", error.getType());
+ assertTrue(error.getMessage().contains("expand"));
+ }
+ verifyNoInteractions(dispatcher);
+ }
+
@ParameterizedTest
@ValueSource(strings = {"TABLE", "VIEW", "FILESET", "TOPIC", "MODEL", "SEMANTIC_MODEL"})
public void testSupportedMemberTypes(String type) {
@@ -189,18 +242,7 @@ public class TestDomainMembershipOperations extends BaseOperationsTest {
@ParameterizedTest
@ValueSource(
- strings = {
- "",
- "TABLE,",
- ",TABLE",
- "TABLE,,VIEW",
- "CATALOG",
- "SCHEMA",
- "COLUMN",
- "FUNCTION",
- "DOMAIN",
- "UNKNOWN"
- })
+ strings = {"", "TABLE,", ",TABLE", "TABLE,,VIEW", "COLUMN", "FUNCTION", "DOMAIN", "UNKNOWN"})
public void testInvalidTypes(String types) {
try (Response response = target(MEMBERS).queryParam("types", types).request().get()) {
assertEquals(400, response.getStatus());