Skip to content

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

[#11170] fix(audit): Add ListEvent interface with resultCount to list events and surface count in audit log (#11199)

Jerry Shaobb05b3f6aa46
diff --git a/core/src/main/java/org/apache/gravitino/audit/v2/SimpleAuditLogV2.java b/core/src/main/java/org/apache/gravitino/audit/v2/SimpleAuditLogV2.java
index 104e91a864..99a6ecb012 100644
--- a/core/src/main/java/org/apache/gravitino/audit/v2/SimpleAuditLogV2.java
+++ b/core/src/main/java/org/apache/gravitino/audit/v2/SimpleAuditLogV2.java
@@ -22,12 +22,15 @@ package org.apache.gravitino.audit.v2;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.audit.AuditLog;
import org.apache.gravitino.listener.api.event.BaseEvent;
import org.apache.gravitino.listener.api.event.EventSource;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationStatus;
import org.apache.gravitino.listener.api.event.OperationType;
@@ -101,7 +104,17 @@ public class SimpleAuditLogV2 implements AuditLog {
@Override
public String toString() {
Map<String, String> info = customInfo();
- String customInfoStr = info != null && !info.isEmpty() ? info.toString() : "";
+ List<String> parts = new ArrayList<>();
+ if (info != null) {
+ info.forEach((k, v) -> parts.add(k + "=" + v));
+ }
+ if (event instanceof ListEvent) {
+ int count = ((ListEvent) event).resultCount();
+ if (count >= 0) {
+ parts.add("count=" + count);
+ }
+ }
+ String customInfoStr = parts.isEmpty() ? "" : "{" + String.join(", ", parts) + "}";
return String.format(
"[%s]\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
TIMESTAMP_FORMATTER.format(Instant.ofEpochMilli(timestamp())),
diff --git a/core/src/main/java/org/apache/gravitino/listener/AccessControlEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/AccessControlEventDispatcher.java
index 2234672875..343c7128bb 100644
--- a/core/src/main/java/org/apache/gravitino/listener/AccessControlEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/AccessControlEventDispatcher.java
@@ -188,7 +188,8 @@ public class AccessControlEventDispatcher implements AccessControlDispatcher {
eventBus.dispatchEvent(new ListUsersPreEvent(initiator, metalake));
try {
User[] users = dispatcher.listUsers(metalake);
- eventBus.dispatchEvent(new ListUsersEvent(initiator, metalake));
+ eventBus.dispatchEvent(
+ new ListUsersEvent(initiator, metalake, users != null ? users.length : -1));
return users;
} catch (Exception e) {
@@ -205,7 +206,8 @@ public class AccessControlEventDispatcher implements AccessControlDispatcher {
eventBus.dispatchEvent(new ListUserNamesPreEvent(initiator, metalake));
try {
String[] userNames = dispatcher.listUserNames(metalake);
- eventBus.dispatchEvent(new ListUserNamesEvent(initiator, metalake));
+ eventBus.dispatchEvent(
+ new ListUserNamesEvent(initiator, metalake, userNames != null ? userNames.length : -1));
return userNames;
} catch (Exception e) {
@@ -275,7 +277,8 @@ public class AccessControlEventDispatcher implements AccessControlDispatcher {
eventBus.dispatchEvent(new ListGroupsPreEvent(initiator, metalake));
try {
Group[] groups = dispatcher.listGroups(metalake);
- eventBus.dispatchEvent(new ListGroupsEvent(initiator, metalake));
+ eventBus.dispatchEvent(
+ new ListGroupsEvent(initiator, metalake, groups != null ? groups.length : -1));
return groups;
} catch (Exception e) {
@@ -292,7 +295,9 @@ public class AccessControlEventDispatcher implements AccessControlDispatcher {
eventBus.dispatchEvent(new ListGroupNamesPreEvent(initiator, metalake));
try {
String[] groupNames = dispatcher.listGroupNames(metalake);
- eventBus.dispatchEvent(new ListGroupNamesEvent(initiator, metalake));
+ eventBus.dispatchEvent(
+ new ListGroupNamesEvent(
+ initiator, metalake, groupNames != null ? groupNames.length : -1));
return groupNames;
} catch (Exception e) {
@@ -452,7 +457,8 @@ public class AccessControlEventDispatcher implements AccessControlDispatcher {
eventBus.dispatchEvent(new ListRoleNamesPreEvent(initiator, metalake));
try {
String[] roleNames = dispatcher.listRoleNames(metalake);
- eventBus.dispatchEvent(new ListRoleNamesEvent(initiator, metalake));
+ eventBus.dispatchEvent(
+ new ListRoleNamesEvent(initiator, metalake, roleNames != null ? roleNames.length : -1));
return roleNames;
} catch (Exception e) {
@@ -470,7 +476,9 @@ public class AccessControlEventDispatcher implements AccessControlDispatcher {
eventBus.dispatchEvent(new ListRoleNamesPreEvent(initiator, metalake, object));
try {
String[] roleNames = dispatcher.listRoleNamesByObject(metalake, object);
- eventBus.dispatchEvent(new ListRoleNamesEvent(initiator, metalake, object));
+ eventBus.dispatchEvent(
+ new ListRoleNamesEvent(
+ initiator, metalake, object, roleNames != null ? roleNames.length : -1));
return roleNames;
} catch (Exception e) {
diff --git a/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java
index afaf131593..ce95aa2b6a 100644
--- a/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java
@@ -82,7 +82,11 @@ public class CatalogEventDispatcher implements CatalogDispatcher {
eventBus.dispatchEvent(new ListCatalogPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
NameIdentifier[] nameIdentifiers = dispatcher.listCatalogs(namespace);
- eventBus.dispatchEvent(new ListCatalogEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListCatalogEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ nameIdentifiers != null ? nameIdentifiers.length : -1));
return nameIdentifiers;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -96,7 +100,11 @@ public class CatalogEventDispatcher implements CatalogDispatcher {
eventBus.dispatchEvent(new ListCatalogPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
Catalog[] catalogs = dispatcher.listCatalogsInfo(namespace);
- eventBus.dispatchEvent(new ListCatalogEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListCatalogEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ catalogs != null ? catalogs.length : -1));
return catalogs;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java
index 77bbe390ae..c0f5fb5d80 100644
--- a/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/FilesetEventDispatcher.java
@@ -77,7 +77,11 @@ public class FilesetEventDispatcher implements FilesetDispatcher {
eventBus.dispatchEvent(new ListFilesetPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
NameIdentifier[] nameIdentifiers = dispatcher.listFilesets(namespace);
- eventBus.dispatchEvent(new ListFilesetEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListFilesetEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ nameIdentifiers != null ? nameIdentifiers.length : -1));
return nameIdentifiers;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -94,7 +98,12 @@ public class FilesetEventDispatcher implements FilesetDispatcher {
try {
FileInfo[] fileInfos = dispatcher.listFiles(ident, locationName, subPath);
eventBus.dispatchEvent(
- new ListFilesEvent(PrincipalUtils.getCurrentUserName(), ident, locationName, subPath));
+ new ListFilesEvent(
+ PrincipalUtils.getCurrentUserName(),
+ ident,
+ locationName,
+ subPath,
+ fileInfos != null ? fileInfos.length : -1));
return fileInfos;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/FunctionEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/FunctionEventDispatcher.java
index 52eba85e04..faf683388d 100644
--- a/core/src/main/java/org/apache/gravitino/listener/FunctionEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/FunctionEventDispatcher.java
@@ -77,7 +77,9 @@ public class FunctionEventDispatcher implements FunctionDispatcher {
eventBus.dispatchEvent(new ListFunctionPreEvent(user, namespace));
try {
NameIdentifier[] nameIdentifiers = dispatcher.listFunctions(namespace);
- eventBus.dispatchEvent(new ListFunctionEvent(user, namespace));
+ eventBus.dispatchEvent(
+ new ListFunctionEvent(
+ user, namespace, nameIdentifiers != null ? nameIdentifiers.length : -1));
return nameIdentifiers;
} catch (Exception e) {
eventBus.dispatchEvent(new ListFunctionFailureEvent(user, namespace, e));
@@ -92,7 +94,9 @@ public class FunctionEventDispatcher implements FunctionDispatcher {
try {
Function[] functions = dispatcher.listFunctionInfos(namespace);
FunctionInfo[] functionInfos =
- Arrays.stream(functions).map(FunctionInfo::new).toArray(FunctionInfo[]::new);
+ functions != null
+ ? Arrays.stream(functions).map(FunctionInfo::new).toArray(FunctionInfo[]::new)
+ : new FunctionInfo[0];
eventBus.dispatchEvent(new ListFunctionInfosEvent(user, namespace, functionInfos));
return functions;
} catch (Exception e) {
diff --git a/core/src/main/java/org/apache/gravitino/listener/JobEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/JobEventDispatcher.java
index f2d40e49b7..28e3f626fd 100644
--- a/core/src/main/java/org/apache/gravitino/listener/JobEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/JobEventDispatcher.java
@@ -78,7 +78,10 @@ public class JobEventDispatcher implements JobOperationDispatcher {
try {
List<JobTemplateEntity> jobTemplates = jobOperationDispatcher.listJobTemplates(metalake);
eventBus.dispatchEvent(
- new ListJobTemplatesEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ new ListJobTemplatesEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ jobTemplates != null ? jobTemplates.size() : -1));
return jobTemplates;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -183,7 +186,11 @@ public class JobEventDispatcher implements JobOperationDispatcher {
try {
List<JobEntity> jobs = jobOperationDispatcher.listJobs(metalake, jobTemplateName);
eventBus.dispatchEvent(
- new ListJobsEvent(PrincipalUtils.getCurrentUserName(), metalake, jobTemplateName));
+ new ListJobsEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ jobTemplateName,
+ jobs != null ? jobs.size() : -1));
return jobs;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java
index 02dbce3f6c..19004dac44 100644
--- a/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/MetalakeEventDispatcher.java
@@ -79,7 +79,9 @@ public class MetalakeEventDispatcher implements MetalakeDispatcher {
eventBus.dispatchEvent(new ListMetalakePreEvent(PrincipalUtils.getCurrentUserName()));
try {
Metalake[] metalakes = dispatcher.listMetalakes();
- eventBus.dispatchEvent(new ListMetalakeEvent(PrincipalUtils.getCurrentUserName()));
+ eventBus.dispatchEvent(
+ new ListMetalakeEvent(
+ PrincipalUtils.getCurrentUserName(), metalakes != null ? metalakes.length : -1));
return metalakes;
} catch (Exception e) {
eventBus.dispatchEvent(new ListMetalakeFailureEvent(PrincipalUtils.getCurrentUserName(), e));
diff --git a/core/src/main/java/org/apache/gravitino/listener/ModelEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/ModelEventDispatcher.java
index c3cb97098e..8b9f8c6bb2 100644
--- a/core/src/main/java/org/apache/gravitino/listener/ModelEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/ModelEventDispatcher.java
@@ -193,7 +193,8 @@ public class ModelEventDispatcher implements ModelDispatcher {
eventBus.dispatchEvent(new ListModelPreEvent(user, namespace));
try {
NameIdentifier[] models = dispatcher.listModels(namespace);
- eventBus.dispatchEvent(new ListModelEvent(user, namespace));
+ eventBus.dispatchEvent(
+ new ListModelEvent(user, namespace, models != null ? models.length : -1));
return models;
} catch (Exception e) {
eventBus.dispatchEvent(new ListModelFailureEvent(user, namespace, e));
diff --git a/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java
index d439b41a5d..401cb61892 100644
--- a/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/PartitionEventDispatcher.java
@@ -132,7 +132,11 @@ public class PartitionEventDispatcher implements PartitionDispatcher {
eventBus.dispatchEvent(new ListPartitionPreEvent(PrincipalUtils.getCurrentUserName(), ident));
try {
Partition[] listPartitions = dispatcher.listPartitions(ident);
- eventBus.dispatchEvent(new ListPartitionEvent(PrincipalUtils.getCurrentUserName(), ident));
+ eventBus.dispatchEvent(
+ new ListPartitionEvent(
+ PrincipalUtils.getCurrentUserName(),
+ ident,
+ listPartitions != null ? listPartitions.length : -1));
return listPartitions;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -148,7 +152,10 @@ public class PartitionEventDispatcher implements PartitionDispatcher {
try {
String[] listPartitionNames = dispatcher.listPartitionNames(ident);
eventBus.dispatchEvent(
- new ListPartitionNamesEvent(PrincipalUtils.getCurrentUserName(), ident));
+ new ListPartitionNamesEvent(
+ PrincipalUtils.getCurrentUserName(),
+ ident,
+ listPartitionNames != null ? listPartitionNames.length : -1));
return listPartitionNames;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java
index f708f06cb2..80308dc476 100644
--- a/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/PolicyEventDispatcher.java
@@ -86,7 +86,11 @@ public class PolicyEventDispatcher implements PolicyDispatcher {
eventBus.dispatchEvent(new ListPoliciesPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
try {
String[] policyNames = dispatcher.listPolicies(metalake);
- eventBus.dispatchEvent(new ListPoliciesEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ eventBus.dispatchEvent(
+ new ListPoliciesEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ policyNames != null ? policyNames.length : -1));
return policyNames;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -102,7 +106,10 @@ public class PolicyEventDispatcher implements PolicyDispatcher {
try {
PolicyEntity[] policies = dispatcher.listPolicyInfos(metalake);
eventBus.dispatchEvent(
- new ListPolicyInfosEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ new ListPolicyInfosEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ policies != null ? policies.length : -1));
return policies;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -268,7 +275,8 @@ public class PolicyEventDispatcher implements PolicyDispatcher {
eventBus.dispatchEvent(
new ListMetadataObjectsForPolicyEvent(
PrincipalUtils.getCurrentUserName(),
- NameIdentifierUtil.ofPolicy(metalake, policyName)));
+ NameIdentifierUtil.ofPolicy(metalake, policyName),
+ metadataObjects != null ? metadataObjects.length : -1));
return metadataObjects;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -291,7 +299,10 @@ public class PolicyEventDispatcher implements PolicyDispatcher {
dispatcher.listPolicyInfosForMetadataObject(metalake, metadataObject);
eventBus.dispatchEvent(
new ListPolicyInfosForMetadataObjectEvent(
- PrincipalUtils.getCurrentUserName(), metalake, metadataObject));
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ metadataObject,
+ policies != null ? policies.length : -1));
return policies;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/SchemaEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/SchemaEventDispatcher.java
index ffbdf28c1f..179609d584 100644
--- a/core/src/main/java/org/apache/gravitino/listener/SchemaEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/SchemaEventDispatcher.java
@@ -75,7 +75,11 @@ public class SchemaEventDispatcher implements SchemaDispatcher {
eventBus.dispatchEvent(new ListSchemaPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
NameIdentifier[] nameIdentifiers = dispatcher.listSchemas(namespace);
- eventBus.dispatchEvent(new ListSchemaEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListSchemaEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ nameIdentifiers != null ? nameIdentifiers.length : -1));
return nameIdentifiers;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/StatisticEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/StatisticEventDispatcher.java
index 7be50a9498..5b3851a882 100644
--- a/core/src/main/java/org/apache/gravitino/listener/StatisticEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/StatisticEventDispatcher.java
@@ -73,7 +73,8 @@ public class StatisticEventDispatcher implements StatisticDispatcher {
try {
List<Statistic> statistics = dispatcher.listStatistics(metalake, metadataObject);
- eventBus.dispatchEvent(new ListStatisticsEvent(user, identifier));
+ eventBus.dispatchEvent(
+ new ListStatisticsEvent(user, identifier, statistics != null ? statistics.size() : -1));
return statistics;
} catch (Exception e) {
eventBus.dispatchEvent(new ListStatisticsFailureEvent(user, identifier, e));
@@ -173,7 +174,12 @@ public class StatisticEventDispatcher implements StatisticDispatcher {
try {
List<PartitionStatistics> partitionStatistics =
dispatcher.listPartitionStatistics(metalake, metadataObject, range);
- eventBus.dispatchEvent(new ListPartitionStatisticsEvent(user, identifier, range));
+ eventBus.dispatchEvent(
+ new ListPartitionStatisticsEvent(
+ user,
+ identifier,
+ range,
+ partitionStatistics != null ? partitionStatistics.size() : -1));
return partitionStatistics;
} catch (Exception e) {
eventBus.dispatchEvent(new ListPartitionStatisticsFailureEvent(user, identifier, e, range));
diff --git a/core/src/main/java/org/apache/gravitino/listener/TableEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TableEventDispatcher.java
index 5ce39f9eea..435322ec08 100644
--- a/core/src/main/java/org/apache/gravitino/listener/TableEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/TableEventDispatcher.java
@@ -83,7 +83,11 @@ public class TableEventDispatcher implements TableDispatcher {
eventBus.dispatchEvent(new ListTablePreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
NameIdentifier[] nameIdentifiers = dispatcher.listTables(namespace);
- eventBus.dispatchEvent(new ListTableEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListTableEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ nameIdentifiers != null ? nameIdentifiers.length : -1));
return nameIdentifiers;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java
index 8b06f10ddb..866af597a2 100644
--- a/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/TagEventDispatcher.java
@@ -81,7 +81,11 @@ public class TagEventDispatcher implements TagDispatcher {
eventBus.dispatchEvent(new ListTagsPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
try {
String[] tagNames = dispatcher.listTags(metalake);
- eventBus.dispatchEvent(new ListTagsEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ eventBus.dispatchEvent(
+ new ListTagsEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ tagNames != null ? tagNames.length : -1));
return tagNames;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -95,7 +99,9 @@ public class TagEventDispatcher implements TagDispatcher {
eventBus.dispatchEvent(new ListTagsInfoPreEvent(PrincipalUtils.getCurrentUserName(), metalake));
try {
Tag[] tags = dispatcher.listTagsInfo(metalake);
- eventBus.dispatchEvent(new ListTagsInfoEvent(PrincipalUtils.getCurrentUserName(), metalake));
+ eventBus.dispatchEvent(
+ new ListTagsInfoEvent(
+ PrincipalUtils.getCurrentUserName(), metalake, tags != null ? tags.length : -1));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -190,7 +196,11 @@ public class TagEventDispatcher implements TagDispatcher {
try {
MetadataObject[] metadataObjects = dispatcher.listMetadataObjectsForTag(metalake, name);
eventBus.dispatchEvent(
- new ListMetadataObjectsForTagEvent(PrincipalUtils.getCurrentUserName(), metalake, name));
+ new ListMetadataObjectsForTagEvent(
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ name,
+ metadataObjects != null ? metadataObjects.length : -1));
return metadataObjects;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -210,7 +220,10 @@ public class TagEventDispatcher implements TagDispatcher {
String[] tags = dispatcher.listTagsForMetadataObject(metalake, metadataObject);
eventBus.dispatchEvent(
new ListTagsForMetadataObjectEvent(
- PrincipalUtils.getCurrentUserName(), metalake, metadataObject));
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ metadataObject,
+ tags != null ? tags.length : -1));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
@@ -229,7 +242,10 @@ public class TagEventDispatcher implements TagDispatcher {
Tag[] tags = dispatcher.listTagsInfoForMetadataObject(metalake, metadataObject);
eventBus.dispatchEvent(
new ListTagsInfoForMetadataObjectEvent(
- PrincipalUtils.getCurrentUserName(), metalake, metadataObject));
+ PrincipalUtils.getCurrentUserName(),
+ metalake,
+ metadataObject,
+ tags != null ? tags.length : -1));
return tags;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/TopicEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/TopicEventDispatcher.java
index eeaa1869ae..50b87ed482 100644
--- a/core/src/main/java/org/apache/gravitino/listener/TopicEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/TopicEventDispatcher.java
@@ -106,7 +106,11 @@ public class TopicEventDispatcher implements TopicDispatcher {
eventBus.dispatchEvent(new ListTopicPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
NameIdentifier[] nameIdentifiers = dispatcher.listTopics(namespace);
- eventBus.dispatchEvent(new ListTopicEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListTopicEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ nameIdentifiers != null ? nameIdentifiers.length : -1));
return nameIdentifiers;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/ViewEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/ViewEventDispatcher.java
index 764e989c63..49e277cc36 100644
--- a/core/src/main/java/org/apache/gravitino/listener/ViewEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/ViewEventDispatcher.java
@@ -74,7 +74,11 @@ public class ViewEventDispatcher implements ViewDispatcher {
eventBus.dispatchEvent(new ListViewPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
NameIdentifier[] identifiers = dispatcher.listViews(namespace);
- eventBus.dispatchEvent(new ListViewEvent(PrincipalUtils.getCurrentUserName(), namespace));
+ eventBus.dispatchEvent(
+ new ListViewEvent(
+ PrincipalUtils.getCurrentUserName(),
+ namespace,
+ identifiers != null ? identifiers.length : -1));
return identifiers;
} catch (Exception e) {
eventBus.dispatchEvent(
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListCatalogEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListCatalogEvent.java
index 5e2834054c..bb05d5c499 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListCatalogEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListCatalogEvent.java
@@ -25,18 +25,34 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is triggered upon the successful list of catalogs. */
@DeveloperApi
-public final class ListCatalogEvent extends CatalogEvent {
+public final class ListCatalogEvent extends CatalogEvent implements ListEvent {
private final Namespace namespace;
+ private final int catalogCount;
/**
* Constructs an instance of {@code ListCatalogEvent}.
*
* @param user The username of the individual who initiated the catalog listing.
* @param namespace The namespace from which catalogs were listed.
+ * @param catalogCount The number of catalogs returned by the list operation.
*/
- public ListCatalogEvent(String user, Namespace namespace) {
+ public ListCatalogEvent(String user, Namespace namespace, int catalogCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.catalogCount = catalogCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListCatalogEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the catalog listing.
+ * @param namespace The namespace from which catalogs were listed.
+ * @deprecated Use {@link #ListCatalogEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListCatalogEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -48,6 +64,12 @@ public final class ListCatalogEvent extends CatalogEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return catalogCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListEvent.java
new file mode 100644
index 0000000000..c3df5895e4
--- /dev/null
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListEvent.java
@@ -0,0 +1,40 @@
+/*
+ * 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.listener.api.event;
+
+import org.apache.gravitino.annotation.DeveloperApi;
+
+/**
+ * Interface for events that represent a list operation. All list-operation success event classes
+ * implement this interface to expose the number of items returned.
+ *
+ * @since 1.3.0
+ */
+@DeveloperApi
+public interface ListEvent {
+
+ /**
+ * Returns the number of items returned by the list operation, or {@code -1} if the count was not
+ * captured.
+ *
+ * @return the result count, or {@code -1}.
+ */
+ int resultCount();
+}
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.java
index 6ec8712a7a..de42f91e49 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesEvent.java
@@ -26,22 +26,41 @@ import org.apache.gravitino.annotation.DeveloperApi;
* a filesets within a system.
*/
@DeveloperApi
-public final class ListFilesEvent extends FilesetEvent {
+public final class ListFilesEvent extends FilesetEvent implements ListEvent {
private final String subPath;
private final String locationName;
+ private final int resultCount;
/**
- * Constructs a new {@code ListFilesEvent}.
+ * Constructs a new {@code ListFilesEvent} with the result count.
*
* @param user The user who initiated the listing of files/directories under the fileset.
* @param ident The identifier of the fileset.
* @param locationName The name of the location.
- * @param subPath The subPath of the fileset
+ * @param subPath The subPath of the fileset.
+ * @param resultCount The number of files returned, or {@code -1} if not captured.
*/
- public ListFilesEvent(String user, NameIdentifier ident, String locationName, String subPath) {
+ public ListFilesEvent(
+ String user, NameIdentifier ident, String locationName, String subPath, int resultCount) {
super(user, ident);
this.locationName = locationName;
this.subPath = subPath;
+ this.resultCount = resultCount;
+ }
+
+ /**
+ * Constructs a new {@code ListFilesEvent} without a result count.
+ *
+ * @param user The user who initiated the listing of files/directories under the fileset.
+ * @param ident The identifier of the fileset.
+ * @param locationName The name of the location.
+ * @param subPath The subPath of the fileset.
+ * @deprecated Use {@link #ListFilesEvent(String, NameIdentifier, String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListFilesEvent(String user, NameIdentifier ident, String locationName, String subPath) {
+ this(user, ident, locationName, subPath, -1);
}
public String locationName() {
@@ -52,6 +71,12 @@ public final class ListFilesEvent extends FilesetEvent {
return subPath;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return resultCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesetEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesetEvent.java
index 4b4b957b44..a02a771ed7 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesetEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListFilesetEvent.java
@@ -27,18 +27,35 @@ import org.apache.gravitino.annotation.DeveloperApi;
* Represents an event that is triggered upon the successful listing of filesets within a system.
*/
@DeveloperApi
-public final class ListFilesetEvent extends FilesetEvent {
+public final class ListFilesetEvent extends FilesetEvent implements ListEvent {
private final Namespace namespace;
+ private final int filesetCount;
+
/**
* Constructs a new {@code ListFilesetEvent}.
*
* @param user The user who initiated the listing of filesets.
* @param namespace The namespace within which the filesets are listed. The namespace provides
* contextual information, identifying the scope and boundaries of the listing operation.
+ * @param filesetCount The number of filesets returned by the list operation.
*/
- public ListFilesetEvent(String user, Namespace namespace) {
+ public ListFilesetEvent(String user, Namespace namespace, int filesetCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.filesetCount = filesetCount;
+ }
+
+ /**
+ * Constructs a new {@code ListFilesetEvent} without a count.
+ *
+ * @param user The user who initiated the listing of filesets.
+ * @param namespace The namespace within which the filesets are listed.
+ * @deprecated Use {@link #ListFilesetEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListFilesetEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -50,6 +67,12 @@ public final class ListFilesetEvent extends FilesetEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return filesetCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupNamesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupNamesEvent.java
index f9b3530c3b..a8e7bc8c63 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupNamesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupNamesEvent.java
@@ -26,16 +26,40 @@ import org.apache.gravitino.utils.NameIdentifierUtil;
* Represents an event triggered after successfully listing group names from a specific metalake.
*/
@DeveloperApi
-public class ListGroupNamesEvent extends GroupEvent {
+public class ListGroupNamesEvent extends GroupEvent implements ListEvent {
+
+ private final int groupNameCount;
/**
- * Constructs a new {@link ListGroupNamesEvent} with the specified initiator and metalake name.
+ * Constructs a new {@link ListGroupNamesEvent} with the specified initiator, metalake name and
+ * count.
*
* @param initiator the user who initiated the list-group-names request.
* @param metalake the name of the metalake from which group names are listed.
+ * @param groupNameCount the number of group names returned by the list operation.
*/
- public ListGroupNamesEvent(String initiator, String metalake) {
+ public ListGroupNamesEvent(String initiator, String metalake, int groupNameCount) {
super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ this.groupNameCount = groupNameCount;
+ }
+
+ /**
+ * Constructs a new {@link ListGroupNamesEvent} without a count.
+ *
+ * @param initiator the user who initiated the list-group-names request.
+ * @param metalake the name of the metalake from which group names are listed.
+ * @deprecated Use {@link #ListGroupNamesEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListGroupNamesEvent(String initiator, String metalake) {
+ this(initiator, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return groupNameCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupsEvent.java
index 73ead32d8f..b0ae88cb2f 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupsEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListGroupsEvent.java
@@ -24,16 +24,39 @@ import org.apache.gravitino.utils.NameIdentifierUtil;
/** Represents an event triggered after successfully listing groups from a specific metalake. */
@DeveloperApi
-public class ListGroupsEvent extends GroupEvent {
+public class ListGroupsEvent extends GroupEvent implements ListEvent {
+
+ private final int groupCount;
/**
- * Constructs a new {@link ListGroupsEvent} with the specified initiator and metalake name.
+ * Constructs a new {@link ListGroupsEvent} with the specified initiator, metalake name and count.
*
* @param initiator the user who initiated the list-groups request.
* @param metalake the name of the metalake from which the groups were listed.
+ * @param groupCount the number of groups returned by the list operation.
*/
- public ListGroupsEvent(String initiator, String metalake) {
+ public ListGroupsEvent(String initiator, String metalake, int groupCount) {
super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ this.groupCount = groupCount;
+ }
+
+ /**
+ * Constructs a new {@link ListGroupsEvent} without a count.
+ *
+ * @param initiator the user who initiated the list-groups request.
+ * @param metalake the name of the metalake from which the groups were listed.
+ * @deprecated Use {@link #ListGroupsEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListGroupsEvent(String initiator, String metalake) {
+ this(initiator, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return groupCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetadataObjectsForTagEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetadataObjectsForTagEvent.java
index 0e8a7e072e..7abbdf78be 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetadataObjectsForTagEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetadataObjectsForTagEvent.java
@@ -24,16 +24,42 @@ import org.apache.gravitino.utils.NameIdentifierUtil;
/** Represents an event that is triggered upon successfully listing metadata objects for a tag. */
@DeveloperApi
-public final class ListMetadataObjectsForTagEvent extends TagEvent {
+public final class ListMetadataObjectsForTagEvent extends TagEvent implements ListEvent {
+
+ private final int metadataObjectCount;
+
/**
* Constructs an instance of {@code ListMetadataObjectsForTagEvent}.
*
* @param user The username of the individual who initiated the metadata objects listing.
* @param metalake The metalake from which metadata objects were listed.
* @param tagName The name of the tag for which metadata objects were listed.
+ * @param metadataObjectCount The number of metadata objects returned by the list operation.
*/
- public ListMetadataObjectsForTagEvent(String user, String metalake, String tagName) {
+ public ListMetadataObjectsForTagEvent(
+ String user, String metalake, String tagName, int metadataObjectCount) {
super(user, NameIdentifierUtil.ofTag(metalake, tagName));
+ this.metadataObjectCount = metadataObjectCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListMetadataObjectsForTagEvent} without a result count.
+ *
+ * @param user The username of the individual who initiated the metadata objects listing.
+ * @param metalake The metalake from which metadata objects were listed.
+ * @param tagName The name of the tag for which metadata objects were listed.
+ * @deprecated Use {@link #ListMetadataObjectsForTagEvent(String, String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListMetadataObjectsForTagEvent(String user, String metalake, String tagName) {
+ this(user, metalake, tagName, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return metadataObjectCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakeEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakeEvent.java
index 6e0a3b1a22..20a4ad9cfd 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakeEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListMetalakeEvent.java
@@ -23,14 +23,37 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is triggered upon the successful list of metalakes. */
@DeveloperApi
-public final class ListMetalakeEvent extends MetalakeEvent {
+public final class ListMetalakeEvent extends MetalakeEvent implements ListEvent {
+
+ private final int metalakeCount;
+
/**
* Constructs an instance of {@code ListMetalakeEvent}.
*
* @param user The username of the individual who initiated the metalake listing.
+ * @param metalakeCount The number of metalakes returned by the list operation.
*/
- public ListMetalakeEvent(String user) {
+ public ListMetalakeEvent(String user, int metalakeCount) {
super(user, null);
+ this.metalakeCount = metalakeCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListMetalakeEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the metalake listing.
+ * @deprecated Use {@link #ListMetalakeEvent(String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListMetalakeEvent(String user) {
+ this(user, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return metalakeCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java
index 1a43fd892c..733a1f0e98 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelEvent.java
@@ -25,18 +25,34 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is generated after a model listing operation. */
@DeveloperApi
-public class ListModelEvent extends ModelEvent {
+public class ListModelEvent extends ModelEvent implements ListEvent {
private final Namespace namespace;
+ private final int modelCount;
/**
- * Constructs an instance of {@code ListModelEvent}, with the specified user and namespace.
+ * Constructs an instance of {@code ListModelEvent}, with the specified user, namespace and count.
*
* @param user The username of the individual who initiated the model listing.
* @param namespace The namespace from which models were listed.
+ * @param modelCount The number of models returned by the list operation.
*/
- public ListModelEvent(String user, Namespace namespace) {
+ public ListModelEvent(String user, Namespace namespace, int modelCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.modelCount = modelCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListModelEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the model listing.
+ * @param namespace The namespace from which models were listed.
+ * @deprecated Use {@link #ListModelEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListModelEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -48,6 +64,12 @@ public class ListModelEvent extends ModelEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return modelCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionInfosEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionInfosEvent.java
index ae44ce15ad..36ebcc29b1 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionInfosEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionInfosEvent.java
@@ -23,7 +23,7 @@ import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.listener.api.info.ModelVersionInfo;
/** Represents an event that is generated after a model version listing operation. */
-public class ListModelVersionInfosEvent extends ModelEvent {
+public class ListModelVersionInfosEvent extends ModelEvent implements ListEvent {
private final ModelVersionInfo[] versions;
/**
@@ -44,12 +44,18 @@ public class ListModelVersionInfosEvent extends ModelEvent {
/**
* Returns the versions of the model in this list operation.
*
- * @return The versions of the model.
+ * @return The versions of the model, or {@code null} if the result was not captured.
*/
public ModelVersionInfo[] versions() {
return versions;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return versions != null ? versions.length : -1;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.java
index d6aa2be3c1..e902d69958 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListModelVersionsEvent.java
@@ -22,7 +22,7 @@ package org.apache.gravitino.listener.api.event;
import org.apache.gravitino.NameIdentifier;
/** Represents an event that is generated after a model version listing operation. */
-public class ListModelVersionsEvent extends ModelEvent {
+public class ListModelVersionsEvent extends ModelEvent implements ListEvent {
private final int[] versions;
/**
@@ -42,12 +42,18 @@ public class ListModelVersionsEvent extends ModelEvent {
/**
* Returns the versions of the model in this list operation.
*
- * @return The versions of the model.
+ * @return The versions of the model, or {@code null} if the result was not captured.
*/
public int[] versions() {
return versions;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return versions != null ? versions.length : -1;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionEvent.java
index 47442b59f0..a947f6b5ee 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionEvent.java
@@ -24,15 +24,39 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is triggered upon the successful list of partitions. */
@DeveloperApi
-public final class ListPartitionEvent extends PartitionEvent {
+public final class ListPartitionEvent extends PartitionEvent implements ListEvent {
+
+ private final int partitionCount;
+
/**
* Constructs an instance of {@code ListPartitionEvent}.
*
* @param user The username of the individual who initiated the partition listing.
* @param ident The identifier from which partitions were listed.
+ * @param partitionCount The number of partitions returned by the list operation.
*/
- public ListPartitionEvent(String user, NameIdentifier ident) {
+ public ListPartitionEvent(String user, NameIdentifier ident, int partitionCount) {
super(user, ident);
+ this.partitionCount = partitionCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListPartitionEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the partition listing.
+ * @param ident The identifier from which partitions were listed.
+ * @deprecated Use {@link #ListPartitionEvent(String, NameIdentifier, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListPartitionEvent(String user, NameIdentifier ident) {
+ this(user, ident, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return partitionCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesEvent.java
index d1ae76ee21..bfde3c2b03 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListPartitionNamesEvent.java
@@ -22,17 +22,41 @@ package org.apache.gravitino.listener.api.event;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
-/** Represents an event that is triggered upon the successful list of partitions. */
+/** Represents an event that is triggered upon the successful list of partition names. */
@DeveloperApi
-public final class ListPartitionNamesEvent extends PartitionEvent {
+public final class ListPartitionNamesEvent extends PartitionEvent implements ListEvent {
+
+ private final int partitionNameCount;
+
/**
* Constructs an instance of {@code ListPartitionNamesEvent}.
*
* @param user The username of the individual who initiated the partition listing.
* @param ident The identifier from which partitions were listed.
+ * @param partitionNameCount The number of partition names returned by the list operation.
*/
- public ListPartitionNamesEvent(String user, NameIdentifier ident) {
+ public ListPartitionNamesEvent(String user, NameIdentifier ident, int partitionNameCount) {
super(user, ident);
+ this.partitionNameCount = partitionNameCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListPartitionNamesEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the partition listing.
+ * @param ident The identifier from which partitions were listed.
+ * @deprecated Use {@link #ListPartitionNamesEvent(String, NameIdentifier, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListPartitionNamesEvent(String user, NameIdentifier ident) {
+ this(user, ident, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return partitionNameCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListRoleNamesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListRoleNamesEvent.java
index ac0df1500d..3829f395e3 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListRoleNamesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListRoleNamesEvent.java
@@ -26,30 +26,64 @@ import org.apache.gravitino.utils.NameIdentifierUtil;
/** Represents an event triggered after role names are listed. */
@DeveloperApi
-public class ListRoleNamesEvent extends RoleEvent {
+public class ListRoleNamesEvent extends RoleEvent implements ListEvent {
private final Optional<MetadataObject> object;
+ private final int roleCount;
+
+ /**
+ * Constructs a new {@code ListRoleNamesEvent} instance with the specified metadata object and
+ * count.
+ *
+ * @param initiator the user who triggered the event.
+ * @param metalake the metalake name where the roles are listed.
+ * @param object the {@code MetadataObject} related to the role names.
+ * @param roleCount the number of role names returned by the list operation.
+ */
+ public ListRoleNamesEvent(
+ String initiator, String metalake, MetadataObject object, int roleCount) {
+ super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ this.object = Optional.ofNullable(object);
+ this.roleCount = roleCount;
+ }
/**
* Constructs a new {@code ListRoleNamesEvent} instance without a related metadata object.
*
* @param initiator the user who triggered the event.
* @param metalake the metalake name where the roles are listed.
+ * @param roleCount the number of role names returned by the list operation.
*/
+ public ListRoleNamesEvent(String initiator, String metalake, int roleCount) {
+ this(initiator, metalake, null, roleCount);
+ }
+
+ /**
+ * Constructs a new {@code ListRoleNamesEvent} instance without a related metadata object or
+ * count.
+ *
+ * @param initiator the user who triggered the event.
+ * @param metalake the metalake name where the roles are listed.
+ * @deprecated Use {@link #ListRoleNamesEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
public ListRoleNamesEvent(String initiator, String metalake) {
- this(initiator, metalake, null);
+ this(initiator, metalake, null, -1);
}
/**
- * Constructs a new {@code ListRoleNamesEvent} instance with the specified metadata object.
+ * Constructs a new {@code ListRoleNamesEvent} instance with the specified metadata object but no
+ * count.
*
* @param initiator the user who triggered the event.
* @param metalake the metalake name where the roles are listed.
* @param object the {@code MetadataObject} related to the role names.
+ * @deprecated Use {@link #ListRoleNamesEvent(String, String, MetadataObject, int)} instead.
*/
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
public ListRoleNamesEvent(String initiator, String metalake, MetadataObject object) {
- super(initiator, NameIdentifierUtil.ofMetalake(metalake));
-
- this.object = Optional.ofNullable(object);
+ this(initiator, metalake, object, -1);
}
/**
@@ -62,6 +96,12 @@ public class ListRoleNamesEvent extends RoleEvent {
return object;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return roleCount;
+ }
+
/**
* Returns the operation type of this event.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListSchemaEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListSchemaEvent.java
index 25123c9c3f..07cd21501f 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListSchemaEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListSchemaEvent.java
@@ -25,12 +25,34 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is triggered upon the successful list of schemas. */
@DeveloperApi
-public final class ListSchemaEvent extends SchemaEvent {
+public final class ListSchemaEvent extends SchemaEvent implements ListEvent {
private final Namespace namespace;
+ private final int schemaCount;
- public ListSchemaEvent(String user, Namespace namespace) {
+ /**
+ * Constructs an instance of {@code ListSchemaEvent}.
+ *
+ * @param user The username of the individual who initiated the schema listing.
+ * @param namespace The namespace from which schemas were listed.
+ * @param schemaCount The number of schemas returned by the list operation.
+ */
+ public ListSchemaEvent(String user, Namespace namespace, int schemaCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.schemaCount = schemaCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListSchemaEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the schema listing.
+ * @param namespace The namespace from which schemas were listed.
+ * @deprecated Use {@link #ListSchemaEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListSchemaEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -42,6 +64,12 @@ public final class ListSchemaEvent extends SchemaEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return schemaCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTableEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTableEvent.java
index 45c5a8d892..bb1a129464 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTableEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTableEvent.java
@@ -26,24 +26,38 @@ import org.apache.gravitino.annotation.DeveloperApi;
/**
* Represents an event that is triggered upon the successful list of tables within a namespace.
*
- * <p>To optimize memory usage and avoid the potential overhead associated with storing a large
- * number of tables directly within the ListTableEvent, the actual tables listed are not maintained
- * in this event. This design decision helps in managing resource efficiency, especially in
- * environments with extensive table listings.
+ * <p>Only the result count is stored rather than the full list of identifiers to avoid excessive
+ * memory usage in environments with large table listings.
*/
@DeveloperApi
-public final class ListTableEvent extends TableEvent {
+public final class ListTableEvent extends TableEvent implements ListEvent {
private final Namespace namespace;
+ private final int tableCount;
/**
* Constructs an instance of {@code ListTableEvent}.
*
* @param user The username of the individual who initiated the table listing.
* @param namespace The namespace from which tables were listed.
+ * @param tableCount The number of tables returned by the list operation.
*/
- public ListTableEvent(String user, Namespace namespace) {
+ public ListTableEvent(String user, Namespace namespace, int tableCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.tableCount = tableCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListTableEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the table listing.
+ * @param namespace The namespace from which tables were listed.
+ * @deprecated Use {@link #ListTableEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListTableEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -55,6 +69,12 @@ public final class ListTableEvent extends TableEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return tableCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsEvent.java
index dd19f00fe3..0dc8febc2e 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsEvent.java
@@ -24,16 +24,39 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is triggered upon the successful listing of tags. */
@DeveloperApi
-public final class ListTagsEvent extends TagEvent {
+public final class ListTagsEvent extends TagEvent implements ListEvent {
+
+ private final int tagCount;
/**
- * Constructs an instance of {@code ListTagEvent}.
+ * Constructs an instance of {@code ListTagsEvent}.
*
* @param user The username of the individual who initiated the tag listing.
- * @param metalake The namespace from which tags were listed.
+ * @param metalake The metalake from which tags were listed.
+ * @param tagCount The number of tags returned by the list operation.
*/
- public ListTagsEvent(String user, String metalake) {
+ public ListTagsEvent(String user, String metalake, int tagCount) {
super(user, NameIdentifier.of(metalake));
+ this.tagCount = tagCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListTagsEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the tag listing.
+ * @param metalake The metalake from which tags were listed.
+ * @deprecated Use {@link #ListTagsEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListTagsEvent(String user, String metalake) {
+ this(user, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return tagCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsForMetadataObjectEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsForMetadataObjectEvent.java
index 598c71cb08..8908025e44 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsForMetadataObjectEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsForMetadataObjectEvent.java
@@ -25,7 +25,9 @@ import org.apache.gravitino.utils.MetadataObjectUtil;
/** Represents an event that is triggered upon successfully listing tags for a metadata object. */
@DeveloperApi
-public final class ListTagsForMetadataObjectEvent extends TagEvent {
+public final class ListTagsForMetadataObjectEvent extends TagEvent implements ListEvent {
+
+ private final int tagCount;
/**
* Constructs an instance of {@code ListTagsForMetadataObjectEvent}.
@@ -33,10 +35,34 @@ public final class ListTagsForMetadataObjectEvent extends TagEvent {
* @param user The username of the individual who initiated the tag listing.
* @param metalake The metalake from which tags were listed.
* @param metadataObject The metadata object for which tags were listed.
+ * @param tagCount The number of tags returned by the list operation.
*/
public ListTagsForMetadataObjectEvent(
- String user, String metalake, MetadataObject metadataObject) {
+ String user, String metalake, MetadataObject metadataObject, int tagCount) {
super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.tagCount = tagCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListTagsForMetadataObjectEvent} without a result count.
+ *
+ * @param user The username of the individual who initiated the tag listing.
+ * @param metalake The metalake from which tags were listed.
+ * @param metadataObject The metadata object for which tags were listed.
+ * @deprecated Use {@link #ListTagsForMetadataObjectEvent(String, String, MetadataObject, int)}
+ * instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListTagsForMetadataObjectEvent(
+ String user, String metalake, MetadataObject metadataObject) {
+ this(user, metalake, metadataObject, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return tagCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoEvent.java
index 13126671f6..6fdaac0ac8 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoEvent.java
@@ -22,18 +22,41 @@ package org.apache.gravitino.listener.api.event;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
-/** Represents an event that is triggered upon the successful listing of tags. */
+/** Represents an event that is triggered upon the successful listing of tag info objects. */
@DeveloperApi
-public final class ListTagsInfoEvent extends TagEvent {
+public final class ListTagsInfoEvent extends TagEvent implements ListEvent {
+
+ private final int tagCount;
/**
- * Constructs an instance of {@code ListTagsEvent}.
+ * Constructs an instance of {@code ListTagsInfoEvent}.
*
* @param user The username of the individual who initiated the tag listing.
- * @param metalake The namespace from which tags were listed.
+ * @param metalake The metalake from which tags were listed.
+ * @param tagCount The number of tags returned by the list operation.
*/
- public ListTagsInfoEvent(String user, String metalake) {
+ public ListTagsInfoEvent(String user, String metalake, int tagCount) {
super(user, NameIdentifier.of(metalake));
+ this.tagCount = tagCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListTagsInfoEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the tag listing.
+ * @param metalake The metalake from which tags were listed.
+ * @deprecated Use {@link #ListTagsInfoEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListTagsInfoEvent(String user, String metalake) {
+ this(user, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return tagCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoForMetadataObjectEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoForMetadataObjectEvent.java
index e41244bd1f..122f0bb035 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoForMetadataObjectEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTagsInfoForMetadataObjectEvent.java
@@ -28,7 +28,9 @@ import org.apache.gravitino.utils.MetadataObjectUtil;
* metadata object.
*/
@DeveloperApi
-public final class ListTagsInfoForMetadataObjectEvent extends TagEvent {
+public final class ListTagsInfoForMetadataObjectEvent extends TagEvent implements ListEvent {
+
+ private final int tagCount;
/**
* Constructs an instance of {@code ListTagsInfoForMetadataObjectEvent}.
@@ -36,10 +38,34 @@ public final class ListTagsInfoForMetadataObjectEvent extends TagEvent {
* @param user The username of the individual who initiated the tag information listing.
* @param metalake The metalake from which tag information was listed.
* @param metadataObject The metadata object for which tag information was listed.
+ * @param tagCount The number of tags returned by the list operation.
*/
public ListTagsInfoForMetadataObjectEvent(
- String user, String metalake, MetadataObject metadataObject) {
+ String user, String metalake, MetadataObject metadataObject, int tagCount) {
super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
+ this.tagCount = tagCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListTagsInfoForMetadataObjectEvent} without a result count.
+ *
+ * @param user The username of the individual who initiated the tag information listing.
+ * @param metalake The metalake from which tag information was listed.
+ * @param metadataObject The metadata object for which tag information was listed.
+ * @deprecated Use {@link #ListTagsInfoForMetadataObjectEvent(String, String, MetadataObject,
+ * int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListTagsInfoForMetadataObjectEvent(
+ String user, String metalake, MetadataObject metadataObject) {
+ this(user, metalake, metadataObject, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return tagCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicEvent.java
index db032cf48e..12bfb13bad 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListTopicEvent.java
@@ -25,18 +25,34 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event that is triggered upon the successful list of topics within a namespace. */
@DeveloperApi
-public final class ListTopicEvent extends TopicEvent {
+public final class ListTopicEvent extends TopicEvent implements ListEvent {
private final Namespace namespace;
+ private final int topicCount;
/**
* Constructs an instance of {@code ListTopicEvent}.
*
* @param user The username of the individual who initiated the topic listing.
* @param namespace The namespace from which topics were listed.
+ * @param topicCount The number of topics returned by the list operation.
*/
- public ListTopicEvent(String user, Namespace namespace) {
+ public ListTopicEvent(String user, Namespace namespace, int topicCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.topicCount = topicCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListTopicEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the topic listing.
+ * @param namespace The namespace from which topics were listed.
+ * @deprecated Use {@link #ListTopicEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListTopicEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -48,6 +64,12 @@ public final class ListTopicEvent extends TopicEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return topicCount;
+ }
+
/**
* Returns the type of operation.
*
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListUserNamesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListUserNamesEvent.java
index 7f6cd33afb..6fff201320 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListUserNamesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListUserNamesEvent.java
@@ -24,16 +24,40 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event triggered after successfully listing usernames from a specific metalake. */
@DeveloperApi
-public class ListUserNamesEvent extends UserEvent {
+public class ListUserNamesEvent extends UserEvent implements ListEvent {
+
+ private final int userNameCount;
+
/**
- * Constructs a new {@link ListUserNamesEvent} instance with the specified initiator and metalake
- * name.
+ * Constructs a new {@link ListUserNamesEvent} instance with the specified initiator, metalake
+ * name and count.
*
* @param initiator the user who initiated the request to list usernames.
* @param metalake the name of the metalake from which the usernames are listed.
+ * @param userNameCount the number of usernames returned by the list operation.
*/
- public ListUserNamesEvent(String initiator, String metalake) {
+ public ListUserNamesEvent(String initiator, String metalake, int userNameCount) {
super(initiator, NameIdentifier.of(metalake));
+ this.userNameCount = userNameCount;
+ }
+
+ /**
+ * Constructs a new {@link ListUserNamesEvent} instance without a count.
+ *
+ * @param initiator the user who initiated the request to list usernames.
+ * @param metalake the name of the metalake from which the usernames are listed.
+ * @deprecated Use {@link #ListUserNamesEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListUserNamesEvent(String initiator, String metalake) {
+ this(initiator, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return userNameCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/ListUsersEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/ListUsersEvent.java
index 2a5b7ed2eb..7b102a55ff 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/ListUsersEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/ListUsersEvent.java
@@ -24,17 +24,40 @@ import org.apache.gravitino.annotation.DeveloperApi;
/** Represents an event triggered after successfully listing users from a specific metalake. */
@DeveloperApi
-public class ListUsersEvent extends UserEvent {
+public class ListUsersEvent extends UserEvent implements ListEvent {
+
+ private final int userCount;
/**
- * Constructs a new {@link ListUsersEvent} instance with the specified initiator and metalake
- * name.
+ * Constructs a new {@link ListUsersEvent} instance with the specified initiator, metalake name
+ * and user count.
*
* @param initiator the user who initiated the request to list users.
* @param metalake the name of the metalake from which the users are listed.
+ * @param userCount the number of users returned by the list operation.
*/
- public ListUsersEvent(String initiator, String metalake) {
+ public ListUsersEvent(String initiator, String metalake, int userCount) {
super(initiator, NameIdentifier.of(metalake));
+ this.userCount = userCount;
+ }
+
+ /**
+ * Constructs a new {@link ListUsersEvent} instance without a count.
+ *
+ * @param initiator the user who initiated the request to list users.
+ * @param metalake the name of the metalake from which the users are listed.
+ * @deprecated Use {@link #ListUsersEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListUsersEvent(String initiator, String metalake) {
+ this(initiator, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return userCount;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionEvent.java
index 5d2853bcef..778f162972 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionEvent.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.listener.api.event.function;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
/**
@@ -29,18 +30,34 @@ import org.apache.gravitino.listener.api.event.OperationType;
* namespace.
*/
@DeveloperApi
-public final class ListFunctionEvent extends FunctionEvent {
+public final class ListFunctionEvent extends FunctionEvent implements ListEvent {
private final Namespace namespace;
+ private final int functionCount;
/**
* Constructs an instance of {@code ListFunctionEvent}.
*
* @param user The username of the individual who initiated the function listing.
* @param namespace The namespace from which functions were listed.
+ * @param functionCount The number of functions returned by the list operation.
*/
- public ListFunctionEvent(String user, Namespace namespace) {
+ public ListFunctionEvent(String user, Namespace namespace, int functionCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.functionCount = functionCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListFunctionEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the function listing.
+ * @param namespace The namespace from which functions were listed.
+ * @deprecated Use {@link #ListFunctionEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListFunctionEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
/**
@@ -52,6 +69,12 @@ public final class ListFunctionEvent extends FunctionEvent {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return functionCount;
+ }
+
@Override
public OperationType operationType() {
return OperationType.LIST_FUNCTION;
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionInfosEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionInfosEvent.java
index be5d30a21f..65df1ed7de 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionInfosEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/function/ListFunctionInfosEvent.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.listener.api.event.function;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
import org.apache.gravitino.listener.api.info.FunctionInfo;
@@ -30,7 +31,7 @@ import org.apache.gravitino.listener.api.info.FunctionInfo;
* namespace.
*/
@DeveloperApi
-public final class ListFunctionInfosEvent extends FunctionEvent {
+public final class ListFunctionInfosEvent extends FunctionEvent implements ListEvent {
private final Namespace namespace;
private final FunctionInfo[] functionInfos;
@@ -59,12 +60,19 @@ public final class ListFunctionInfosEvent extends FunctionEvent {
/**
* Provides the function infos associated with this event.
*
- * @return An array of {@link FunctionInfo} instances that were listed.
+ * @return An array of {@link FunctionInfo} instances that were listed, or {@code null} if the
+ * result was not captured.
*/
public FunctionInfo[] functionInfos() {
return functionInfos;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return functionInfos != null ? functionInfos.length : -1;
+ }
+
@Override
public OperationType operationType() {
return OperationType.LIST_FUNCTION_INFOS;
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobTemplatesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobTemplatesEvent.java
index 9495311960..82415ff50d 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobTemplatesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobTemplatesEvent.java
@@ -21,20 +21,44 @@ package org.apache.gravitino.listener.api.event.job;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
/** Represents an event that is triggered upon the successful listing of job templates. */
@DeveloperApi
-public final class ListJobTemplatesEvent extends JobTemplateEvent {
+public final class ListJobTemplatesEvent extends JobTemplateEvent implements ListEvent {
+
+ private final int count;
/**
* Constructs an instance of {@code ListJobTemplatesEvent}.
*
* @param user The username of the individual who initiated the job template listing.
* @param metalake The namespace from which job templates were listed.
+ * @param count The number of job templates returned by the list operation.
*/
- public ListJobTemplatesEvent(String user, String metalake) {
+ public ListJobTemplatesEvent(String user, String metalake, int count) {
super(user, NameIdentifier.of(metalake));
+ this.count = count;
+ }
+
+ /**
+ * Constructs an instance of {@code ListJobTemplatesEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the job template listing.
+ * @param metalake The namespace from which job templates were listed.
+ * @deprecated Use {@link #ListJobTemplatesEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListJobTemplatesEvent(String user, String metalake) {
+ this(user, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobsEvent.java
index 625987a678..a3727be290 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobsEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/job/ListJobsEvent.java
@@ -22,13 +22,15 @@ package org.apache.gravitino.listener.api.event.job;
import java.util.Optional;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
/** Represents an event that is triggered upon the successful listing of jobs. */
@DeveloperApi
-public final class ListJobsEvent extends JobEvent {
+public final class ListJobsEvent extends JobEvent implements ListEvent {
private final Optional<String> jobTemplateName;
+ private final int count;
/**
* Constructs an instance of {@code ListJobsEvent}.
@@ -36,10 +38,32 @@ public final class ListJobsEvent extends JobEvent {
* @param user The username of the individual who initiated the job listing.
* @param metalake The namespace from which jobs were listed.
* @param jobTemplateName An optional job template name used to filter the listed jobs.
+ * @param count The number of jobs returned by the list operation.
*/
- public ListJobsEvent(String user, String metalake, Optional<String> jobTemplateName) {
+ public ListJobsEvent(String user, String metalake, Optional<String> jobTemplateName, int count) {
super(user, NameIdentifier.of(metalake));
this.jobTemplateName = jobTemplateName;
+ this.count = count;
+ }
+
+ /**
+ * Constructs an instance of {@code ListJobsEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the job listing.
+ * @param metalake The namespace from which jobs were listed.
+ * @param jobTemplateName An optional job template name used to filter the listed jobs.
+ * @deprecated Use {@link #ListJobsEvent(String, String, Optional, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListJobsEvent(String user, String metalake, Optional<String> jobTemplateName) {
+ this(user, metalake, jobTemplateName, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java
index cf8f14d5dd..087f756566 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListMetadataObjectsForPolicyEvent.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.listener.api.event.policy;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
/**
@@ -28,15 +29,40 @@ import org.apache.gravitino.listener.api.event.OperationType;
* a policy.
*/
@DeveloperApi
-public final class ListMetadataObjectsForPolicyEvent extends PolicyEvent {
+public final class ListMetadataObjectsForPolicyEvent extends PolicyEvent implements ListEvent {
+
+ private final int count;
+
/**
* Constructs an instance of {@code ListMetadataObjectsForPolicyEvent}.
*
* @param user The username of the individual who initiated the list metadata objects operation.
* @param identifier The identifier of the policy.
+ * @param count The number of metadata objects returned by the list operation.
*/
- public ListMetadataObjectsForPolicyEvent(String user, NameIdentifier identifier) {
+ public ListMetadataObjectsForPolicyEvent(String user, NameIdentifier identifier, int count) {
super(user, identifier);
+ this.count = count;
+ }
+
+ /**
+ * Constructs an instance of {@code ListMetadataObjectsForPolicyEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the list metadata objects operation.
+ * @param identifier The identifier of the policy.
+ * @deprecated Use {@link #ListMetadataObjectsForPolicyEvent(String, NameIdentifier, int)}
+ * instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListMetadataObjectsForPolicyEvent(String user, NameIdentifier identifier) {
+ this(user, identifier, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java
index 667ce0d37f..3bad462534 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPoliciesEvent.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.listener.api.event.policy;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
import org.apache.gravitino.utils.NameIdentifierUtil;
@@ -28,16 +29,39 @@ import org.apache.gravitino.utils.NameIdentifierUtil;
* metalake.
*/
@DeveloperApi
-public class ListPoliciesEvent extends PolicyEvent {
+public class ListPoliciesEvent extends PolicyEvent implements ListEvent {
+
+ private final int count;
/**
* Constructs an instance of {@code ListPoliciesEvent}.
*
* @param initiator The username of the individual who initiated the list-policies request.
* @param metalake The name of the metalake from which the policies were listed.
+ * @param count The number of policies returned by the list operation.
*/
- public ListPoliciesEvent(String initiator, String metalake) {
+ public ListPoliciesEvent(String initiator, String metalake, int count) {
super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ this.count = count;
+ }
+
+ /**
+ * Constructs an instance of {@code ListPoliciesEvent} without a count.
+ *
+ * @param initiator The username of the individual who initiated the list-policies request.
+ * @param metalake The name of the metalake from which the policies were listed.
+ * @deprecated Use {@link #ListPoliciesEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListPoliciesEvent(String initiator, String metalake) {
+ this(initiator, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java
index 8e201f2457..67e780929e 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosEvent.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.listener.api.event.policy;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
import org.apache.gravitino.utils.NameIdentifierUtil;
@@ -28,16 +29,39 @@ import org.apache.gravitino.utils.NameIdentifierUtil;
* metalake.
*/
@DeveloperApi
-public class ListPolicyInfosEvent extends PolicyEvent {
+public class ListPolicyInfosEvent extends PolicyEvent implements ListEvent {
+
+ private final int count;
/**
* Constructs an instance of {@code ListPolicyInfosEvent}.
*
* @param initiator The username of the individual who initiated the list-policy-infos request.
* @param metalake The name of the metalake from which the policy infos were listed.
+ * @param count The number of policy infos returned by the list operation.
*/
- public ListPolicyInfosEvent(String initiator, String metalake) {
+ public ListPolicyInfosEvent(String initiator, String metalake, int count) {
super(initiator, NameIdentifierUtil.ofMetalake(metalake));
+ this.count = count;
+ }
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosEvent} without a count.
+ *
+ * @param initiator The username of the individual who initiated the list-policy-infos request.
+ * @param metalake The name of the metalake from which the policy infos were listed.
+ * @deprecated Use {@link #ListPolicyInfosEvent(String, String, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListPolicyInfosEvent(String initiator, String metalake) {
+ this(initiator, metalake, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java
index 5b0d9b7e1d..b7a9fd1954 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/policy/ListPolicyInfosForMetadataObjectEvent.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.listener.api.event.policy;
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
import org.apache.gravitino.utils.MetadataObjectUtil;
@@ -29,8 +30,9 @@ import org.apache.gravitino.utils.MetadataObjectUtil;
* metadata object.
*/
@DeveloperApi
-public final class ListPolicyInfosForMetadataObjectEvent extends PolicyEvent {
+public final class ListPolicyInfosForMetadataObjectEvent extends PolicyEvent implements ListEvent {
private final MetadataObject metadataObject;
+ private final int count;
/**
* Constructs an instance of {@code ListPolicyInfosForMetadataObjectEvent}.
@@ -38,11 +40,35 @@ public final class ListPolicyInfosForMetadataObjectEvent extends PolicyEvent {
* @param user The username of the individual who initiated the list policy infos operation.
* @param metalake The metalake from which the policy infos were listed.
* @param metadataObject The metadata object for which policy infos were listed.
+ * @param count The number of policy infos returned by the list operation.
*/
public ListPolicyInfosForMetadataObjectEvent(
- String user, String metalake, MetadataObject metadataObject) {
+ String user, String metalake, MetadataObject metadataObject, int count) {
super(user, MetadataObjectUtil.toEntityIdent(metalake, metadataObject));
this.metadataObject = metadataObject;
+ this.count = count;
+ }
+
+ /**
+ * Constructs an instance of {@code ListPolicyInfosForMetadataObjectEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the list policy infos operation.
+ * @param metalake The metalake from which the policy infos were listed.
+ * @param metadataObject The metadata object for which policy infos were listed.
+ * @deprecated Use {@link #ListPolicyInfosForMetadataObjectEvent(String, String, MetadataObject,
+ * int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListPolicyInfosForMetadataObjectEvent(
+ String user, String metalake, MetadataObject metadataObject) {
+ this(user, metalake, metadataObject, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListPartitionStatisticsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListPartitionStatisticsEvent.java
index 2bb24c8a2a..3daa026a1a 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListPartitionStatisticsEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListPartitionStatisticsEvent.java
@@ -20,13 +20,15 @@ package org.apache.gravitino.listener.api.event.stats;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
import org.apache.gravitino.stats.PartitionRange;
/** Event fired when listing partition statistics. */
@DeveloperApi
-public class ListPartitionStatisticsEvent extends StatisticsEvent {
+public class ListPartitionStatisticsEvent extends StatisticsEvent implements ListEvent {
private final PartitionRange partitionRange;
+ private final int count;
/**
* Creates a new ListPartitionStatisticsEvent.
@@ -34,11 +36,35 @@ public class ListPartitionStatisticsEvent extends StatisticsEvent {
* @param user the user performing the operation
* @param identifier the identifier of the metadata object
* @param partitionRange the partition range for which statistics are being listed
+ * @param count the number of partition statistics returned by the list operation
*/
public ListPartitionStatisticsEvent(
- String user, NameIdentifier identifier, PartitionRange partitionRange) {
+ String user, NameIdentifier identifier, PartitionRange partitionRange, int count) {
super(user, identifier);
this.partitionRange = partitionRange;
+ this.count = count;
+ }
+
+ /**
+ * Creates a new ListPartitionStatisticsEvent without a count.
+ *
+ * @param user the user performing the operation
+ * @param identifier the identifier of the metadata object
+ * @param partitionRange the partition range for which statistics are being listed
+ * @deprecated Use {@link #ListPartitionStatisticsEvent(String, NameIdentifier, PartitionRange,
+ * int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListPartitionStatisticsEvent(
+ String user, NameIdentifier identifier, PartitionRange partitionRange) {
+ this(user, identifier, partitionRange, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
/**
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListStatisticsEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListStatisticsEvent.java
index d2fa4ee436..7afbf778b1 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListStatisticsEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/stats/ListStatisticsEvent.java
@@ -20,20 +20,44 @@ package org.apache.gravitino.listener.api.event.stats;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
/** Event fired when listing statistics. */
@DeveloperApi
-public class ListStatisticsEvent extends StatisticsEvent {
+public class ListStatisticsEvent extends StatisticsEvent implements ListEvent {
+
+ private final int count;
/**
* Constructor for creating a list statistics event.
*
* @param user the user initiating the event
* @param identifier the name identifier associated with the event.
+ * @param count the number of statistics returned by the list operation.
*/
- public ListStatisticsEvent(String user, NameIdentifier identifier) {
+ public ListStatisticsEvent(String user, NameIdentifier identifier, int count) {
super(user, identifier);
+ this.count = count;
+ }
+
+ /**
+ * Constructor for creating a list statistics event without a count.
+ *
+ * @param user the user initiating the event
+ * @param identifier the name identifier associated with the event.
+ * @deprecated Use {@link #ListStatisticsEvent(String, NameIdentifier, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListStatisticsEvent(String user, NameIdentifier identifier) {
+ this(user, identifier, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return count;
}
@Override
diff --git a/core/src/main/java/org/apache/gravitino/listener/api/event/view/ListViewEvent.java b/core/src/main/java/org/apache/gravitino/listener/api/event/view/ListViewEvent.java
index a4afbb59eb..a1c6ab9f41 100644
--- a/core/src/main/java/org/apache/gravitino/listener/api/event/view/ListViewEvent.java
+++ b/core/src/main/java/org/apache/gravitino/listener/api/event/view/ListViewEvent.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.listener.api.event.view;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.annotation.DeveloperApi;
+import org.apache.gravitino.listener.api.event.ListEvent;
import org.apache.gravitino.listener.api.event.OperationType;
/**
@@ -29,18 +30,51 @@ import org.apache.gravitino.listener.api.event.OperationType;
* listed identifiers are not stored on the event.
*/
@DeveloperApi
-public final class ListViewEvent extends ViewEvent {
+public final class ListViewEvent extends ViewEvent implements ListEvent {
private final Namespace namespace;
+ private final int viewCount;
- public ListViewEvent(String user, Namespace namespace) {
+ /**
+ * Constructs an instance of {@code ListViewEvent}.
+ *
+ * @param user The username of the individual who initiated the view listing.
+ * @param namespace The namespace from which views were listed.
+ * @param viewCount The number of views returned by the list operation.
+ */
+ public ListViewEvent(String user, Namespace namespace, int viewCount) {
super(user, NameIdentifier.of(namespace.levels()));
this.namespace = namespace;
+ this.viewCount = viewCount;
+ }
+
+ /**
+ * Constructs an instance of {@code ListViewEvent} without a count.
+ *
+ * @param user The username of the individual who initiated the view listing.
+ * @param namespace The namespace from which views were listed.
+ * @deprecated Use {@link #ListViewEvent(String, Namespace, int)} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public ListViewEvent(String user, Namespace namespace) {
+ this(user, namespace, -1);
}
+ /**
+ * Returns the namespace associated with this event.
+ *
+ * @return the namespace.
+ */
public Namespace namespace() {
return namespace;
}
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return viewCount;
+ }
+
@Override
public OperationType operationType() {
return OperationType.LIST_VIEW;
diff --git a/core/src/test/java/org/apache/gravitino/audit/TestFileAuditWriter.java b/core/src/test/java/org/apache/gravitino/audit/TestFileAuditWriter.java
index f117c649f4..f17a04599c 100644
--- a/core/src/test/java/org/apache/gravitino/audit/TestFileAuditWriter.java
+++ b/core/src/test/java/org/apache/gravitino/audit/TestFileAuditWriter.java
@@ -23,7 +23,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.gravitino.Namespace;
import org.apache.gravitino.audit.v2.SimpleFormatterV2;
+import org.apache.gravitino.listener.api.event.ListCatalogEvent;
+import org.apache.gravitino.listener.api.event.ListMetalakeEvent;
+import org.apache.gravitino.listener.api.event.ListTableEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
@@ -141,6 +145,62 @@ public class TestFileAuditWriter {
Assertions.assertTrue(warnCapture.getEvents().isEmpty());
}
+ @Test
+ public void testListTableEventProducesCorrectLogLine() {
+ FileAuditWriter writer = new FileAuditWriter();
+ writer.init(new SimpleFormatterV2(), new HashMap<>());
+
+ ListTableEvent event = new ListTableEvent("alice", Namespace.of("m", "c", "s"), 4);
+ writer.doWrite(writer.getFormatter().format(event));
+
+ Assertions.assertEquals(1, auditCapture.getEvents().size());
+ String line = auditCapture.getEvents().get(0).getMessage().getFormattedMessage();
+ String[] fields = line.split("\t", -1);
+ Assertions.assertEquals(8, fields.length, "Expected 8 tab-separated fields");
+ Assertions.assertEquals("alice", fields[1]);
+ Assertions.assertEquals("LIST_TABLE", fields[2]);
+ Assertions.assertEquals("m.c.s", fields[3]);
+ Assertions.assertEquals("SUCCESS", fields[4]);
+ Assertions.assertEquals("GRAVITINO_SERVER", fields[5]);
+ Assertions.assertEquals("unknown", fields[6]);
+ Assertions.assertEquals("{count=4}", fields[7]); // count surfaced in last field
+ }
+
+ @Test
+ public void testListMetalakeEventNullIdentifierInLogLine() {
+ FileAuditWriter writer = new FileAuditWriter();
+ writer.init(new SimpleFormatterV2(), new HashMap<>());
+
+ ListMetalakeEvent event = new ListMetalakeEvent("bob", 2);
+ writer.doWrite(writer.getFormatter().format(event));
+
+ String line = auditCapture.getEvents().get(0).getMessage().getFormattedMessage();
+ String[] fields = line.split("\t", -1);
+ Assertions.assertEquals(8, fields.length);
+ Assertions.assertEquals("bob", fields[1]);
+ Assertions.assertEquals("LIST_METALAKE", fields[2]);
+ Assertions.assertEquals("null", fields[3]); // null identifier serialises as "null"
+ Assertions.assertEquals("{count=2}", fields[7]);
+ }
+
+ @Test
+ public void testListCatalogEventLogLine() {
+ FileAuditWriter writer = new FileAuditWriter();
+ writer.init(new SimpleFormatterV2(), new HashMap<>());
+
+ ListCatalogEvent event = new ListCatalogEvent("carol", Namespace.of("metalake"), 3);
+ writer.doWrite(writer.getFormatter().format(event));
+
+ String line = auditCapture.getEvents().get(0).getMessage().getFormattedMessage();
+ String[] fields = line.split("\t", -1);
+ Assertions.assertEquals(8, fields.length);
+ Assertions.assertEquals("carol", fields[1]);
+ Assertions.assertEquals("LIST_CATALOG", fields[2]);
+ Assertions.assertEquals("metalake", fields[3]);
+ Assertions.assertEquals("SUCCESS", fields[4]);
+ Assertions.assertEquals("{count=3}", fields[7]);
+ }
+
@Test
public void testCloseIsNoOp() {
FileAuditWriter writer = new FileAuditWriter();
diff --git a/core/src/test/java/org/apache/gravitino/audit/TestOperation.java b/core/src/test/java/org/apache/gravitino/audit/TestOperation.java
index 2a7032e45e..94c7405d72 100644
--- a/core/src/test/java/org/apache/gravitino/audit/TestOperation.java
+++ b/core/src/test/java/org/apache/gravitino/audit/TestOperation.java
@@ -219,59 +219,59 @@ public class TestOperation {
public void testCreateOperation() {
Event createMetalakeEvent = new CreateMetalakeEvent(USER, catalogIdentifier, metalakeInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createMetalakeEvent), AuditLog.Operation.CREATE_METALAKE);
+ AuditLog.Operation.CREATE_METALAKE, AuditLog.Operation.fromEvent(createMetalakeEvent));
Event createMetalakeFaileEvent =
new CreateMetalakeFailureEvent(USER, metalakeIdentifier, new Exception(), metalakeInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createMetalakeFaileEvent), AuditLog.Operation.CREATE_METALAKE);
+ AuditLog.Operation.CREATE_METALAKE, AuditLog.Operation.fromEvent(createMetalakeFaileEvent));
Event createCatalogEvent = new CreateCatalogEvent(USER, catalogIdentifier, catalogInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createCatalogEvent), AuditLog.Operation.CREATE_CATALOG);
+ AuditLog.Operation.CREATE_CATALOG, AuditLog.Operation.fromEvent(createCatalogEvent));
Event CreateCatalogFailureEvent =
new CreateCatalogFailureEvent(USER, catalogIdentifier, new Exception(), catalogInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(CreateCatalogFailureEvent), AuditLog.Operation.CREATE_CATALOG);
+ AuditLog.Operation.CREATE_CATALOG, AuditLog.Operation.fromEvent(CreateCatalogFailureEvent));
Event createSchemaEvent = new CreateSchemaEvent(USER, schemaIdentifier, schemaInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createSchemaEvent), AuditLog.Operation.CREATE_SCHEMA);
+ AuditLog.Operation.CREATE_SCHEMA, AuditLog.Operation.fromEvent(createSchemaEvent));
Event createSchemaFailureEvent =
new CreateSchemaFailureEvent(USER, schemaIdentifier, new Exception(), schemaInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createSchemaFailureEvent), AuditLog.Operation.CREATE_SCHEMA);
+ AuditLog.Operation.CREATE_SCHEMA, AuditLog.Operation.fromEvent(createSchemaFailureEvent));
Event createTableEvent = new CreateTableEvent(USER, tableIdentifier, tableInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createTableEvent), AuditLog.Operation.CREATE_TABLE);
+ AuditLog.Operation.CREATE_TABLE, AuditLog.Operation.fromEvent(createTableEvent));
Event createTableFailureEvent =
new CreateTableFailureEvent(USER, tableIdentifier, new Exception(), tableInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createTableFailureEvent), AuditLog.Operation.CREATE_TABLE);
+ AuditLog.Operation.CREATE_TABLE, AuditLog.Operation.fromEvent(createTableFailureEvent));
Event createFilesetEvent = new CreateFilesetEvent(USER, filesetIdentifier, filesetInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createFilesetEvent), AuditLog.Operation.CREATE_FILESET);
+ AuditLog.Operation.CREATE_FILESET, AuditLog.Operation.fromEvent(createFilesetEvent));
Event createFilesetFailureEvent =
new CreateFilesetFailureEvent(USER, filesetIdentifier, new Exception(), filesetInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createFilesetFailureEvent), AuditLog.Operation.CREATE_FILESET);
+ AuditLog.Operation.CREATE_FILESET, AuditLog.Operation.fromEvent(createFilesetFailureEvent));
Event createTopicEvent = new CreateTopicEvent(USER, topicIdentifier, topicInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createTopicEvent), AuditLog.Operation.CREATE_TOPIC);
+ AuditLog.Operation.CREATE_TOPIC, AuditLog.Operation.fromEvent(createTopicEvent));
Event createTopicFailureEvent =
new CreateTopicFailureEvent(USER, topicIdentifier, new Exception(), topicInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createTopicFailureEvent), AuditLog.Operation.CREATE_TOPIC);
+ AuditLog.Operation.CREATE_TOPIC, AuditLog.Operation.fromEvent(createTopicFailureEvent));
Event createViewEvent = new CreateViewEvent(USER, viewIdentifier, viewInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createViewEvent), AuditLog.Operation.CREATE_VIEW);
+ AuditLog.Operation.CREATE_VIEW, AuditLog.Operation.fromEvent(createViewEvent));
Event createViewFailureEvent =
new CreateViewFailureEvent(USER, viewIdentifier, new Exception(), viewInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(createViewFailureEvent), AuditLog.Operation.CREATE_VIEW);
+ AuditLog.Operation.CREATE_VIEW, AuditLog.Operation.fromEvent(createViewFailureEvent));
}
@Test
@@ -279,122 +279,122 @@ public class TestOperation {
Event alterMetalakeEvent =
new AlterMetalakeEvent(USER, metalakeIdentifier, new MetalakeChange[] {}, metalakeInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterMetalakeEvent), AuditLog.Operation.ALTER_METALAKE);
+ AuditLog.Operation.ALTER_METALAKE, AuditLog.Operation.fromEvent(alterMetalakeEvent));
Event alterMetalakeFailureEvent =
new AlterMetalakeFailureEvent(
USER, metalakeIdentifier, new Exception(), new MetalakeChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterMetalakeFailureEvent), AuditLog.Operation.ALTER_METALAKE);
+ AuditLog.Operation.ALTER_METALAKE, AuditLog.Operation.fromEvent(alterMetalakeFailureEvent));
Event alterCatalogEvent =
new AlterCatalogEvent(USER, schemaIdentifier, new CatalogChange[] {}, catalogInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterCatalogEvent), AuditLog.Operation.ALTER_CATALOG);
+ AuditLog.Operation.ALTER_CATALOG, AuditLog.Operation.fromEvent(alterCatalogEvent));
Event alterCatalogFailureEvent =
new AlterCatalogFailureEvent(
USER, catalogIdentifier, new Exception(), new CatalogChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterCatalogFailureEvent), AuditLog.Operation.ALTER_CATALOG);
+ AuditLog.Operation.ALTER_CATALOG, AuditLog.Operation.fromEvent(alterCatalogFailureEvent));
Event alterSchemaEvent =
new AlterSchemaEvent(USER, schemaIdentifier, new SchemaChange[] {}, schemaInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterSchemaEvent), AuditLog.Operation.ALTER_SCHEMA);
+ AuditLog.Operation.ALTER_SCHEMA, AuditLog.Operation.fromEvent(alterSchemaEvent));
Event alterSchemaFailureEvent =
new AlterSchemaFailureEvent(USER, schemaIdentifier, new Exception(), new SchemaChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterSchemaFailureEvent), AuditLog.Operation.ALTER_SCHEMA);
+ AuditLog.Operation.ALTER_SCHEMA, AuditLog.Operation.fromEvent(alterSchemaFailureEvent));
Event alterTableEvent =
new AlterTableEvent(USER, tableIdentifier, new TableChange[] {}, tableInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterTableEvent), AuditLog.Operation.ALTER_TABLE);
+ AuditLog.Operation.ALTER_TABLE, AuditLog.Operation.fromEvent(alterTableEvent));
Event alterTableFailureEvent =
new AlterTableFailureEvent(USER, tableIdentifier, new Exception(), new TableChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterTableFailureEvent), AuditLog.Operation.ALTER_TABLE);
+ AuditLog.Operation.ALTER_TABLE, AuditLog.Operation.fromEvent(alterTableFailureEvent));
Event alterFilesetEvent =
new AlterFilesetEvent(USER, filesetIdentifier, new FilesetChange[] {}, filesetInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterFilesetEvent), AuditLog.Operation.ALTER_FILESET);
+ AuditLog.Operation.ALTER_FILESET, AuditLog.Operation.fromEvent(alterFilesetEvent));
Event alterFilesetFailureEvent =
new AlterFilesetFailureEvent(
USER, filesetIdentifier, new Exception(), new FilesetChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterFilesetFailureEvent), AuditLog.Operation.ALTER_FILESET);
+ AuditLog.Operation.ALTER_FILESET, AuditLog.Operation.fromEvent(alterFilesetFailureEvent));
Event alterTopicEvent =
new AlterTopicEvent(USER, topicIdentifier, new TopicChange[] {}, topicInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterTopicEvent), AuditLog.Operation.ALTER_TOPIC);
+ AuditLog.Operation.ALTER_TOPIC, AuditLog.Operation.fromEvent(alterTopicEvent));
Event alterTopicFailureEvent =
new AlterTopicFailureEvent(USER, topicIdentifier, new Exception(), new TopicChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterTopicFailureEvent), AuditLog.Operation.ALTER_TOPIC);
+ AuditLog.Operation.ALTER_TOPIC, AuditLog.Operation.fromEvent(alterTopicFailureEvent));
Event alterViewEvent = new AlterViewEvent(USER, viewIdentifier, new ViewChange[] {}, viewInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterViewEvent), AuditLog.Operation.ALTER_VIEW);
+ AuditLog.Operation.ALTER_VIEW, AuditLog.Operation.fromEvent(alterViewEvent));
Event alterViewFailureEvent =
new AlterViewFailureEvent(USER, viewIdentifier, new Exception(), new ViewChange[] {});
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(alterViewFailureEvent), AuditLog.Operation.ALTER_VIEW);
+ AuditLog.Operation.ALTER_VIEW, AuditLog.Operation.fromEvent(alterViewFailureEvent));
}
@Test
public void testDropOperation() {
Event dropMetalakeEvent = new DropMetalakeEvent(USER, metalakeIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropMetalakeEvent), AuditLog.Operation.DROP_METALAKE);
+ AuditLog.Operation.DROP_METALAKE, AuditLog.Operation.fromEvent(dropMetalakeEvent));
Event dropMetalakeFailureEvent = new DropMetalakeFailureEvent(USER, metalakeIdentifier, null);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropMetalakeFailureEvent), AuditLog.Operation.DROP_METALAKE);
+ AuditLog.Operation.DROP_METALAKE, AuditLog.Operation.fromEvent(dropMetalakeFailureEvent));
Event dropCatalogEvent = new DropCatalogEvent(USER, catalogIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropCatalogEvent), AuditLog.Operation.DROP_CATALOG);
+ AuditLog.Operation.DROP_CATALOG, AuditLog.Operation.fromEvent(dropCatalogEvent));
Event dropCatalogFailureEvent =
new DropCatalogFailureEvent(USER, catalogIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropCatalogFailureEvent), AuditLog.Operation.DROP_CATALOG);
+ AuditLog.Operation.DROP_CATALOG, AuditLog.Operation.fromEvent(dropCatalogFailureEvent));
Event dropSchemaEvent = new DropSchemaEvent(USER, schemaIdentifier, true, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropSchemaEvent), AuditLog.Operation.DROP_SCHEMA);
+ AuditLog.Operation.DROP_SCHEMA, AuditLog.Operation.fromEvent(dropSchemaEvent));
Event dropSchemaFailureEvent =
new DropSchemaFailureEvent(USER, schemaIdentifier, new Exception(), true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropSchemaFailureEvent), AuditLog.Operation.DROP_SCHEMA);
+ AuditLog.Operation.DROP_SCHEMA, AuditLog.Operation.fromEvent(dropSchemaFailureEvent));
Event dropTableEvent = new DropTableEvent(USER, tableIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropTableEvent), AuditLog.Operation.DROP_TABLE);
+ AuditLog.Operation.DROP_TABLE, AuditLog.Operation.fromEvent(dropTableEvent));
Event dropTableFailureEvent = new DropTableFailureEvent(USER, tableIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropTableFailureEvent), AuditLog.Operation.DROP_TABLE);
+ AuditLog.Operation.DROP_TABLE, AuditLog.Operation.fromEvent(dropTableFailureEvent));
Event dropFilesetEvent = new DropFilesetEvent(USER, filesetIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropFilesetEvent), AuditLog.Operation.DROP_FILESET);
+ AuditLog.Operation.DROP_FILESET, AuditLog.Operation.fromEvent(dropFilesetEvent));
Event dropFilesetFailureEvent =
new DropFilesetFailureEvent(USER, filesetIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropFilesetFailureEvent), AuditLog.Operation.DROP_FILESET);
+ AuditLog.Operation.DROP_FILESET, AuditLog.Operation.fromEvent(dropFilesetFailureEvent));
Event dropTopicEvent = new DropTopicEvent(USER, topicIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropTopicEvent), AuditLog.Operation.DROP_TOPIC);
+ AuditLog.Operation.DROP_TOPIC, AuditLog.Operation.fromEvent(dropTopicEvent));
Event dropTopicFailureEvent = new DropTopicFailureEvent(USER, topicIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropTopicFailureEvent), AuditLog.Operation.DROP_TOPIC);
+ AuditLog.Operation.DROP_TOPIC, AuditLog.Operation.fromEvent(dropTopicFailureEvent));
Event dropViewEvent = new DropViewEvent(USER, viewIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropViewEvent), AuditLog.Operation.DROP_VIEW);
+ AuditLog.Operation.DROP_VIEW, AuditLog.Operation.fromEvent(dropViewEvent));
Event dropViewFailureEvent = new DropViewFailureEvent(USER, viewIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(dropViewFailureEvent), AuditLog.Operation.DROP_VIEW);
+ AuditLog.Operation.DROP_VIEW, AuditLog.Operation.fromEvent(dropViewFailureEvent));
}
@Test
@@ -402,21 +402,21 @@ public class TestOperation {
Event purgeMetalakeEvent =
new PurgePartitionEvent(USER, metalakeIdentifier, true, PARTITION_NAME);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(purgeMetalakeEvent), AuditLog.Operation.PURGE_PARTITION);
+ AuditLog.Operation.PURGE_PARTITION, AuditLog.Operation.fromEvent(purgeMetalakeEvent));
Event purgeMetalakeFailureEvent =
new PurgePartitionFailureEvent(USER, partitionIdentifier, new Exception(), PARTITION_NAME);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(purgeMetalakeFailureEvent),
- AuditLog.Operation.PURGE_PARTITION);
+ AuditLog.Operation.PURGE_PARTITION,
+ AuditLog.Operation.fromEvent(purgeMetalakeFailureEvent));
Event purgeTableEvent = new PurgeTableEvent(USER, tableIdentifier, true);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(purgeTableEvent), AuditLog.Operation.PURGE_TABLE);
+ AuditLog.Operation.PURGE_TABLE, AuditLog.Operation.fromEvent(purgeTableEvent));
Event purgePartitionFailureEvent =
new PurgePartitionFailureEvent(USER, partitionIdentifier, new Exception(), PARTITION_NAME);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(purgePartitionFailureEvent),
- AuditLog.Operation.PURGE_PARTITION);
+ AuditLog.Operation.PURGE_PARTITION,
+ AuditLog.Operation.fromEvent(purgePartitionFailureEvent));
}
@Test
@@ -424,168 +424,168 @@ public class TestOperation {
Event getFileLocationEvent =
new GetFileLocationEvent(USER, filesetIdentifier, "location", "subPath", new HashMap<>());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(getFileLocationEvent), AuditLog.Operation.GET_FILE_LOCATION);
+ AuditLog.Operation.GET_FILE_LOCATION, AuditLog.Operation.fromEvent(getFileLocationEvent));
Event getFilesetFailureEvent =
new GetFileLocationFailureEvent(USER, filesetIdentifier, "subPath", new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(getFilesetFailureEvent), AuditLog.Operation.GET_FILE_LOCATION);
+ AuditLog.Operation.GET_FILE_LOCATION, AuditLog.Operation.fromEvent(getFilesetFailureEvent));
Event getPartitionEvent = new GetPartitionEvent(USER, partitionIdentifier, partitionInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(getPartitionEvent), AuditLog.Operation.GET_PARTITION);
+ AuditLog.Operation.GET_PARTITION, AuditLog.Operation.fromEvent(getPartitionEvent));
Event getPartitionFailureEvent =
new GetPartitionFailureEvent(USER, partitionIdentifier, new Exception(), PARTITION_NAME);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(getPartitionFailureEvent), AuditLog.Operation.GET_PARTITION);
+ AuditLog.Operation.GET_PARTITION, AuditLog.Operation.fromEvent(getPartitionFailureEvent));
}
@Test
public void testListOperation() {
Namespace namespace = Namespace.of("metalake", "catalog");
- Event listCatalogEvent = new ListCatalogEvent(USER, namespace);
+ Event listCatalogEvent = new ListCatalogEvent(USER, namespace, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listCatalogEvent), AuditLog.Operation.LIST_CATALOG);
+ AuditLog.Operation.LIST_CATALOG, AuditLog.Operation.fromEvent(listCatalogEvent));
Event listCatalogFailureEvent = new ListCatalogFailureEvent(USER, new Exception(), namespace);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listCatalogFailureEvent), AuditLog.Operation.LIST_CATALOG);
+ AuditLog.Operation.LIST_CATALOG, AuditLog.Operation.fromEvent(listCatalogFailureEvent));
- Event listSchemaEvent = new ListSchemaEvent(USER, namespace);
+ Event listSchemaEvent = new ListSchemaEvent(USER, namespace, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listSchemaEvent), AuditLog.Operation.LIST_SCHEMA);
+ AuditLog.Operation.LIST_SCHEMA, AuditLog.Operation.fromEvent(listSchemaEvent));
Event listSchemaFailureEvent = new ListSchemaFailureEvent(USER, namespace, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listSchemaFailureEvent), AuditLog.Operation.LIST_SCHEMA);
+ AuditLog.Operation.LIST_SCHEMA, AuditLog.Operation.fromEvent(listSchemaFailureEvent));
- Event listTableEvent = new ListTableEvent(USER, namespace);
+ Event listTableEvent = new ListTableEvent(USER, namespace, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listTableEvent), AuditLog.Operation.LIST_TABLE);
+ AuditLog.Operation.LIST_TABLE, AuditLog.Operation.fromEvent(listTableEvent));
Event listTableFailureEvent = new ListTableFailureEvent(USER, namespace, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listTableFailureEvent), AuditLog.Operation.LIST_TABLE);
+ AuditLog.Operation.LIST_TABLE, AuditLog.Operation.fromEvent(listTableFailureEvent));
- Event listTopicEvent = new ListTopicEvent(USER, namespace);
+ Event listTopicEvent = new ListTopicEvent(USER, namespace, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listTopicEvent), AuditLog.Operation.LIST_TOPIC);
+ AuditLog.Operation.LIST_TOPIC, AuditLog.Operation.fromEvent(listTopicEvent));
Event listTopicFailureEvent = new ListTopicFailureEvent(USER, namespace, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listTopicFailureEvent), AuditLog.Operation.LIST_TOPIC);
+ AuditLog.Operation.LIST_TOPIC, AuditLog.Operation.fromEvent(listTopicFailureEvent));
Namespace viewNamespace = Namespace.of("metalake", "catalog", "schema");
- Event listViewEvent = new ListViewEvent(USER, viewNamespace);
+ Event listViewEvent = new ListViewEvent(USER, viewNamespace, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listViewEvent), AuditLog.Operation.LIST_VIEW);
+ AuditLog.Operation.LIST_VIEW, AuditLog.Operation.fromEvent(listViewEvent));
Event listViewFailureEvent = new ListViewFailureEvent(USER, viewNamespace, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listViewFailureEvent), AuditLog.Operation.LIST_VIEW);
+ AuditLog.Operation.LIST_VIEW, AuditLog.Operation.fromEvent(listViewFailureEvent));
- Event listFilesetEvent = new ListFilesetEvent(USER, namespace);
+ Event listFilesetEvent = new ListFilesetEvent(USER, namespace, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listFilesetEvent), AuditLog.Operation.LIST_FILESET);
+ AuditLog.Operation.LIST_FILESET, AuditLog.Operation.fromEvent(listFilesetEvent));
Event listFilesetFailureEvent = new ListFilesetFailureEvent(USER, namespace, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listFilesetFailureEvent), AuditLog.Operation.LIST_FILESET);
+ AuditLog.Operation.LIST_FILESET, AuditLog.Operation.fromEvent(listFilesetFailureEvent));
- Event listPartitionEvent = new ListPartitionEvent(USER, partitionIdentifier);
+ Event listPartitionEvent = new ListPartitionEvent(USER, partitionIdentifier, 0);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listPartitionEvent), AuditLog.Operation.LIST_PARTITION);
+ AuditLog.Operation.LIST_PARTITION, AuditLog.Operation.fromEvent(listPartitionEvent));
Event listPartitionFailureEvent =
new ListPartitionFailureEvent(USER, partitionIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(listPartitionFailureEvent), AuditLog.Operation.LIST_PARTITION);
+ AuditLog.Operation.LIST_PARTITION, AuditLog.Operation.fromEvent(listPartitionFailureEvent));
}
@Test
public void testLoadOperation() {
Event loadMetalakeEvent = new LoadMetalakeEvent(USER, metalakeIdentifier, metalakeInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadMetalakeEvent), AuditLog.Operation.LOAD_METALAKE);
+ AuditLog.Operation.LOAD_METALAKE, AuditLog.Operation.fromEvent(loadMetalakeEvent));
Event loadMetalakeFailureEvent =
new LoadMetalakeFailureEvent(USER, metalakeIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadMetalakeFailureEvent), AuditLog.Operation.LOAD_METALAKE);
+ AuditLog.Operation.LOAD_METALAKE, AuditLog.Operation.fromEvent(loadMetalakeFailureEvent));
Event loadCatalogEvent = new LoadCatalogEvent(USER, catalogIdentifier, catalogInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadCatalogEvent), AuditLog.Operation.LOAD_CATALOG);
+ AuditLog.Operation.LOAD_CATALOG, AuditLog.Operation.fromEvent(loadCatalogEvent));
Event loadCatalogFailureEvent =
new LoadCatalogFailureEvent(USER, catalogIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadCatalogFailureEvent), AuditLog.Operation.LOAD_CATALOG);
+ AuditLog.Operation.LOAD_CATALOG, AuditLog.Operation.fromEvent(loadCatalogFailureEvent));
Event loadSchemaEvent = new LoadSchemaEvent(USER, schemaIdentifier, schemaInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadSchemaEvent), AuditLog.Operation.LOAD_SCHEMA);
+ AuditLog.Operation.LOAD_SCHEMA, AuditLog.Operation.fromEvent(loadSchemaEvent));
Event loadSchemaFailureEvent =
new LoadSchemaFailureEvent(USER, schemaIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadSchemaFailureEvent), AuditLog.Operation.LOAD_SCHEMA);
+ AuditLog.Operation.LOAD_SCHEMA, AuditLog.Operation.fromEvent(loadSchemaFailureEvent));
Event loadTableEvent = new LoadTableEvent(USER, tableIdentifier, tableInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadTableEvent), AuditLog.Operation.LOAD_TABLE);
+ AuditLog.Operation.LOAD_TABLE, AuditLog.Operation.fromEvent(loadTableEvent));
Event loadTableFailureEvent = new LoadTableFailureEvent(USER, tableIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadTableFailureEvent), AuditLog.Operation.LOAD_TABLE);
+ AuditLog.Operation.LOAD_TABLE, AuditLog.Operation.fromEvent(loadTableFailureEvent));
Event loadFilesetEvent = new LoadFilesetEvent(USER, filesetIdentifier, filesetInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadFilesetEvent), AuditLog.Operation.LOAD_FILESET);
+ AuditLog.Operation.LOAD_FILESET, AuditLog.Operation.fromEvent(loadFilesetEvent));
Event loadFilesetFailureEvent =
new LoadFilesetFailureEvent(USER, filesetIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadFilesetFailureEvent), AuditLog.Operation.LOAD_FILESET);
+ AuditLog.Operation.LOAD_FILESET, AuditLog.Operation.fromEvent(loadFilesetFailureEvent));
Event loadTopicEvent = new LoadTopicEvent(USER, topicIdentifier, topicInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadTopicEvent), AuditLog.Operation.LOAD_TOPIC);
+ AuditLog.Operation.LOAD_TOPIC, AuditLog.Operation.fromEvent(loadTopicEvent));
Event loadTopicFailureEvent = new LoadTopicFailureEvent(USER, topicIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadTopicFailureEvent), AuditLog.Operation.LOAD_TOPIC);
+ AuditLog.Operation.LOAD_TOPIC, AuditLog.Operation.fromEvent(loadTopicFailureEvent));
Event loadViewEvent = new LoadViewEvent(USER, viewIdentifier, viewInfo);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadViewEvent), AuditLog.Operation.LOAD_VIEW);
+ AuditLog.Operation.LOAD_VIEW, AuditLog.Operation.fromEvent(loadViewEvent));
Event loadViewFailureEvent = new LoadViewFailureEvent(USER, viewIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(loadViewFailureEvent), AuditLog.Operation.LOAD_VIEW);
+ AuditLog.Operation.LOAD_VIEW, AuditLog.Operation.fromEvent(loadViewFailureEvent));
}
@Test
public void testEnableDisableOperation() {
Event enableMetalakeEvent = new EnableMetalakeEvent(USER, metalakeIdentifier);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(enableMetalakeEvent), AuditLog.Operation.ENABLE_METALAKE);
+ AuditLog.Operation.ENABLE_METALAKE, AuditLog.Operation.fromEvent(enableMetalakeEvent));
Event enableMetalakeFailureEvent =
new EnableMetalakeFailureEvent(USER, metalakeIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(enableMetalakeFailureEvent),
- AuditLog.Operation.ENABLE_METALAKE);
+ AuditLog.Operation.ENABLE_METALAKE,
+ AuditLog.Operation.fromEvent(enableMetalakeFailureEvent));
Event disableMetalakeEvent = new DisableMetalakeEvent(USER, metalakeIdentifier);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(disableMetalakeEvent), AuditLog.Operation.DISABLE_METALAKE);
+ AuditLog.Operation.DISABLE_METALAKE, AuditLog.Operation.fromEvent(disableMetalakeEvent));
Event disableMetalakeFailureEvent =
new DisableMetalakeFailureEvent(USER, metalakeIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(disableMetalakeFailureEvent),
- AuditLog.Operation.DISABLE_METALAKE);
+ AuditLog.Operation.DISABLE_METALAKE,
+ AuditLog.Operation.fromEvent(disableMetalakeFailureEvent));
Event enableCatalogEvent = new EnableCatalogEvent(USER, catalogIdentifier);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(enableCatalogEvent), AuditLog.Operation.ENABLE_CATALOG);
+ AuditLog.Operation.ENABLE_CATALOG, AuditLog.Operation.fromEvent(enableCatalogEvent));
Event enableCatalogFailureEvent =
new EnableCatalogFailureEvent(USER, catalogIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(enableCatalogFailureEvent), AuditLog.Operation.ENABLE_CATALOG);
+ AuditLog.Operation.ENABLE_CATALOG, AuditLog.Operation.fromEvent(enableCatalogFailureEvent));
Event disableCatalogEvent = new DisableCatalogEvent(USER, catalogIdentifier);
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(disableCatalogEvent), AuditLog.Operation.DISABLE_CATALOG);
+ AuditLog.Operation.DISABLE_CATALOG, AuditLog.Operation.fromEvent(disableCatalogEvent));
Event disableCatalogFailureEvent =
new DisableCatalogFailureEvent(USER, catalogIdentifier, new Exception());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(disableCatalogFailureEvent),
- AuditLog.Operation.DISABLE_CATALOG);
+ AuditLog.Operation.DISABLE_CATALOG,
+ AuditLog.Operation.fromEvent(disableCatalogFailureEvent));
}
@Test
@@ -593,13 +593,13 @@ public class TestOperation {
Event partitionExistsEvent =
new PartitionExistsEvent(USER, partitionIdentifier, true, partitionIdentifier.name());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(partitionExistsEvent), AuditLog.Operation.PARTITION_EXIST);
+ AuditLog.Operation.PARTITION_EXIST, AuditLog.Operation.fromEvent(partitionExistsEvent));
Event partitionExistsFailureEvent =
new PartitionExistsEvent(USER, partitionIdentifier, true, partitionIdentifier.name());
Assertions.assertEquals(
- AuditLog.Operation.fromEvent(partitionExistsFailureEvent),
- AuditLog.Operation.PARTITION_EXIST);
+ AuditLog.Operation.PARTITION_EXIST,
+ AuditLog.Operation.fromEvent(partitionExistsFailureEvent));
}
private NameIdentifier mockMetalakeIdentifier() {
diff --git a/core/src/test/java/org/apache/gravitino/audit/v2/TestSimpleAuditLogV2.java b/core/src/test/java/org/apache/gravitino/audit/v2/TestSimpleAuditLogV2.java
index a96a4de2a3..e57f60c93e 100644
--- a/core/src/test/java/org/apache/gravitino/audit/v2/TestSimpleAuditLogV2.java
+++ b/core/src/test/java/org/apache/gravitino/audit/v2/TestSimpleAuditLogV2.java
@@ -22,8 +22,13 @@ package org.apache.gravitino.audit.v2;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.Namespace;
import org.apache.gravitino.listener.api.event.Event;
import org.apache.gravitino.listener.api.event.EventSource;
+import org.apache.gravitino.listener.api.event.ListCatalogEvent;
+import org.apache.gravitino.listener.api.event.ListMetalakeEvent;
+import org.apache.gravitino.listener.api.event.ListSchemaEvent;
+import org.apache.gravitino.listener.api.event.ListTableEvent;
import org.apache.gravitino.listener.api.event.OperationStatus;
import org.apache.gravitino.listener.api.event.OperationType;
import org.junit.jupiter.api.Assertions;
@@ -71,6 +76,147 @@ public class TestSimpleAuditLogV2 {
Assertions.assertTrue(output.contains("SUCCESS"));
}
+ // ---- list event tests ----
+ @Test
+ public void testListTableEventFormat() {
+ Namespace namespace = Namespace.of("metalake", "catalog", "schema");
+ ListTableEvent event = new ListTableEvent("alice", namespace, 5);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertEquals(OperationType.LIST_TABLE, log.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, log.operationStatus());
+ Assertions.assertEquals("metalake.catalog.schema", log.identifier());
+ Assertions.assertEquals("alice", log.user());
+
+ String output = log.toString();
+ String[] fields = output.split("\t", -1);
+ Assertions.assertEquals(8, fields.length);
+ Assertions.assertTrue(
+ fields[0].matches("\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\.\\d{3}\\]"));
+ Assertions.assertEquals("alice", fields[1]);
+ Assertions.assertEquals("LIST_TABLE", fields[2]);
+ Assertions.assertEquals("metalake.catalog.schema", fields[3]);
+ Assertions.assertEquals("SUCCESS", fields[4]);
+ Assertions.assertEquals("GRAVITINO_SERVER", fields[5]);
+ Assertions.assertEquals("unknown", fields[6]); // no RequestContext set in tests
+ Assertions.assertEquals("{count=5}", fields[7]); // count surfaced in last field
+ }
+
+ @Test
+ public void testListMetalakeEventNullIdentifier() {
+ ListMetalakeEvent event = new ListMetalakeEvent("bob", 3);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertNull(log.identifier());
+ Assertions.assertEquals(OperationType.LIST_METALAKE, log.operationType());
+
+ // toString() must not throw and must have 8 fields with count in last field.
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals(8, fields.length);
+ Assertions.assertEquals("bob", fields[1]);
+ Assertions.assertEquals("LIST_METALAKE", fields[2]);
+ Assertions.assertEquals("null", fields[3]);
+ Assertions.assertEquals("{count=3}", fields[7]);
+ }
+
+ @Test
+ public void testListCatalogEventFormat() {
+ Namespace namespace = Namespace.of("metalake");
+ ListCatalogEvent event = new ListCatalogEvent("carol", namespace, 2);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertEquals("metalake", log.identifier());
+ Assertions.assertEquals(OperationType.LIST_CATALOG, log.operationType());
+
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("LIST_CATALOG", fields[2]);
+ Assertions.assertEquals("metalake", fields[3]);
+ Assertions.assertEquals("{count=2}", fields[7]);
+ }
+
+ @Test
+ public void testListSchemaEventFormat() {
+ Namespace namespace = Namespace.of("metalake", "catalog");
+ ListSchemaEvent event = new ListSchemaEvent("dave", namespace, 7);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("LIST_SCHEMA", fields[2]);
+ Assertions.assertEquals("metalake.catalog", fields[3]);
+ Assertions.assertEquals("{count=7}", fields[7]);
+ }
+
+ @Test
+ public void testListEventZeroCountInOutput() {
+ // count=0 is a valid result (empty list) and must appear in the log.
+ ListTableEvent event = new ListTableEvent("eve", Namespace.of("m", "c", "s"), 0);
+ String[] fields = new SimpleAuditLogV2(event).toString().split("\t", -1);
+ Assertions.assertEquals("{count=0}", fields[7]);
+ }
+
+ @Test
+ public void testListEventRemoteAddressDefaultsToUnknown() {
+ // No RequestContext set — Event subclasses fall back to "unknown".
+ ListTableEvent event = new ListTableEvent("frank", Namespace.of("m", "c", "s"), 4);
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(event);
+
+ Assertions.assertEquals("unknown", log.remoteAddress());
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("unknown", fields[6]);
+ }
+
+ @Test
+ public void testListEventCountMergedWithExistingCustomInfo() {
+ // Verify count and user-defined customInfo both appear in the audit log field.
+ ListTableEvent base = new ListTableEvent("grace", Namespace.of("m", "c", "s"), 9);
+ SimpleAuditLogV2 log =
+ new SimpleAuditLogV2(base) {
+ @Override
+ public Map<String, String> customInfo() {
+ return ImmutableMap.of("env", "prod");
+ }
+ };
+
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertTrue(fields[7].contains("count=9"));
+ Assertions.assertTrue(fields[7].contains("env=prod"));
+ }
+
+ @Test
+ public void testListEventCountKeyCollisionPreservesBothValues() {
+ // When customInfo also contains a "count" key, both values must appear in the output.
+ ListTableEvent base = new ListTableEvent("grace", Namespace.of("m", "c", "s"), 9);
+ SimpleAuditLogV2 log =
+ new SimpleAuditLogV2(base) {
+ @Override
+ public Map<String, String> customInfo() {
+ return ImmutableMap.of("count", "user-value");
+ }
+ };
+
+ String lastField = log.toString().split("\t", -1)[7];
+ // Both the user-supplied value and the event-derived count must be present.
+ Assertions.assertTrue(lastField.contains("count=user-value"), lastField);
+ Assertions.assertTrue(lastField.contains("count=9"), lastField);
+ }
+
+ @Test
+ public void testNonListEventHasEmptyCountField() {
+ // A non-list stub event must not have count in the output.
+ SimpleAuditLogV2 log = new SimpleAuditLogV2(new StubEvent());
+ String[] fields = log.toString().split("\t", -1);
+ Assertions.assertEquals("", fields[7]);
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ public void testDeprecatedConstructorOmitsCountFromLog() {
+ // The deprecated no-count constructor sets resultCount()=-1; the log must not emit {count=-1}.
+ ListTableEvent event = new ListTableEvent("henry", Namespace.of("m", "c", "s"));
+ String[] fields = new SimpleAuditLogV2(event).toString().split("\t", -1);
+ Assertions.assertEquals("", fields[7]);
+ }
+
// ---- stubs ----
static class StubEvent extends Event {
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java
index 0bbb7caff2..eaf01f9fb3 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java
@@ -154,6 +154,7 @@ public class TestCatalogEvent {
Assertions.assertEquals(namespace.toString(), event.identifier().toString());
Assertions.assertEquals(ListCatalogEvent.class, event.getClass());
Assertions.assertEquals(namespace, ((ListCatalogEvent) event).namespace());
+ Assertions.assertEquals(2, ((ListCatalogEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_CATALOG, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -173,6 +174,7 @@ public class TestCatalogEvent {
Assertions.assertEquals(namespace.toString(), event.identifier().toString());
Assertions.assertEquals(ListCatalogEvent.class, event.getClass());
Assertions.assertEquals(namespace, ((ListCatalogEvent) event).namespace());
+ Assertions.assertEquals(3, ((ListCatalogEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_CATALOG, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -318,6 +320,14 @@ public class TestCatalogEvent {
Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListCatalogEventDeprecatedConstructorReturnsNegativeCount() {
+ Namespace namespace = Namespace.of("metalake");
+ ListCatalogEvent event = new ListCatalogEvent("user", namespace);
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
@Test
void testListCatalogFailureEvent() {
Namespace namespace = Namespace.of("metalake", "catalog");
@@ -376,7 +386,13 @@ public class TestCatalogEvent {
.thenReturn(catalog);
when(dispatcher.loadCatalog(any(NameIdentifier.class))).thenReturn(catalog);
when(dispatcher.dropCatalog(any(NameIdentifier.class), anyBoolean())).thenReturn(true);
- when(dispatcher.listCatalogs(any(Namespace.class))).thenReturn(null);
+ when(dispatcher.listCatalogs(any(Namespace.class)))
+ .thenReturn(
+ new NameIdentifier[] {
+ NameIdentifier.of("metalake", "catalog1"), NameIdentifier.of("metalake", "catalog2")
+ });
+ when(dispatcher.listCatalogsInfo(any(Namespace.class)))
+ .thenReturn(new Catalog[] {catalog, catalog, catalog});
when(dispatcher.alterCatalog(any(NameIdentifier.class), any(CatalogChange.class)))
.thenReturn(catalog);
return dispatcher;
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java
index 967758e99b..db200d91f9 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestFilesetEvent.java
@@ -187,6 +187,7 @@ public class TestFilesetEvent {
Assertions.assertEquals(subPath, ((ListFilesEvent) event).subPath());
Assertions.assertEquals(OperationType.LIST_FILESET_FILES, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
+ Assertions.assertEquals(-1, ((ListFilesEvent) event).resultCount());
PreEvent preEvent = dummyEventListener.popPreEvent();
Assertions.assertEquals(ListFilesPreEvent.class, preEvent.getClass());
@@ -395,7 +396,7 @@ public class TestFilesetEvent {
.thenReturn(fileset);
when(dispatcher.loadFileset(any(NameIdentifier.class))).thenReturn(fileset);
when(dispatcher.dropFileset(any(NameIdentifier.class))).thenReturn(true);
- when(dispatcher.listFilesets(any(Namespace.class))).thenReturn(null);
+ when(dispatcher.listFilesets(any(Namespace.class))).thenReturn(new NameIdentifier[0]);
when(dispatcher.alterFileset(any(NameIdentifier.class), any(FilesetChange.class)))
.thenReturn(fileset);
when(dispatcher.getFileLocation(any(NameIdentifier.class), any()))
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestFunctionEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestFunctionEvent.java
index b1a2455aa7..3d776d3934 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestFunctionEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestFunctionEvent.java
@@ -200,6 +200,7 @@ public class TestFunctionEvent {
FunctionInfo[] functionInfos = ((ListFunctionInfosEvent) event).functionInfos();
Assertions.assertEquals(1, functionInfos.length);
checkFunctionInfo(functionInfos[0], function);
+ Assertions.assertEquals(1, ((ListFunctionInfosEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_FUNCTION_INFOS, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -341,7 +342,7 @@ public class TestFunctionEvent {
.thenReturn(function);
when(dispatcher.getFunction(any(NameIdentifier.class))).thenReturn(function);
when(dispatcher.dropFunction(any(NameIdentifier.class))).thenReturn(true);
- when(dispatcher.listFunctions(any(Namespace.class))).thenReturn(null);
+ when(dispatcher.listFunctions(any(Namespace.class))).thenReturn(new NameIdentifier[0]);
when(dispatcher.listFunctionInfos(any(Namespace.class))).thenReturn(new Function[] {function});
when(dispatcher.alterFunction(any(NameIdentifier.class), any(FunctionChange.class)))
.thenReturn(function);
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
index 19f1393d95..fd87bc0a0c 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
@@ -115,6 +115,14 @@ public class TestJobEventDispatcher {
Assertions.assertInstanceOf(ListJobTemplatesEvent.class, postEvent);
Assertions.assertEquals(OperationType.LIST_JOB_TEMPLATES, postEvent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postEvent.operationStatus());
+ Assertions.assertEquals(1, ((ListJobTemplatesEvent) postEvent).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListJobTemplatesEventDeprecatedConstructorReturnsNegativeCount() {
+ ListJobTemplatesEvent event = new ListJobTemplatesEvent("user", "metalake");
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
@@ -320,6 +328,14 @@ public class TestJobEventDispatcher {
Assertions.assertInstanceOf(ListJobsEvent.class, postEvent);
Assertions.assertEquals(OperationType.LIST_JOBS, postEvent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postEvent.operationStatus());
+ Assertions.assertEquals(1, ((ListJobsEvent) postEvent).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListJobsEventDeprecatedConstructorReturnsNegativeCount() {
+ ListJobsEvent event = new ListJobsEvent("user", "metalake", Optional.empty());
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java
index 1a45ed9363..5eeef0f900 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestMetalakeEvent.java
@@ -150,6 +150,7 @@ public class TestMetalakeEvent {
Event event = dummyEventListener.popPostEvent();
Assertions.assertNull(event.identifier());
Assertions.assertEquals(ListMetalakeEvent.class, event.getClass());
+ Assertions.assertEquals(2, ((ListMetalakeEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_METALAKE, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -291,6 +292,27 @@ public class TestMetalakeEvent {
Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListMetalakeEventDeprecatedConstructorReturnsNegativeCount() {
+ ListMetalakeEvent event = new ListMetalakeEvent("user");
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
+ @Test
+ void testListMetalakeEventEmptyList() {
+ MetalakeDispatcher emptyDispatcher = mock(MetalakeDispatcher.class);
+ when(emptyDispatcher.listMetalakes()).thenReturn(new Metalake[] {});
+ MetalakeEventDispatcher emptyEventDispatcher =
+ new MetalakeEventDispatcher(
+ new EventBus(Arrays.asList(dummyEventListener)), emptyDispatcher);
+
+ emptyEventDispatcher.listMetalakes();
+ Event event = dummyEventListener.popPostEvent();
+ Assertions.assertEquals(ListMetalakeEvent.class, event.getClass());
+ Assertions.assertEquals(0, ((ListMetalakeEvent) event).resultCount());
+ }
+
@Test
void testListMetalakeFailureEvent() {
Assertions.assertThrowsExactly(
@@ -326,7 +348,7 @@ public class TestMetalakeEvent {
.thenReturn(metalake);
when(dispatcher.loadMetalake(any(NameIdentifier.class))).thenReturn(metalake);
when(dispatcher.dropMetalake(any(NameIdentifier.class), anyBoolean())).thenReturn(true);
- when(dispatcher.listMetalakes()).thenReturn(null);
+ when(dispatcher.listMetalakes()).thenReturn(new Metalake[] {metalake, metalake});
when(dispatcher.alterMetalake(any(NameIdentifier.class), any(MetalakeChange.class)))
.thenReturn(metalake);
return dispatcher;
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestModelEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestModelEvent.java
index 4c4234e547..02f8353bd0 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestModelEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestModelEvent.java
@@ -907,6 +907,7 @@ class TestModelEvent {
Assertions.assertEquals(existingIdentA, listModelVersionsEvent.identifier());
Assertions.assertEquals(2, listModelVersionsEvent.versions().length);
Assertions.assertArrayEquals(new int[] {1, 2}, listModelVersionsEvent.versions());
+ Assertions.assertEquals(2, listModelVersionsEvent.resultCount());
}
@Test
@@ -933,6 +934,7 @@ class TestModelEvent {
Assertions.assertEquals(existingIdentA, listModelVersionInfosEvent.identifier());
Assertions.assertEquals(1, listModelVersionInfosEvent.versions().length);
checkModelVersionInfo(listModelVersionInfosEvent.versions()[0], firstModelVersion);
+ Assertions.assertEquals(1, listModelVersionInfosEvent.resultCount());
}
@Test
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java
index 6a5b389930..9222466bb4 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPartitionEvent.java
@@ -344,8 +344,8 @@ public class TestPartitionEvent {
.thenReturn(partition);
when(dispatcher.getPartition(any(NameIdentifier.class), any(String.class)))
.thenReturn(partition);
- when(dispatcher.listPartitionNames(any(NameIdentifier.class))).thenReturn(null);
- when(dispatcher.listPartitions(any(NameIdentifier.class))).thenReturn(null);
+ when(dispatcher.listPartitionNames(any(NameIdentifier.class))).thenReturn(new String[0]);
+ when(dispatcher.listPartitions(any(NameIdentifier.class))).thenReturn(new Partition[0]);
return dispatcher;
}
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java
index 5629d21b48..eed972ead6 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestPolicyEvent.java
@@ -119,6 +119,14 @@ public class TestPolicyEvent {
Assertions.assertEquals(ListPoliciesEvent.class, postevent.getClass());
Assertions.assertEquals(OperationType.LIST_POLICY, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(2, ((ListPoliciesEvent) postevent).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListPoliciesEventDeprecatedConstructorReturnsNegativeCount() {
+ ListPoliciesEvent event = new ListPoliciesEvent("user", "metalake");
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
@@ -136,6 +144,14 @@ public class TestPolicyEvent {
Assertions.assertEquals(ListPolicyInfosEvent.class, postevent.getClass());
Assertions.assertEquals(OperationType.LIST_POLICY_INFO, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(2, ((ListPolicyInfosEvent) postevent).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListPolicyInfosEventDeprecatedConstructorReturnsNegativeCount() {
+ ListPolicyInfosEvent event = new ListPolicyInfosEvent("user", "metalake");
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
@@ -292,6 +308,16 @@ public class TestPolicyEvent {
Assertions.assertEquals(
OperationType.LIST_METADATA_OBJECTS_FOR_POLICY, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(1, ((ListMetadataObjectsForPolicyEvent) postevent).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListMetadataObjectsForPolicyEventDeprecatedConstructorReturnsNegativeCount() {
+ NameIdentifier identifier = NameIdentifierUtil.ofPolicy("metalake", policy.name());
+ ListMetadataObjectsForPolicyEvent event =
+ new ListMetadataObjectsForPolicyEvent("user", identifier);
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
@@ -317,6 +343,19 @@ public class TestPolicyEvent {
Assertions.assertEquals(
OperationType.LIST_POLICY_INFOS_FOR_METADATA_OBJECT, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(2, ((ListPolicyInfosForMetadataObjectEvent) postevent).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListPolicyInfosForMetadataObjectEventDeprecatedConstructorReturnsNegativeCount() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+ ListPolicyInfosForMetadataObjectEvent event =
+ new ListPolicyInfosForMetadataObjectEvent("user", "metalake", metadataObject);
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestSchemaEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestSchemaEvent.java
index 1bd48e5f9c..9e2e8fa293 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestSchemaEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestSchemaEvent.java
@@ -113,6 +113,7 @@ public class TestSchemaEvent {
Assertions.assertEquals(namespace.toString(), event.identifier().toString());
Assertions.assertEquals(ListSchemaEvent.class, event.getClass());
Assertions.assertEquals(namespace, ((ListSchemaEvent) event).namespace());
+ Assertions.assertEquals(3, ((ListSchemaEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_SCHEMA, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -233,6 +234,14 @@ public class TestSchemaEvent {
Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListSchemaEventDeprecatedConstructorReturnsNegativeCount() {
+ Namespace namespace = Namespace.of("metalake", "catalog");
+ ListSchemaEvent event = new ListSchemaEvent("user", namespace);
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
@Test
void testListSchemaFailureEvent() {
Namespace namespace = Namespace.of("metalake", "catalog");
@@ -269,7 +278,13 @@ public class TestSchemaEvent {
.thenReturn(schema);
when(dispatcher.loadSchema(any(NameIdentifier.class))).thenReturn(schema);
when(dispatcher.dropSchema(any(NameIdentifier.class), eq(true))).thenReturn(false);
- when(dispatcher.listSchemas(any(Namespace.class))).thenReturn(null);
+ when(dispatcher.listSchemas(any(Namespace.class)))
+ .thenReturn(
+ new NameIdentifier[] {
+ NameIdentifier.of("metalake", "catalog", "schema1"),
+ NameIdentifier.of("metalake", "catalog", "schema2"),
+ NameIdentifier.of("metalake", "catalog", "schema3")
+ });
when(dispatcher.alterSchema(any(NameIdentifier.class), any(SchemaChange.class)))
.thenReturn(schema);
return dispatcher;
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestStatisticsEventDispatcher.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestStatisticsEventDispatcher.java
index 6bf4004f87..76a2610728 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestStatisticsEventDispatcher.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestStatisticsEventDispatcher.java
@@ -100,6 +100,15 @@ public class TestStatisticsEventDispatcher {
Assertions.assertEquals(ListStatisticsEvent.class, event.getClass());
Assertions.assertEquals(OperationType.LIST_STATISTICS, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
+ Assertions.assertEquals(0, ((ListStatisticsEvent) event).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ public void testListStatisticsEventDeprecatedConstructorReturnsNegativeCount() {
+ ListStatisticsEvent event =
+ new ListStatisticsEvent("user", NameIdentifier.of("metalake", "catalog", "db", "table"));
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
@@ -141,6 +150,19 @@ public class TestStatisticsEventDispatcher {
NameIdentifier.of("metalake", "catalog", "db", "table"), event.identifier());
Assertions.assertEquals(ListPartitionStatisticsEvent.class, event.getClass());
Assertions.assertEquals(OperationType.LIST_PARTITION_STATISTICS, event.operationType());
+ Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
+ Assertions.assertEquals(0, ((ListPartitionStatisticsEvent) event).resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ public void testListPartitionStatisticsEventDeprecatedConstructorReturnsNegativeCount() {
+ ListPartitionStatisticsEvent event =
+ new ListPartitionStatisticsEvent(
+ "user",
+ NameIdentifier.of("metalake", "catalog", "db", "table"),
+ PartitionRange.upTo("p1", PartitionRange.BoundType.CLOSED));
+ Assertions.assertEquals(-1, event.resultCount());
}
@Test
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestTableEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestTableEvent.java
index 5d66da9fd3..bd07402602 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestTableEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestTableEvent.java
@@ -194,6 +194,7 @@ public class TestTableEvent {
Assertions.assertEquals(namespace.toString(), event.identifier().toString());
Assertions.assertEquals(ListTableEvent.class, event.getClass());
Assertions.assertEquals(namespace, ((ListTableEvent) event).namespace());
+ Assertions.assertEquals(2, ((ListTableEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_TABLE, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -289,6 +290,14 @@ public class TestTableEvent {
Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListTableEventDeprecatedConstructorReturnsNegativeCount() {
+ Namespace namespace = Namespace.of("metalake", "catalog", "schema");
+ ListTableEvent event = new ListTableEvent("user", namespace);
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
@Test
void testListTableFailureEvent() {
Namespace namespace = Namespace.of("metalake", "catalog");
@@ -348,7 +357,12 @@ public class TestTableEvent {
when(dispatcher.loadTable(any(NameIdentifier.class))).thenReturn(table);
when(dispatcher.dropTable(any(NameIdentifier.class))).thenReturn(true);
when(dispatcher.purgeTable(any(NameIdentifier.class))).thenReturn(true);
- when(dispatcher.listTables(any(Namespace.class))).thenReturn(null);
+ when(dispatcher.listTables(any(Namespace.class)))
+ .thenReturn(
+ new NameIdentifier[] {
+ NameIdentifier.of("metalake", "catalog", "schema", "t1"),
+ NameIdentifier.of("metalake", "catalog", "schema", "t2")
+ });
when(dispatcher.alterTable(any(NameIdentifier.class), any(TableChange.class)))
.thenReturn(table);
return dispatcher;
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestTagEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestTagEvent.java
index 23eb638336..b68d4dd395 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestTagEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestTagEvent.java
@@ -204,6 +204,7 @@ public class TestTagEvent {
Assertions.assertEquals(ListMetadataObjectsForTagEvent.class, postevent.getClass());
Assertions.assertEquals(OperationType.LIST_METADATA_OBJECTS_FOR_TAG, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(1, ((ListMetadataObjectsForTagEvent) postevent).resultCount());
}
@Test
@@ -227,6 +228,7 @@ public class TestTagEvent {
Assertions.assertEquals(ListTagsForMetadataObjectEvent.class, postevent.getClass());
Assertions.assertEquals(OperationType.LIST_TAGS_FOR_METADATA_OBJECT, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(2, ((ListTagsForMetadataObjectEvent) postevent).resultCount());
}
@Test
@@ -252,6 +254,7 @@ public class TestTagEvent {
Assertions.assertEquals(
OperationType.LIST_TAGS_INFO_FOR_METADATA_OBJECT, postevent.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, postevent.operationStatus());
+ Assertions.assertEquals(2, ((ListTagsInfoForMetadataObjectEvent) postevent).resultCount());
}
@Test
@@ -515,6 +518,38 @@ public class TestTagEvent {
Assertions.assertEquals(OperationStatus.FAILURE, event.operationStatus());
}
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListMetadataObjectsForTagEventDeprecatedConstructor() {
+ ListMetadataObjectsForTagEvent event =
+ new ListMetadataObjectsForTagEvent("user", "metalake", "tag");
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListTagsForMetadataObjectEventDeprecatedConstructor() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+ ListTagsForMetadataObjectEvent event =
+ new ListTagsForMetadataObjectEvent("user", "metalake", metadataObject);
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testListTagsInfoForMetadataObjectEventDeprecatedConstructor() {
+ MetadataObject metadataObject =
+ NameIdentifierUtil.toMetadataObject(
+ NameIdentifierUtil.ofCatalog("metalake", "catalog_for_test"),
+ Entity.EntityType.CATALOG);
+ ListTagsInfoForMetadataObjectEvent event =
+ new ListTagsInfoForMetadataObjectEvent("user", "metalake", metadataObject);
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
private Tag mockTag() {
Tag tag = mock(Tag.class);
when(tag.name()).thenReturn("tag");
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestTopicEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestTopicEvent.java
index 032a770018..485aae2b51 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestTopicEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestTopicEvent.java
@@ -266,7 +266,7 @@ public class TestTopicEvent {
.thenReturn(topic);
when(dispatcher.loadTopic(any(NameIdentifier.class))).thenReturn(topic);
when(dispatcher.dropTopic(any(NameIdentifier.class))).thenReturn(true);
- when(dispatcher.listTopics(any(Namespace.class))).thenReturn(null);
+ when(dispatcher.listTopics(any(Namespace.class))).thenReturn(new NameIdentifier[0]);
when(dispatcher.alterTopic(any(NameIdentifier.class), any(TopicChange.class)))
.thenReturn(topic);
return dispatcher;
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestViewEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestViewEvent.java
index 1d9529ce22..203cc201ee 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestViewEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestViewEvent.java
@@ -177,6 +177,7 @@ public class TestViewEvent {
Assertions.assertEquals(namespace.toString(), event.identifier().toString());
Assertions.assertEquals(ListViewEvent.class, event.getClass());
Assertions.assertEquals(namespace, ((ListViewEvent) event).namespace());
+ Assertions.assertEquals(1, ((ListViewEvent) event).resultCount());
Assertions.assertEquals(OperationType.LIST_VIEW, event.operationType());
Assertions.assertEquals(OperationStatus.SUCCESS, event.operationStatus());
@@ -311,7 +312,9 @@ public class TestViewEvent {
.thenReturn(view);
when(d.loadView(any(NameIdentifier.class))).thenReturn(view);
when(d.dropView(any(NameIdentifier.class))).thenReturn(true);
- when(d.listViews(any(Namespace.class))).thenReturn(null);
+ when(d.listViews(any(Namespace.class)))
+ .thenReturn(
+ new NameIdentifier[] {NameIdentifier.of("metalake", "catalog", "schema", "v1")});
when(d.alterView(any(NameIdentifier.class), any(ViewChange.class))).thenReturn(view);
return d;
}
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceEventDispatcher.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceEventDispatcher.java
index 1329da2ddf..965b304270 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceEventDispatcher.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergNamespaceEventDispatcher.java
@@ -19,6 +19,7 @@
package org.apache.gravitino.iceberg.service.dispatcher;
+import java.util.List;
import java.util.Optional;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.iceberg.service.IcebergRESTUtils;
@@ -191,16 +192,18 @@ public class IcebergNamespaceEventDispatcher implements IcebergNamespaceOperatio
metalakeName, context.catalogName(), parentNamespace);
eventBus.dispatchEvent(new IcebergListNamespacesPreEvent(context, nameIdentifier));
- ListNamespacesResponse listResponse;
try {
- listResponse = operationDispatcher.listNamespaces(context, parentNamespace);
+ ListNamespacesResponse listResponse =
+ operationDispatcher.listNamespaces(context, parentNamespace);
+ List<Namespace> namespaces = listResponse.namespaces();
+ eventBus.dispatchEvent(
+ new IcebergListNamespacesEvent(
+ context, nameIdentifier, namespaces != null ? namespaces.size() : -1));
+ return listResponse;
} catch (Exception e) {
eventBus.dispatchEvent(new IcebergListNamespacesFailureEvent(context, nameIdentifier, e));
throw e;
}
-
- eventBus.dispatchEvent(new IcebergListNamespacesEvent(context, nameIdentifier));
- return listResponse;
}
@Override
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java
index 65744546fa..9a6cb21ee2 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergTableEventDispatcher.java
@@ -19,6 +19,7 @@
package org.apache.gravitino.iceberg.service.dispatcher;
+import java.util.List;
import java.util.Optional;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.iceberg.service.IcebergRESTUtils;
@@ -191,15 +192,18 @@ public class IcebergTableEventDispatcher implements IcebergTableOperationDispatc
NameIdentifier gravitinoNameIdentifier =
IcebergRESTUtils.getGravitinoNameIdentifier(metalakeName, context.catalogName(), namespace);
eventBus.dispatchEvent(new IcebergListTablePreEvent(context, gravitinoNameIdentifier));
- ListTablesResponse listTablesResponse;
try {
- listTablesResponse = icebergTableOperationDispatcher.listTable(context, namespace);
+ ListTablesResponse listTablesResponse =
+ icebergTableOperationDispatcher.listTable(context, namespace);
+ List<TableIdentifier> identifiers = listTablesResponse.identifiers();
+ eventBus.dispatchEvent(
+ new IcebergListTableEvent(
+ context, gravitinoNameIdentifier, identifiers != null ? identifiers.size() : -1));
+ return listTablesResponse;
} catch (Exception e) {
eventBus.dispatchEvent(new IcebergListTableFailureEvent(context, gravitinoNameIdentifier, e));
throw e;
}
- eventBus.dispatchEvent(new IcebergListTableEvent(context, gravitinoNameIdentifier));
- return listTablesResponse;
}
@Override
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewEventDispatcher.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewEventDispatcher.java
index 0c3d78f4e4..9ea7b8f040 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewEventDispatcher.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/dispatcher/IcebergViewEventDispatcher.java
@@ -19,6 +19,7 @@
package org.apache.gravitino.iceberg.service.dispatcher;
+import java.util.List;
import java.util.Optional;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.iceberg.service.IcebergRESTUtils;
@@ -174,15 +175,18 @@ public class IcebergViewEventDispatcher implements IcebergViewOperationDispatche
NameIdentifier gravitinoNameIdentifier =
IcebergRESTUtils.getGravitinoNameIdentifier(metalakeName, context.catalogName(), namespace);
eventBus.dispatchEvent(new IcebergListViewPreEvent(context, gravitinoNameIdentifier));
- ListTablesResponse listViewsResponse;
try {
- listViewsResponse = icebergViewOperationDispatcher.listView(context, namespace);
+ ListTablesResponse listViewsResponse =
+ icebergViewOperationDispatcher.listView(context, namespace);
+ List<TableIdentifier> identifiers = listViewsResponse.identifiers();
+ eventBus.dispatchEvent(
+ new IcebergListViewEvent(
+ context, gravitinoNameIdentifier, identifiers != null ? identifiers.size() : -1));
+ return listViewsResponse;
} catch (Exception e) {
eventBus.dispatchEvent(new IcebergListViewFailureEvent(context, gravitinoNameIdentifier, e));
throw e;
}
- eventBus.dispatchEvent(new IcebergListViewEvent(context, gravitinoNameIdentifier));
- return listViewsResponse;
}
@Override
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListNamespacesEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListNamespacesEvent.java
index c6bf6fdd0c..f724ddeb91 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListNamespacesEvent.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListNamespacesEvent.java
@@ -25,15 +25,48 @@ import org.apache.gravitino.annotation.DeveloperApi;
/**
* Represent an event after listing Iceberg namespace successfully.
*
- * <p>To optimize memory usage and avoid the potential overhead associated with storing a large
- * number of namespaces directly within the ListNamespaceEvent, the actual namespaces listed are not
- * maintained in this event.
+ * <p>Only the result count is stored rather than the full list of namespaces to avoid excessive
+ * memory usage in environments with large namespace listings.
*/
@DeveloperApi
-public class IcebergListNamespacesEvent extends IcebergNamespaceEvent {
+public class IcebergListNamespacesEvent extends IcebergNamespaceEvent implements ListEvent {
+
+ private final int namespaceCount;
+
+ /**
+ * Constructs an instance of {@code IcebergListNamespacesEvent}.
+ *
+ * @param icebergRequestContext the request context.
+ * @param nameIdentifier the parent namespace identifier.
+ * @param namespaceCount the number of namespaces returned by the list operation.
+ */
public IcebergListNamespacesEvent(
- IcebergRequestContext icebergRequestContext, NameIdentifier nameIdentifier) {
+ IcebergRequestContext icebergRequestContext,
+ NameIdentifier nameIdentifier,
+ int namespaceCount) {
super(icebergRequestContext, nameIdentifier);
+ this.namespaceCount = namespaceCount;
+ }
+
+ /**
+ * Constructs an instance of {@code IcebergListNamespacesEvent} without a count.
+ *
+ * @param icebergRequestContext the request context.
+ * @param nameIdentifier the parent namespace identifier.
+ * @deprecated Use {@link #IcebergListNamespacesEvent(IcebergRequestContext, NameIdentifier, int)}
+ * instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public IcebergListNamespacesEvent(
+ IcebergRequestContext icebergRequestContext, NameIdentifier nameIdentifier) {
+ this(icebergRequestContext, nameIdentifier, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return namespaceCount;
}
@Override
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java
index 3a7d2690bb..908b36b527 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListTableEvent.java
@@ -25,15 +25,48 @@ import org.apache.gravitino.annotation.DeveloperApi;
/**
* Represent an event after listing Iceberg table successfully.
*
- * <p>To optimize memory usage and avoid the potential overhead associated with storing a large
- * number of tables directly within the ListTableEvent, the actual tables listed are not maintained
- * in this event.
+ * <p>Only the result count is stored rather than the full list of identifiers to avoid excessive
+ * memory usage in environments with large table listings.
*/
@DeveloperApi
-public class IcebergListTableEvent extends IcebergTableEvent {
+public class IcebergListTableEvent extends IcebergTableEvent implements ListEvent {
+
+ private final int tableCount;
+
+ /**
+ * Constructs an instance of {@code IcebergListTableEvent}.
+ *
+ * @param icebergRequestContext the request context.
+ * @param resourceIdentifier the namespace identifier from which tables were listed.
+ * @param tableCount the number of tables returned by the list operation.
+ */
public IcebergListTableEvent(
- IcebergRequestContext icebergRequestContext, NameIdentifier resourceIdentifier) {
+ IcebergRequestContext icebergRequestContext,
+ NameIdentifier resourceIdentifier,
+ int tableCount) {
super(icebergRequestContext, resourceIdentifier);
+ this.tableCount = tableCount;
+ }
+
+ /**
+ * Constructs an instance of {@code IcebergListTableEvent} without a count.
+ *
+ * @param icebergRequestContext the request context.
+ * @param resourceIdentifier the namespace identifier from which tables were listed.
+ * @deprecated Use {@link #IcebergListTableEvent(IcebergRequestContext, NameIdentifier, int)}
+ * instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public IcebergListTableEvent(
+ IcebergRequestContext icebergRequestContext, NameIdentifier resourceIdentifier) {
+ this(icebergRequestContext, resourceIdentifier, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return tableCount;
}
@Override
diff --git a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListViewEvent.java b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListViewEvent.java
index 6397edb1f8..d82e923db0 100644
--- a/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListViewEvent.java
+++ b/iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/listener/api/event/IcebergListViewEvent.java
@@ -25,15 +25,46 @@ import org.apache.gravitino.annotation.DeveloperApi;
/**
* Represent an event after listing Iceberg view successfully.
*
- * <p>To optimize memory usage and avoid the potential overhead associated with storing a large
- * number of views directly within the ListViewEvent, the actual views listed are not maintained in
- * this event.
+ * <p>Only the result count is stored rather than the full list of identifiers to avoid excessive
+ * memory usage in environments with large view listings.
*/
@DeveloperApi
-public class IcebergListViewEvent extends IcebergViewEvent {
+public class IcebergListViewEvent extends IcebergViewEvent implements ListEvent {
+
+ private final int viewCount;
+
+ /**
+ * Constructs an instance of {@code IcebergListViewEvent}.
+ *
+ * @param icebergRequestContext the request context.
+ * @param viewIdentifier the namespace identifier from which views were listed.
+ * @param viewCount the number of views returned by the list operation.
+ */
public IcebergListViewEvent(
- IcebergRequestContext icebergRequestContext, NameIdentifier viewIdentifier) {
+ IcebergRequestContext icebergRequestContext, NameIdentifier viewIdentifier, int viewCount) {
super(icebergRequestContext, viewIdentifier);
+ this.viewCount = viewCount;
+ }
+
+ /**
+ * Constructs an instance of {@code IcebergListViewEvent} without a count.
+ *
+ * @param icebergRequestContext the request context.
+ * @param viewIdentifier the namespace identifier from which views were listed.
+ * @deprecated Use {@link #IcebergListViewEvent(IcebergRequestContext, NameIdentifier, int)}
+ * instead.
+ */
+ @Deprecated
+ @SuppressWarnings("InlineMeSuggester")
+ public IcebergListViewEvent(
+ IcebergRequestContext icebergRequestContext, NameIdentifier viewIdentifier) {
+ this(icebergRequestContext, viewIdentifier, -1);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int resultCount() {
+ return viewCount;
}
@Override
diff --git a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
index 86e6b3e38d..fcda9dd3f9 100644
--- a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
+++ b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergNamespaceOperations.java
@@ -27,6 +27,7 @@ import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.iceberg.service.IcebergRESTUtils;
import org.apache.gravitino.iceberg.service.extension.DummyCredentialProvider;
@@ -37,6 +38,9 @@ import org.apache.gravitino.listener.api.event.IcebergCreateNamespacePreEvent;
import org.apache.gravitino.listener.api.event.IcebergDropNamespaceEvent;
import org.apache.gravitino.listener.api.event.IcebergDropNamespaceFailureEvent;
import org.apache.gravitino.listener.api.event.IcebergDropNamespacePreEvent;
+import org.apache.gravitino.listener.api.event.IcebergListNamespacesEvent;
+import org.apache.gravitino.listener.api.event.IcebergListNamespacesFailureEvent;
+import org.apache.gravitino.listener.api.event.IcebergListNamespacesPreEvent;
import org.apache.gravitino.listener.api.event.IcebergLoadNamespaceEvent;
import org.apache.gravitino.listener.api.event.IcebergLoadNamespaceFailureEvent;
import org.apache.gravitino.listener.api.event.IcebergLoadNamespacePreEvent;
@@ -45,6 +49,7 @@ import org.apache.gravitino.listener.api.event.IcebergNamespaceExistsPreEvent;
import org.apache.gravitino.listener.api.event.IcebergRegisterTableEvent;
import org.apache.gravitino.listener.api.event.IcebergRegisterTableFailureEvent;
import org.apache.gravitino.listener.api.event.IcebergRegisterTablePreEvent;
+import org.apache.gravitino.listener.api.event.IcebergRequestContext;
import org.apache.gravitino.listener.api.event.IcebergUpdateNamespaceEvent;
import org.apache.gravitino.listener.api.event.IcebergUpdateNamespaceFailureEvent;
import org.apache.gravitino.listener.api.event.IcebergUpdateNamespacePreEvent;
@@ -258,7 +263,14 @@ public class TestIcebergNamespaceOperations extends IcebergNamespaceTestBase {
void testListNamespace(String prefix) {
setUrlPathWithPrefix(prefix);
dropAllExistingNamespace();
+
+ dummyEventListener.clearEvent();
verifyListNamespaceSucc(Optional.empty(), Arrays.asList());
+ Assertions.assertTrue(
+ dummyEventListener.popPreEvent() instanceof IcebergListNamespacesPreEvent);
+ Event emptyListEvent = dummyEventListener.popPostEvent();
+ Assertions.assertTrue(emptyListEvent instanceof IcebergListNamespacesEvent);
+ Assertions.assertEquals(0, ((IcebergListNamespacesEvent) emptyListEvent).resultCount());
doCreateNamespace(Namespace.of("list_foo1"));
doCreateNamespace(Namespace.of("list_foo2"));
@@ -267,18 +279,40 @@ public class TestIcebergNamespaceOperations extends IcebergNamespaceTestBase {
doCreateNamespace(Namespace.of("list_foo3", "a", "z"));
doCreateNamespace(Namespace.of("list_foo3", "a", "y"));
+ dummyEventListener.clearEvent();
verifyListNamespaceSucc(Optional.empty(), Arrays.asList("list_foo1", "list_foo2", "list_foo3"));
+ Assertions.assertTrue(
+ dummyEventListener.popPreEvent() instanceof IcebergListNamespacesPreEvent);
+ Event listEvent = dummyEventListener.popPostEvent();
+ Assertions.assertTrue(listEvent instanceof IcebergListNamespacesEvent);
+ Assertions.assertEquals(3, ((IcebergListNamespacesEvent) listEvent).resultCount());
+
verifyListNamespaceSucc(
Optional.of(Namespace.of("list_foo3")), Arrays.asList("list_foo3.a", "list_foo3.b"));
verifyListNamespaceSucc(
Optional.of(Namespace.of("list_foo3", "a")),
Arrays.asList("list_foo3.a.y", "list_foo3.a.z"));
+ dummyEventListener.clearEvent();
verifyListNamespaceFail(Optional.of(Namespace.of("list_fooxx")), 404);
+ Assertions.assertTrue(
+ dummyEventListener.popPreEvent() instanceof IcebergListNamespacesPreEvent);
+ Assertions.assertTrue(
+ dummyEventListener.popPostEvent() instanceof IcebergListNamespacesFailureEvent);
+
verifyListNamespaceFail(Optional.of(Namespace.of("list_foo3", "c")), 404);
verifyListNamespaceFail(Optional.of(Namespace.of("list_foo3", "a", "x")), 404);
}
+ @Test
+ @SuppressWarnings("deprecation")
+ void testIcebergListNamespacesEventDeprecatedConstructorReturnsNegativeCount() {
+ IcebergListNamespacesEvent event =
+ new IcebergListNamespacesEvent(
+ Mockito.mock(IcebergRequestContext.class), NameIdentifier.of("metalake", "catalog"));
+ Assertions.assertEquals(-1, event.resultCount());
+ }
+
@Test
void testUpdateNamespace() {
verifyCreateNamespaceSucc("update_foo1");
diff --git a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergTableOperations.java b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergTableOperations.java
index 3bf5e46122..4025fe26e2 100644
--- a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergTableOperations.java
+++ b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergTableOperations.java
@@ -35,6 +35,7 @@ import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.credential.Credential;
import org.apache.gravitino.iceberg.service.extension.DummyCredentialProvider;
import org.apache.gravitino.listener.api.event.Event;
@@ -56,6 +57,7 @@ import org.apache.gravitino.listener.api.event.IcebergPlanTableScanPreEvent;
import org.apache.gravitino.listener.api.event.IcebergRenameTableEvent;
import org.apache.gravitino.listener.api.event.IcebergRenameTableFailureEvent;
import org.apache.gravitino.listener.api.event.IcebergRenameTablePreEvent;
+import org.apache.gravitino.listener.api.event.IcebergRequestContext;
import org.apache.gravitino.listener.api.event.IcebergTableExistsEvent;
import org.apache.gravitino.listener.api.event.IcebergTableExistsPreEvent;
import org.apache.gravitino.listener.api.event.IcebergUpdateTableEvent;
@@ -90,6 +92,7 @@ import org.apache.iceberg.util.JsonUtil;
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
@@ -295,7 +298,9 @@ public class TestIcebergTableOperations extends IcebergNamespaceTestBase {
dummyEventListener.clearEvent();
verifyListTableSucc(namespace, ImmutableSet.of("list_foo1", "list_foo2"));
Assertions.assertTrue(dummyEventListener.popPreEvent() instanceof IcebergListTablePreEvent);
- Assertions.assertTrue(dummyEventListener.popPostEvent() instanceof IcebergListTableEvent);
+ Event listTablePostEvent = dummyEventListener.popPostEvent();
+ Assertions.assertTrue(listTablePostEvent instanceof IcebergListTableEvent);
+ Assertions.assertEquals(2, ((IcebergListTableEvent) listTablePostEvent).resultCount());
}
@ParameterizedTest
@@ -1046,4 +1051,14 @@ public class TestIcebergTableOperations extends IcebergNamespaceTestBase {
allTableResponse.tableMetadata().snapshots().size(),
"Default load and snapshots=all should return the same number of snapshots");
}
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testIcebergListTableEventDeprecatedConstructorReturnsNegativeCount() {
+ IcebergListTableEvent event =
+ new IcebergListTableEvent(
+ Mockito.mock(IcebergRequestContext.class),
+ NameIdentifier.of("metalake", "catalog", "schema"));
+ Assertions.assertEquals(-1, event.resultCount());
+ }
}
diff --git a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergViewOperations.java b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergViewOperations.java
index e70fa0efea..2c47a44739 100644
--- a/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergViewOperations.java
+++ b/iceberg/iceberg-rest-server/src/test/java/org/apache/gravitino/iceberg/service/rest/TestIcebergViewOperations.java
@@ -29,6 +29,7 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.listener.api.event.Event;
import org.apache.gravitino.listener.api.event.IcebergCreateViewEvent;
import org.apache.gravitino.listener.api.event.IcebergCreateViewFailureEvent;
@@ -48,6 +49,7 @@ import org.apache.gravitino.listener.api.event.IcebergRenameViewPreEvent;
import org.apache.gravitino.listener.api.event.IcebergReplaceViewEvent;
import org.apache.gravitino.listener.api.event.IcebergReplaceViewFailureEvent;
import org.apache.gravitino.listener.api.event.IcebergReplaceViewPreEvent;
+import org.apache.gravitino.listener.api.event.IcebergRequestContext;
import org.apache.gravitino.listener.api.event.IcebergViewExistsEvent;
import org.apache.gravitino.listener.api.event.IcebergViewExistsPreEvent;
import org.apache.gravitino.listener.api.event.OperationType;
@@ -70,6 +72,7 @@ import org.apache.iceberg.view.ViewMetadata;
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
@@ -126,7 +129,9 @@ public class TestIcebergViewOperations extends IcebergNamespaceTestBase {
dummyEventListener.clearEvent();
verifyLisViewSucc(namespace, ImmutableSet.of("list_foo1", "list_foo2"));
Assertions.assertTrue(dummyEventListener.popPreEvent() instanceof IcebergListViewPreEvent);
- Assertions.assertTrue(dummyEventListener.popPostEvent() instanceof IcebergListViewEvent);
+ Event listViewPostEvent = dummyEventListener.popPostEvent();
+ Assertions.assertTrue(listViewPostEvent instanceof IcebergListViewEvent);
+ Assertions.assertEquals(2, ((IcebergListViewEvent) listViewPostEvent).resultCount());
}
@ParameterizedTest
@@ -452,4 +457,14 @@ public class TestIcebergViewOperations extends IcebergNamespaceTestBase {
Response response = doRenameView(ns, source, dest);
Assertions.assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testIcebergListViewEventDeprecatedConstructorReturnsNegativeCount() {
+ IcebergListViewEvent event =
+ new IcebergListViewEvent(
+ Mockito.mock(IcebergRequestContext.class),
+ NameIdentifier.of("metalake", "catalog", "schema"));
+ Assertions.assertEquals(-1, event.resultCount());
+ }
}