diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogAudit.java index b46dc50ada8..6600e1d4291 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogAudit.java @@ -59,6 +59,8 @@ public void handle() { exitWithError(exp.getMessage()); } - displayAuditInfo(result.auditInfo()); + if (result != null) { + displayAuditInfo(result.auditInfo()); + } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTable.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTable.java index 9c9ce76c9f5..c45e0ef6748 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTable.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTable.java @@ -86,9 +86,19 @@ public void handle() { exitWithError("Error initializing client or table name: " + exp.getMessage()); } + if (client == null) { + exitWithError("Client initialization failed."); + } + if (tableName == null) { + exitWithError("Table name could not be determined."); + } + try { tableData = readTableCSV.parse(columnFile); columns = readTableCSV.columns(tableData); + if (columns == null || columns.length == 0) { + exitWithError("No valid columns found in the provided file."); + } } catch (Exception exp) { exitWithError("Error reading or parsing column file: " + exp.getMessage()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/FilesetDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/FilesetDetails.java index 5654f44a627..0397cc635c2 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/FilesetDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/FilesetDetails.java @@ -43,7 +43,7 @@ public class FilesetDetails extends Command { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param fileset The name of the fileset. */ public FilesetDetails( diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java index 54312b8e437..94b05a6564d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogProperties.java @@ -25,7 +25,6 @@ import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; -import org.apache.gravitino.exceptions.NoSuchMetalakeException; /** List the properties of a catalog. */ public class ListCatalogProperties extends ListProperties { @@ -50,8 +49,8 @@ public ListCatalogProperties(CommandContext context, String metalake, String cat @Override public void handle() { Catalog gCatalog = null; - try { - GravitinoClient client = buildClient(metalake); + + try (GravitinoClient client = buildClient(metalake)) { gCatalog = client.loadCatalog(catalog); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); @@ -61,7 +60,9 @@ public void handle() { exitWithError(exp.getMessage()); } - Map properties = gCatalog.properties(); - printProperties(properties); + if (gCatalog != null) { + Map properties = gCatalog.properties(); + printProperties(properties); + } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java index 1fc642a555a..258ef308864 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.gravitino.cli.commands; import com.google.common.base.Joiner; @@ -51,18 +50,39 @@ public ListColumns( /** Displays the details of a table's columns. */ @Override public void handle() { - Column[] columns = null; - try { NameIdentifier name = NameIdentifier.of(schema, table); - columns = tableCatalog().loadTable(name).columns(); + Column[] columns = tableCatalog().loadTable(name).columns(); + + if (columns == null || columns.length == 0) { + exitWithError("No columns found for the specified table."); + } + + StringBuilder all = new StringBuilder(); + all.append("name\tdatatype\tcomment\tnullable\tauto_increment").append(System.lineSeparator()); + + for (Column column : columns) { + if (column == null) { + continue; + } + + all.append(column.name()).append("\t"); + all.append(column.dataType() != null ? column.dataType().simpleString() : "UNKNOWN").append("\t"); + all.append(column.comment() != null ? column.comment() : "N/A").append("\t"); + all.append(column.nullable() ? "true" : "false").append("\t"); + all.append(column.autoIncrement() ? "true" : "false"); + all.append(System.lineSeparator()); + } + + printResults(all.toString()); + } catch (NoSuchTableException noSuchTableException) { exitWithError( - ErrorMessages.UNKNOWN_TABLE + Joiner.on(".").join(metalake, catalog, schema, table)); + ErrorMessages.UNKNOWN_TABLE + + " " + + Joiner.on(".").join(metalake, catalog, schema, table)); } catch (Exception exp) { - exitWithError(exp.getMessage()); + printResults("An error occurred while retrieving column details: " + exp.getMessage()); } - - printResults(columns); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java index bdaeaccd1e7..6a81c6b6c94 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListFilesetProperties.java @@ -19,7 +19,7 @@ package org.apache.gravitino.cli.commands; -import java.util.Map; +import java.util.Collections; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.cli.ErrorMessages; @@ -59,10 +59,12 @@ public ListFilesetProperties( @Override public void handle() { Fileset gFileset = null; - try { + + try (GravitinoClient client = buildClient(metalake)) { NameIdentifier name = NameIdentifier.of(schema, fileset); - GravitinoClient client = buildClient(metalake); gFileset = client.loadCatalog(catalog).asFilesetCatalog().loadFileset(name); + } catch (IllegalArgumentException exp) { + exitWithError("Invalid schema or fileset name: " + exp.getMessage()); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (NoSuchCatalogException err) { @@ -73,7 +75,10 @@ public void handle() { exitWithError(exp.getMessage()); } - Map properties = gFileset.properties(); - printProperties(properties); + if (gFileset == null) { + exitWithError("Failed to load fileset: " + fileset); + } + + printProperties(gFileset.properties() != null ? gFileset.properties() : Collections.emptyMap()); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java index 2e85058d123..0837467c3ee 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java @@ -46,8 +46,8 @@ public ListMetalakeProperties(CommandContext context, String metalake) { @Override public void handle() { Metalake gMetalake = null; - try { - GravitinoAdminClient client = buildAdminClient(); + + try (GravitinoAdminClient client = buildAdminClient()) { // Ensure resource cleanup gMetalake = client.loadMetalake(metalake); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); @@ -55,8 +55,11 @@ public void handle() { exitWithError(exp.getMessage()); } - Map properties = gMetalake.properties(); + if (gMetalake == null) { + exitWithError("Metalake not found: " + metalake); + } + Map properties = gMetalake.properties(); printProperties(properties); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java index ff28d4970c2..0ce90fa4f9d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchemaProperties.java @@ -55,8 +55,10 @@ public ListSchemaProperties( @Override public void handle() { Schema gSchema = null; + GravitinoClient client = null; + try { - GravitinoClient client = buildClient(metalake); + client = buildClient(metalake); gSchema = client.loadCatalog(catalog).asSchemas().loadSchema(schema); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); @@ -68,6 +70,10 @@ public void handle() { exitWithError(exp.getMessage()); } + if (gSchema == null) { + exitWithError("Schema not found: " + schema); + } + Map properties = gSchema.properties(); printProperties(properties); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTableProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTableProperties.java index 1b9f6fbbbb2..7c47fcf6481 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTableProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTableProperties.java @@ -59,10 +59,12 @@ public ListTableProperties( /** List the properties of a table. */ @Override public void handle() { + GravitinoClient client = null; Table gTable = null; + try { + client = buildClient(metalake); NameIdentifier name = NameIdentifier.of(schema, table); - GravitinoClient client = buildClient(metalake); gTable = client.loadCatalog(catalog).asTableCatalog().loadTable(name); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); @@ -76,6 +78,10 @@ public void handle() { exitWithError(exp.getMessage()); } + if (gTable == null) { + exitWithError("Table not found: " + table); + } + Map properties = gTable.properties(); printProperties(properties); } 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 1f098efce77..bffce35c280 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 @@ -37,7 +37,7 @@ public class ListTables extends TableCommand { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. */ public ListTables(CommandContext context, String metalake, String catalog, String schema) { super(context, metalake, catalog); @@ -47,43 +47,50 @@ public ListTables(CommandContext context, String metalake, String catalog, Strin /** List the names of all tables in a schema. */ @Override public void handle() { - NameIdentifier[] tables = null; - Namespace name = Namespace.of(schema); - try { - tables = tableCatalog().listTables(name); + Namespace name = Namespace.of(schema); + NameIdentifier[] tables = tableCatalog().listTables(name); + + if (tables == null || tables.length == 0) { + printInformation("No tables exist."); + return; + } + + try { + Table[] gTables = new Table[tables.length]; + for (int i = 0; i < tables.length; i++) { + String tableName = tables[i].name(); + gTables[i] = createTableStub(tableName); + } + + printResults(gTables); } catch (Exception exp) { exitWithError(exp.getMessage()); } + } - if (tables.length == 0) { - printInformation("No tables exist."); - return; - } - - Table[] gTables = new Table[tables.length]; - for (int i = 0; i < tables.length; i++) { - String tableName = tables[i].name(); - gTables[i] = - new Table() { - - @Override - public String name() { - return tableName; - } - - @Override - public Column[] columns() { - return new Column[0]; - } + /** + * Creates a stub Table instance with only the table name. + * + * @param tableName The name of the table. + * @return A minimal Table instance. + */ + private Table createTableStub(String tableName) { + return new Table() { + @Override + public String name() { + return tableName; + } - @Override - public Audit auditInfo() { - return null; - } - }; - } + @Override + public Column[] columns() { + return new Column[0]; // Empty columns since only table names are needed + } - printResults(gTables); + @Override + public Audit auditInfo() { + return null; // No audit info needed for listing tables + } + }; } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java index 13ace743f7c..927b13b1708 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTagProperties.java @@ -53,6 +53,7 @@ public void handle() { try { GravitinoClient client = buildClient(metalake); gTag = client.getTag(tag); + } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (NoSuchTagException err) { @@ -61,6 +62,10 @@ public void handle() { exitWithError(exp.getMessage()); } + if (gTag == null) { + exitWithError(ErrorMessages.UNKNOWN_TAG); + } + Map properties = gTag.properties(); printProperties(properties); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java index 038c29b3cb7..91994a8ed9c 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTopicProperties.java @@ -77,6 +77,10 @@ public void handle() { exitWithError(exp.getMessage()); } + if (gTopic == null) { + exitWithError(ErrorMessages.UNKNOWN_TOPIC); + } + Map properties = gTopic.properties(); printProperties(properties); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java index 4c5f1a57d4f..fe05104e319 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelDetails.java @@ -68,20 +68,27 @@ public void handle() { ModelCatalog modelCatalog = client.loadCatalog(catalog).asModelCatalog(); gModel = modelCatalog.getModel(name); versions = modelCatalog.listModelVersions(name); - } catch (NoSuchMetalakeException noSuchMetalakeException) { + + } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); - } catch (NoSuchCatalogException noSuchCatalogException) { + } catch (NoSuchCatalogException err) { exitWithError(ErrorMessages.UNKNOWN_CATALOG); - } catch (NoSuchSchemaException noSuchSchemaException) { + } catch (NoSuchSchemaException err) { exitWithError(ErrorMessages.UNKNOWN_SCHEMA); - } catch (NoSuchModelException noSuchModelException) { + } catch (NoSuchModelException err) { exitWithError(ErrorMessages.UNKNOWN_MODEL); } catch (Exception err) { exitWithError(err.getMessage()); } + + if (gModel == null) { + exitWithError(ErrorMessages.UNKNOWN_MODEL); + } + String basicInfo = - String.format("Model name %s, latest version: %s%n", gModel.name(), gModel.latestVersion()); - String versionInfo = Arrays.toString(versions); + String.format( + "Model Name: %s, Latest Version: %s%n", gModel.name(), gModel.latestVersion()); + String versionInfo = "Versions: " + Arrays.toString(versions); printResults(basicInfo + "versions: " + versionInfo); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaAudit.java index db01ed437b6..14ebe4c2b87 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaAudit.java @@ -40,7 +40,7 @@ public class SchemaAudit extends AuditCommand { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. */ public SchemaAudit(CommandContext context, String metalake, String catalog, String schema) { super(context); @@ -52,9 +52,11 @@ public SchemaAudit(CommandContext context, String metalake, String catalog, Stri /** Displays the audit information of schema. */ @Override public void handle() { + GravitinoClient client = null; Schema result = null; - try (GravitinoClient client = buildClient(metalake)) { + try { + client = buildClient(metalake); result = client.loadCatalog(catalog).asSchemas().loadSchema(this.schema); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); @@ -66,6 +68,10 @@ public void handle() { exitWithError(exp.getMessage()); } + if (result == null) { + exitWithError("Failed to retrieve schema details."); + } + displayAuditInfo(result.auditInfo()); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java index 560fca20dfd..0d776aa4fac 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java @@ -40,7 +40,7 @@ public class SchemaDetails extends Command { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. */ public SchemaDetails(CommandContext context, String metalake, String catalog, String schema) { super(context); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableAudit.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableAudit.java index 1e4ef0b91fc..4da1689c2f8 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableAudit.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableAudit.java @@ -21,6 +21,10 @@ import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.cli.CommandContext; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; import org.apache.gravitino.rel.Table; /** Displays the audit information of a table. */ @@ -35,7 +39,7 @@ public class TableAudit extends TableCommand { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param table The name of the table. */ public TableAudit( @@ -53,10 +57,21 @@ public void handle() { try { NameIdentifier name = NameIdentifier.of(schema, table); gTable = tableCatalog().loadTable(name); + + } catch (NoSuchMetalakeException err) { + exitWithError(ErrorMessages.UNKNOWN_METALAKE); + } catch (NoSuchCatalogException err) { + exitWithError(ErrorMessages.UNKNOWN_CATALOG); + } catch (NoSuchSchemaException err) { + exitWithError(ErrorMessages.UNKNOWN_SCHEMA); } catch (Exception exp) { exitWithError(exp.getMessage()); } + if (gTable == null) { + exitWithError("Failed to retrieve table details."); + } + displayAuditInfo(gTable.auditInfo()); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java index 23950e7ee93..19866a97f72 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java @@ -35,7 +35,7 @@ public class TableDetails extends TableCommand { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param table The name of the table. */ public TableDetails( diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java index 958715ead59..439355c246b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java @@ -23,19 +23,19 @@ import org.apache.gravitino.cli.CommandContext; import org.apache.gravitino.rel.expressions.distributions.Distribution; -/** Displays the details of a table's distirbution. */ +/** Displays the details of a table's distribution. */ public class TableDistribution extends TableCommand { protected final String schema; protected final String table; /** - * Displays the details of a table's distirbution. + * Displays the details of a table's distribution. * * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param table The name of the table. */ public TableDistribution( @@ -45,7 +45,7 @@ public TableDistribution( this.table = table; } - /** Displays the strategy and bucket number of distirbution. */ + /** Displays the strategy and bucket number of distribution. */ @Override public void handle() { Distribution distribution = null; diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TablePartition.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TablePartition.java index 352386383b9..192d5238807 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TablePartition.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TablePartition.java @@ -36,7 +36,7 @@ public class TablePartition extends TableCommand { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param table The name of the table. */ public TablePartition( diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableSortOrder.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableSortOrder.java index 2d352b16b3c..ba42685a5ed 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableSortOrder.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableSortOrder.java @@ -35,7 +35,7 @@ public class TableSortOrder extends TableCommand { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param table The name of the table. */ public TableSortOrder( diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java index d72002419d6..49c6242f80d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TopicDetails.java @@ -43,7 +43,7 @@ public class TopicDetails extends Command { * @param context The command context. * @param metalake The name of the metalake. * @param catalog The name of the catalog. - * @param schema The name of the schenma. + * @param schema The name of the schema. * @param topic The name of the topic. */ public TopicDetails( @@ -60,9 +60,8 @@ public TopicDetails( public void handle() { Topic gTopic = null; - try { + try (GravitinoClient client = buildClient(metalake)) { NameIdentifier name = NameIdentifier.of(schema, topic); - GravitinoClient client = buildClient(metalake); gTopic = client.loadCatalog(catalog).asTopicCatalog().loadTopic(name); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); @@ -76,6 +75,10 @@ public void handle() { exitWithError(exp.getMessage()); } - printResults(gTopic.name() + "," + gTopic.comment()); + if (gTopic == null) { + exitWithError(ErrorMessages.UNKNOWN_TOPIC); + } + + printResults("Topic Name: " + gTopic.name() + ", Comment: " + gTopic.comment()); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java index 26c11a0e12b..dd6f43d558f 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UserDetails.java @@ -49,19 +49,18 @@ public UserDetails(CommandContext context, String metalake, String user) { public void handle() { List roles = null; - try { - GravitinoClient client = buildClient(metalake); + try (GravitinoClient client = buildClient(metalake)) { roles = client.getUser(user).roles(); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (NoSuchUserException err) { exitWithError(ErrorMessages.UNKNOWN_USER); - } catch (Exception exp) { - exitWithError(exp.getMessage()); + } catch (Exception err) { + exitWithError(err.getMessage()); } - if (roles.isEmpty()) { - printInformation("The user has no roles."); + if (roles == null || roles.isEmpty()) { + printInformation("The user has no assigned roles."); } else { printResults(String.join(",", roles)); }