Skip to content

Commit

Permalink
[apache#6493] feat(CLI): Support table format output for Schema and T…
Browse files Browse the repository at this point in the history
…able command

fix some bugs.
  • Loading branch information
Abyss-lord committed Feb 24, 2025
1 parent 6b45438 commit 9f5f7c6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.apache.gravitino.cli.commands;

import org.apache.gravitino.Catalog;
import org.apache.gravitino.Audit;
import org.apache.gravitino.Schema;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
Expand Down Expand Up @@ -51,12 +51,10 @@ public ListSchema(CommandContext context, String metalake, String catalog) {
public void handle() {
String[] schemas = new String[0];
GravitinoClient client;
Catalog gCatalog = null;

try {
client = buildClient(metalake);
gCatalog = client.loadCatalog(catalog);
schemas = gCatalog.asSchemas().listSchemas();
schemas = client.loadCatalog(catalog).asSchemas().listSchemas();
} catch (NoSuchMetalakeException err) {
exitWithError(ErrorMessages.UNKNOWN_METALAKE);
} catch (NoSuchCatalogException err) {
Expand All @@ -65,16 +63,29 @@ public void handle() {
exitWithError(exp.getMessage());
}

Schema[] schemaObjects = new Schema[schemas.length];
for (int i = 0; i < schemas.length; i++) {
schemaObjects[i] = gCatalog.asSchemas().loadSchema(schemas[i]);
}

if (schemas.length == 0) {
printInformation("No schemas exist.");
return;
}

Schema[] schemaObjects = new Schema[schemas.length];
for (int i = 0; i < schemas.length; i++) {
String schemaName = schemas[i];
Schema gSchema =
new Schema() {
@Override
public String name() {
return schemaName;
}

@Override
public Audit auditInfo() {
return null;
}
};
schemaObjects[i] = gSchema;
}

printResults(schemaObjects);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

package org.apache.gravitino.cli.commands;

import org.apache.gravitino.Audit;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.Column;
import org.apache.gravitino.rel.Table;
import org.apache.gravitino.rel.TableCatalog;

/** List the names of all tables in a schema. */
public class ListTables extends TableCommand {
Expand All @@ -48,11 +49,9 @@ public ListTables(CommandContext context, String metalake, String catalog, Strin
public void handle() {
NameIdentifier[] tables = null;
Namespace name = Namespace.of(schema);
TableCatalog gCatalog = null;

try {
gCatalog = tableCatalog();
tables = gCatalog.listTables(name);
tables = tableCatalog().listTables(name);
} catch (Exception exp) {
exitWithError(exp.getMessage());
}
Expand All @@ -64,7 +63,25 @@ public void handle() {

Table[] gTables = new Table[tables.length];
for (int i = 0; i < tables.length; i++) {
gTables[i] = gCatalog.loadTable(tables[i]);
String tableName = tables[i].name();
gTables[i] =
new Table() {

@Override
public String name() {
return tableName;
}

@Override
public Column[] columns() {
return new Column[0];
}

@Override
public Audit auditInfo() {
return null;
}
};
}

printResults(gTables);
Expand Down

0 comments on commit 9f5f7c6

Please sign in to comment.