From f7d12412b5c4de0401e86245e78c7112b29b1b9d Mon Sep 17 00:00:00 2001 From: pancx Date: Sun, 22 Dec 2024 21:24:09 +0800 Subject: [PATCH 1/3] [#5924] improvement(CLI): fix cli list command produce no outputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using the list command, it’s helpful to provide a friendly reminder if no data is retrieve. --- .../java/org/apache/gravitino/cli/commands/ListAllTags.java | 2 +- .../org/apache/gravitino/cli/commands/ListCatalogs.java | 6 +++++- .../org/apache/gravitino/cli/commands/ListFilesets.java | 2 +- .../java/org/apache/gravitino/cli/commands/ListGroups.java | 2 +- .../org/apache/gravitino/cli/commands/ListMetalakes.java | 6 +++++- .../java/org/apache/gravitino/cli/commands/ListRoles.java | 2 +- .../java/org/apache/gravitino/cli/commands/ListSchema.java | 2 +- .../java/org/apache/gravitino/cli/commands/ListTables.java | 5 ++++- .../java/org/apache/gravitino/cli/commands/ListTopics.java | 5 ++++- 9 files changed, 23 insertions(+), 9 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java index fa6c74c7afa..5baa329fef1 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java @@ -53,7 +53,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = String.join(",", tags); + String all = tags.length == 0 ? "No tags exists." : String.join(",", tags); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java index e6aaf811ec9..c2dabc43cdc 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -49,7 +49,11 @@ public void handle() { try { GravitinoClient client = buildClient(metalake); catalogs = client.listCatalogsInfo(); - output(catalogs); + if (catalogs.length == 0) { + System.out.println("No catalogs exists."); + } else { + output(catalogs); + } } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (Exception exp) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java index 34839f683c5..004f63add36 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java @@ -71,7 +71,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = Joiner.on(",").join(filesets); + String all = filesets.length == 0 ? "No filesets exists." : Joiner.on(",").join(filesets); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java index fd9009a755a..00328104e9e 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java @@ -53,7 +53,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = String.join(",", groups); + String all = groups.length == 0 ? "No groups exists." : String.join(",", groups); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java index ee5ac81d646..1e5ac5d914d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -43,7 +43,11 @@ public void handle() { try { GravitinoAdminClient client = buildAdminClient(); metalakes = client.listMetalakes(); - output(metalakes); + if (metalakes.length == 0) { + System.out.println("No metalakes exists."); + } else { + output(metalakes); + } } catch (Exception exp) { exitWithError(exp.getMessage()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java index a7bb1cd20f7..8158fcbaa05 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java @@ -53,7 +53,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = String.join(",", roles); + String all = roles.length == 0 ? "No roles exists." : String.join(",", roles); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java index cf5fe487cc8..0098cf182c1 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java @@ -60,7 +60,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = Joiner.on(",").join(schemas); + String all = schemas.length == 0 ? "No schemas exists." : Joiner.on(",").join(schemas); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java index e6afb9b51c0..117757f8e5b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java @@ -61,7 +61,10 @@ public void handle() { tableNames.add(tables[i].name()); } - String all = Joiner.on(System.lineSeparator()).join(tableNames); + String all = + tableNames.isEmpty() + ? "No tables exists." + : Joiner.on(System.lineSeparator()).join(tableNames); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java index af4cc217713..a82b565d9f0 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java @@ -66,7 +66,10 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = Joiner.on(",").join(Arrays.stream(topics).map(topic -> topic.name()).iterator()); + String all = + topics.length == 0 + ? "No topics exists." + : Joiner.on(",").join(Arrays.stream(topics).map(topic -> topic.name()).iterator()); System.out.println(all); } } From 997636c4c1464fc01e7c09943c5c11cb1c151b4b Mon Sep 17 00:00:00 2001 From: Lord of Abyss <103809695+Abyss-lord@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:36:22 +0800 Subject: [PATCH 2/3] Update clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java Co-authored-by: Qiming Teng --- .../java/org/apache/gravitino/cli/commands/ListAllTags.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java index 5baa329fef1..cded12808d9 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListAllTags.java @@ -53,7 +53,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = tags.length == 0 ? "No tags exists." : String.join(",", tags); + String all = tags.length == 0 ? "No tags exist." : String.join(",", tags); System.out.println(all.toString()); } From 1489a2d2ccc173172cce98868e1ca40d50287eab Mon Sep 17 00:00:00 2001 From: pancx Date: Mon, 23 Dec 2024 17:15:42 +0800 Subject: [PATCH 3/3] [#5924] improvement(CLI): fix cli list command produce no outputs fix output message "No XXXs" is still a plural. --- .../java/org/apache/gravitino/cli/commands/ListCatalogs.java | 2 +- .../java/org/apache/gravitino/cli/commands/ListFilesets.java | 2 +- .../main/java/org/apache/gravitino/cli/commands/ListGroups.java | 2 +- .../java/org/apache/gravitino/cli/commands/ListMetalakes.java | 2 +- .../main/java/org/apache/gravitino/cli/commands/ListRoles.java | 2 +- .../main/java/org/apache/gravitino/cli/commands/ListSchema.java | 2 +- .../main/java/org/apache/gravitino/cli/commands/ListTables.java | 2 +- .../main/java/org/apache/gravitino/cli/commands/ListTopics.java | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java index c2dabc43cdc..eb9c960b14e 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -50,7 +50,7 @@ public void handle() { GravitinoClient client = buildClient(metalake); catalogs = client.listCatalogsInfo(); if (catalogs.length == 0) { - System.out.println("No catalogs exists."); + System.out.println("No catalogs exist."); } else { output(catalogs); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java index 004f63add36..d00ba3e6ba5 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesets.java @@ -71,7 +71,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = filesets.length == 0 ? "No filesets exists." : Joiner.on(",").join(filesets); + String all = filesets.length == 0 ? "No filesets exist." : Joiner.on(",").join(filesets); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java index 00328104e9e..a517b4daed8 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListGroups.java @@ -53,7 +53,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = groups.length == 0 ? "No groups exists." : String.join(",", groups); + String all = groups.length == 0 ? "No groups exist." : String.join(",", groups); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java index 1e5ac5d914d..b2388e5cd3d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -44,7 +44,7 @@ public void handle() { GravitinoAdminClient client = buildAdminClient(); metalakes = client.listMetalakes(); if (metalakes.length == 0) { - System.out.println("No metalakes exists."); + System.out.println("No metalakes exist."); } else { output(metalakes); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java index 8158fcbaa05..2ecb35bd093 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListRoles.java @@ -53,7 +53,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = roles.length == 0 ? "No roles exists." : String.join(",", roles); + String all = roles.length == 0 ? "No roles exist." : String.join(",", roles); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java index 0098cf182c1..110a6477a62 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java @@ -60,7 +60,7 @@ public void handle() { exitWithError(exp.getMessage()); } - String all = schemas.length == 0 ? "No schemas exists." : Joiner.on(",").join(schemas); + String all = schemas.length == 0 ? "No schemas exist." : Joiner.on(",").join(schemas); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java index 117757f8e5b..41a71e87c00 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java @@ -63,7 +63,7 @@ public void handle() { String all = tableNames.isEmpty() - ? "No tables exists." + ? "No tables exist." : Joiner.on(System.lineSeparator()).join(tableNames); System.out.println(all.toString()); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java index a82b565d9f0..a2da6a69ad7 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopics.java @@ -68,7 +68,7 @@ public void handle() { String all = topics.length == 0 - ? "No topics exists." + ? "No topics exist." : Joiner.on(",").join(Arrays.stream(topics).map(topic -> topic.name()).iterator()); System.out.println(all); }