From 7dd31fa4bd77ea48084d6c9104c5d9daf0b05b6e Mon Sep 17 00:00:00 2001 From: pancx Date: Sun, 29 Dec 2024 15:15:31 +0800 Subject: [PATCH 1/5] [#6030] fix(CLI): Fix Setting the same tags multiple times in the Gravitino CLi gives unexpected output Fix the error information when Setting the same tags multiple times in the Gravitino CLi. --- .../gravitino/cli/commands/TagEntity.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java index d2d1cbbe18f..976c14fe9cb 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -19,6 +19,10 @@ package org.apache.gravitino.cli.commands; +import com.google.common.base.Joiner; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import org.apache.gravitino.Catalog; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.Schema; @@ -32,6 +36,7 @@ import org.apache.gravitino.rel.Table; public class TagEntity extends Command { + public static final Joiner COMMA_JOINER = Joiner.on(", ").skipNulls(); protected final String metalake; protected final FullName name; protected final String[] tags; @@ -72,17 +77,20 @@ public void handle() { .loadCatalog(catalog) .asTableCatalog() .loadTable(NameIdentifier.of(schema, table)); + checkTags(gTable); tagsToAdd = gTable.supportsTags().associateTags(tags, null); entity = table; } else if (name.hasSchemaName()) { String catalog = name.getCatalogName(); String schema = name.getSchemaName(); Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); + checkTags(gSchema); tagsToAdd = gSchema.supportsTags().associateTags(tags, null); entity = schema; } else if (name.hasCatalogName()) { String catalog = name.getCatalogName(); Catalog gCatalog = client.loadCatalog(catalog); + checkTags(gCatalog); tagsToAdd = gCatalog.supportsTags().associateTags(tags, null); entity = catalog; } @@ -102,4 +110,33 @@ public void handle() { System.out.println(entity + " now tagged with " + all); } + + private void checkTags(Table gTable) { + String[] associatedTags = gTable.supportsTags().listTags(); + checkRedundantTags(associatedTags); + } + + private void checkTags(Schema gSchema) { + String[] associatedTags = gSchema.supportsTags().listTags(); + checkRedundantTags(associatedTags); + } + + private void checkTags(Catalog gCatalog) { + String[] associatedTags = gCatalog.supportsTags().listTags(); + checkRedundantTags(associatedTags); + } + + private void checkRedundantTags(String[] associatedTags) { + List redundantTags = + Arrays.stream(associatedTags) + .filter(x -> Arrays.asList(tags).contains(x)) + .collect(Collectors.toList()); + if (!redundantTags.isEmpty()) + exitWithError( + "[" + + COMMA_JOINER.join(redundantTags) + + "]" + + " are(is) already associated with " + + name.getName()); + } } From 4331e0dac8905ba423f6628c22b96b13723452ab Mon Sep 17 00:00:00 2001 From: pancx Date: Tue, 31 Dec 2024 13:53:39 +0800 Subject: [PATCH 2/5] [#6030] fix(CLI): Fix Setting the same tags multiple times in the Gravitino CLi gives unexpected output fix some error --- .../gravitino/cli/commands/TagEntity.java | 39 ++----------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java index 976c14fe9cb..9e288319b05 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -20,9 +20,6 @@ package org.apache.gravitino.cli.commands; import com.google.common.base.Joiner; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; import org.apache.gravitino.Catalog; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.Schema; @@ -33,6 +30,7 @@ import org.apache.gravitino.exceptions.NoSuchMetalakeException; import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.exceptions.TagAlreadyAssociatedException; import org.apache.gravitino.rel.Table; public class TagEntity extends Command { @@ -77,20 +75,17 @@ public void handle() { .loadCatalog(catalog) .asTableCatalog() .loadTable(NameIdentifier.of(schema, table)); - checkTags(gTable); tagsToAdd = gTable.supportsTags().associateTags(tags, null); entity = table; } else if (name.hasSchemaName()) { String catalog = name.getCatalogName(); String schema = name.getSchemaName(); Schema gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); - checkTags(gSchema); tagsToAdd = gSchema.supportsTags().associateTags(tags, null); entity = schema; } else if (name.hasCatalogName()) { String catalog = name.getCatalogName(); Catalog gCatalog = client.loadCatalog(catalog); - checkTags(gCatalog); tagsToAdd = gCatalog.supportsTags().associateTags(tags, null); entity = catalog; } @@ -102,6 +97,9 @@ public void handle() { exitWithError(ErrorMessages.UNKNOWN_SCHEMA); } catch (NoSuchTableException err) { exitWithError(ErrorMessages.UNKNOWN_TABLE); + } catch (TagAlreadyAssociatedException tagAlreadyAssociatedException) { + exitWithError( + "[" + COMMA_JOINER.join(tags) + "]" + " are already associated with " + name.getName()); } catch (Exception exp) { exitWithError(exp.getMessage()); } @@ -110,33 +108,4 @@ public void handle() { System.out.println(entity + " now tagged with " + all); } - - private void checkTags(Table gTable) { - String[] associatedTags = gTable.supportsTags().listTags(); - checkRedundantTags(associatedTags); - } - - private void checkTags(Schema gSchema) { - String[] associatedTags = gSchema.supportsTags().listTags(); - checkRedundantTags(associatedTags); - } - - private void checkTags(Catalog gCatalog) { - String[] associatedTags = gCatalog.supportsTags().listTags(); - checkRedundantTags(associatedTags); - } - - private void checkRedundantTags(String[] associatedTags) { - List redundantTags = - Arrays.stream(associatedTags) - .filter(x -> Arrays.asList(tags).contains(x)) - .collect(Collectors.toList()); - if (!redundantTags.isEmpty()) - exitWithError( - "[" - + COMMA_JOINER.join(redundantTags) - + "]" - + " are(is) already associated with " - + name.getName()); - } } From 61e1b1d555f279b10a6a09ae2a4b687508135c0f Mon Sep 17 00:00:00 2001 From: pancx Date: Wed, 1 Jan 2025 11:12:43 +0800 Subject: [PATCH 3/5] [#6030] fix(CLI): Fix Setting the same tags multiple times in the Gravitino CLi gives unexpected output fix some error, remove long error name and fix the error info. --- .../java/org/apache/gravitino/cli/commands/TagEntity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java index 9e288319b05..a9dacf6d891 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -97,9 +97,8 @@ public void handle() { exitWithError(ErrorMessages.UNKNOWN_SCHEMA); } catch (NoSuchTableException err) { exitWithError(ErrorMessages.UNKNOWN_TABLE); - } catch (TagAlreadyAssociatedException tagAlreadyAssociatedException) { - exitWithError( - "[" + COMMA_JOINER.join(tags) + "]" + " are already associated with " + name.getName()); + } catch (TagAlreadyAssociatedException err) { + exitWithError("Tags are already associated with " + name.getName()); } catch (Exception exp) { exitWithError(exp.getMessage()); } From 417afa18b1dcb499e4d705f5749c8e3934ee0f4a Mon Sep 17 00:00:00 2001 From: pancx Date: Wed, 1 Jan 2025 11:13:40 +0800 Subject: [PATCH 4/5] [#6030] fix(CLI): Fix Setting the same tags multiple times in the Gravitino CLi gives unexpected output fix some error. --- .../main/java/org/apache/gravitino/cli/commands/TagEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java index a9dacf6d891..5aabc2d89d4 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -34,7 +34,6 @@ import org.apache.gravitino.rel.Table; public class TagEntity extends Command { - public static final Joiner COMMA_JOINER = Joiner.on(", ").skipNulls(); protected final String metalake; protected final FullName name; protected final String[] tags; From d660c12cc64d3293d29005fcd572507a61d8d5ce Mon Sep 17 00:00:00 2001 From: pancx Date: Thu, 2 Jan 2025 11:47:16 +0800 Subject: [PATCH 5/5] [#6030] fix(CLI): Fix Setting the same tags multiple times in the Gravitino CLi gives unexpected output fix some error. --- .../main/java/org/apache/gravitino/cli/commands/TagEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java index 5aabc2d89d4..7bc8ec37649 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -19,7 +19,6 @@ package org.apache.gravitino.cli.commands; -import com.google.common.base.Joiner; import org.apache.gravitino.Catalog; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.Schema;