This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new d883068551 [#6419] improve(CLI): Add table command context CLI (#6428)
d883068551 is described below
commit d88306855196988e6e574b4c9fb8b0f0d89cc6c2
Author: Lord of Abyss <[email protected]>
AuthorDate: Tue Feb 11 08:23:33 2025 +0800
[#6419] improve(CLI): Add table command context CLI (#6428)
### What changes were proposed in this pull request?
Add table command context CLI.
### Why are the changes needed?
Fix: #6419
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
local test.
---
.../apache/gravitino/cli/GravitinoCommandLine.java | 2 +-
.../apache/gravitino/cli/TableCommandHandler.java | 43 ++---
.../apache/gravitino/cli/TestableCommandLine.java | 67 +++----
.../apache/gravitino/cli/commands/CreateTable.java | 11 +-
.../apache/gravitino/cli/commands/DeleteTable.java | 21 +--
.../apache/gravitino/cli/commands/ListIndexes.java | 15 +-
.../cli/commands/ListTableProperties.java | 13 +-
.../apache/gravitino/cli/commands/ListTables.java | 11 +-
.../cli/commands/RemoveTableProperty.java | 11 +-
.../gravitino/cli/commands/SetTableProperty.java | 11 +-
.../apache/gravitino/cli/commands/TableAudit.java | 13 +-
.../gravitino/cli/commands/TableCommand.java | 7 +
.../gravitino/cli/commands/TableDetails.java | 15 +-
.../gravitino/cli/commands/TableDistribution.java | 15 +-
.../gravitino/cli/commands/TablePartition.java | 17 +-
.../gravitino/cli/commands/TableSortOrder.java | 19 +-
.../gravitino/cli/commands/UpdateTableComment.java | 11 +-
.../gravitino/cli/commands/UpdateTableName.java | 11 +-
.../apache/gravitino/cli/TestTableCommands.java | 206 ++++++++++-----------
19 files changed, 233 insertions(+), 286 deletions(-)
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
index 1923562e1f..29094207b5 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
@@ -118,7 +118,7 @@ public class GravitinoCommandLine extends
TestableCommandLine {
} else if (entity.equals(CommandEntities.COLUMN)) {
new ColumnCommandHandler(this, line, command, ignore).handle();
} else if (entity.equals(CommandEntities.TABLE)) {
- new TableCommandHandler(this, line, command, ignore).handle();
+ new TableCommandHandler(this, line, command, context).handle();
} else if (entity.equals(CommandEntities.SCHEMA)) {
new SchemaCommandHandler(this, line, command, ignore).handle();
} else if (entity.equals(CommandEntities.CATALOG)) {
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/TableCommandHandler.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/TableCommandHandler.java
index b6d90ccd0a..520b655c25 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/TableCommandHandler.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/TableCommandHandler.java
@@ -29,8 +29,7 @@ public class TableCommandHandler extends CommandHandler {
private final GravitinoCommandLine gravitinoCommandLine;
private final CommandLine line;
private final String command;
- private final boolean ignore;
- private final String url;
+ private final CommandContext context;
private final FullName name;
private final String metalake;
private final String catalog;
@@ -43,16 +42,19 @@ public class TableCommandHandler extends CommandHandler {
* @param gravitinoCommandLine The Gravitino command line instance.
* @param line The command line arguments.
* @param command The command to execute.
- * @param ignore Ignore server version mismatch.
+ * @param context The command context.
*/
public TableCommandHandler(
- GravitinoCommandLine gravitinoCommandLine, CommandLine line, String
command, boolean ignore) {
+ GravitinoCommandLine gravitinoCommandLine,
+ CommandLine line,
+ String command,
+ CommandContext context) {
this.gravitinoCommandLine = gravitinoCommandLine;
this.line = line;
this.command = command;
- this.ignore = ignore;
+ this.context = context;
- this.url = getUrl(line);
+ this.context.setUrl(getUrl(line));
this.name = new FullName(line);
this.metalake = name.getMetalakeName();
this.catalog = name.getCatalogName();
@@ -129,32 +131,32 @@ public class TableCommandHandler extends CommandHandler {
private void handleDetailsCommand() {
if (line.hasOption(GravitinoOptions.AUDIT)) {
gravitinoCommandLine
- .newTableAudit(url, ignore, metalake, catalog, schema, table)
+ .newTableAudit(context, metalake, catalog, schema, table)
.validate()
.handle();
} else if (line.hasOption(GravitinoOptions.INDEX)) {
gravitinoCommandLine
- .newListIndexes(url, ignore, metalake, catalog, schema, table)
+ .newListIndexes(context, metalake, catalog, schema, table)
.validate()
.handle();
} else if (line.hasOption(GravitinoOptions.DISTRIBUTION)) {
gravitinoCommandLine
- .newTableDistribution(url, ignore, metalake, catalog, schema, table)
+ .newTableDistribution(context, metalake, catalog, schema, table)
.validate()
.handle();
} else if (line.hasOption(GravitinoOptions.PARTITION)) {
gravitinoCommandLine
- .newTablePartition(url, ignore, metalake, catalog, schema, table)
+ .newTablePartition(context, metalake, catalog, schema, table)
.validate()
.handle();
} else if (line.hasOption(GravitinoOptions.SORTORDER)) {
gravitinoCommandLine
- .newTableSortOrder(url, ignore, metalake, catalog, schema, table)
+ .newTableSortOrder(context, metalake, catalog, schema, table)
.validate()
.handle();
} else {
gravitinoCommandLine
- .newTableDetails(url, ignore, metalake, catalog, schema, table)
+ .newTableDetails(context, metalake, catalog, schema, table)
.validate()
.handle();
}
@@ -165,16 +167,15 @@ public class TableCommandHandler extends CommandHandler {
String columnFile = line.getOptionValue(GravitinoOptions.COLUMNFILE);
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
- .newCreateTable(url, ignore, metalake, catalog, schema, table,
columnFile, comment)
+ .newCreateTable(context, metalake, catalog, schema, table, columnFile,
comment)
.validate()
.handle();
}
/** Handles the "DELETE" command. */
private void handleDeleteCommand() {
- boolean force = line.hasOption(GravitinoOptions.FORCE);
gravitinoCommandLine
- .newDeleteTable(url, ignore, force, metalake, catalog, schema, table)
+ .newDeleteTable(context, metalake, catalog, schema, table)
.validate()
.handle();
}
@@ -184,7 +185,7 @@ public class TableCommandHandler extends CommandHandler {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
gravitinoCommandLine
- .newSetTableProperty(url, ignore, metalake, catalog, schema, table,
property, value)
+ .newSetTableProperty(context, metalake, catalog, schema, table,
property, value)
.validate()
.handle();
}
@@ -193,21 +194,21 @@ public class TableCommandHandler extends CommandHandler {
private void handleRemoveCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
gravitinoCommandLine
- .newRemoveTableProperty(url, ignore, metalake, catalog, schema, table,
property)
+ .newRemoveTableProperty(context, metalake, catalog, schema, table,
property)
.validate()
.handle();
}
/** Handles the "PROPERTIES" command. */
private void handlePropertiesCommand() {
gravitinoCommandLine
- .newListTableProperties(url, ignore, metalake, catalog, schema, table)
+ .newListTableProperties(context, metalake, catalog, schema, table)
.validate()
.handle();
}
/** Handles the "LIST" command. */
private void handleListCommand() {
- gravitinoCommandLine.newListTables(url, ignore, metalake, catalog,
schema).validate().handle();
+ gravitinoCommandLine.newListTables(context, metalake, catalog,
schema).validate().handle();
}
/** Handles the "UPDATE" command. */
@@ -215,14 +216,14 @@ public class TableCommandHandler extends CommandHandler {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
- .newUpdateTableComment(url, ignore, metalake, catalog, schema,
table, comment)
+ .newUpdateTableComment(context, metalake, catalog, schema, table,
comment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
gravitinoCommandLine
- .newUpdateTableName(url, ignore, metalake, catalog, schema, table,
newName)
+ .newUpdateTableName(context, metalake, catalog, schema, table,
newName)
.validate()
.handle();
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
index 21eec0c865..9fd2428d40 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
@@ -305,99 +305,89 @@ public class TestableCommandLine {
}
protected TableAudit newTableAudit(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new TableAudit(url, ignore, metalake, catalog, schema, table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new TableAudit(context, metalake, catalog, schema, table);
}
protected TableDetails newTableDetails(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new TableDetails(url, ignore, metalake, catalog, schema, table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new TableDetails(context, metalake, catalog, schema, table);
}
protected ListTables newListTables(
- String url, boolean ignore, String metalake, String catalog, String
schema) {
- return new ListTables(url, ignore, metalake, catalog, schema);
+ CommandContext context, String metalake, String catalog, String schema) {
+ return new ListTables(context, metalake, catalog, schema);
}
protected DeleteTable newDeleteTable(
- String url,
- boolean ignore,
- boolean force,
- String metalake,
- String catalog,
- String schema,
- String table) {
- return new DeleteTable(url, ignore, force, metalake, catalog, schema,
table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new DeleteTable(context, metalake, catalog, schema, table);
}
protected ListIndexes newListIndexes(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new ListIndexes(url, ignore, metalake, catalog, schema, table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new ListIndexes(context, metalake, catalog, schema, table);
}
protected TablePartition newTablePartition(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new TablePartition(url, ignore, metalake, catalog, schema, table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new TablePartition(context, metalake, catalog, schema, table);
}
protected TableDistribution newTableDistribution(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new TableDistribution(url, ignore, metalake, catalog, schema,
table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new TableDistribution(context, metalake, catalog, schema, table);
}
protected TableSortOrder newTableSortOrder(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new TableSortOrder(url, ignore, metalake, catalog, schema, table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new TableSortOrder(context, metalake, catalog, schema, table);
}
protected UpdateTableComment newUpdateTableComment(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String comment) {
- return new UpdateTableComment(url, ignore, metalake, catalog, schema,
table, comment);
+ return new UpdateTableComment(context, metalake, catalog, schema, table,
comment);
}
protected UpdateTableName newUpdateTableName(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String rename) {
- return new UpdateTableName(url, ignore, metalake, catalog, schema, table,
rename);
+ return new UpdateTableName(context, metalake, catalog, schema, table,
rename);
}
protected SetTableProperty newSetTableProperty(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String property,
String value) {
- return new SetTableProperty(url, ignore, metalake, catalog, schema, table,
property, value);
+ return new SetTableProperty(context, metalake, catalog, schema, table,
property, value);
}
protected RemoveTableProperty newRemoveTableProperty(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String property) {
- return new RemoveTableProperty(url, ignore, metalake, catalog, schema,
table, property);
+ return new RemoveTableProperty(context, metalake, catalog, schema, table,
property);
}
protected ListTableProperties newListTableProperties(
- String url, boolean ignore, String metalake, String catalog, String
schema, String table) {
- return new ListTableProperties(url, ignore, metalake, catalog, schema,
table);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ return new ListTableProperties(context, metalake, catalog, schema, table);
}
protected UserDetails newUserDetails(String url, boolean ignore, String
metalake, String user) {
@@ -869,15 +859,14 @@ public class TestableCommandLine {
}
protected CreateTable newCreateTable(
- String url,
- boolean ignore,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String columnFile,
String comment) {
- return new CreateTable(url, ignore, metalake, catalog, schema, table,
columnFile, comment);
+ return new CreateTable(context, metalake, catalog, schema, table,
columnFile, comment);
}
protected GrantPrivilegesToRole newGrantPrivilegesToRole(
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 aa409941e5..9c9ce76c9f 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
@@ -22,6 +22,7 @@ package org.apache.gravitino.cli.commands;
import java.util.List;
import java.util.Map;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.cli.ReadTableCSV;
import org.apache.gravitino.client.GravitinoClient;
@@ -42,8 +43,7 @@ public class CreateTable extends Command {
/**
* Create a new table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
@@ -52,15 +52,14 @@ public class CreateTable extends Command {
* @param comment The table's comment.
*/
public CreateTable(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String columnFile,
String comment) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -106,7 +105,7 @@ public class CreateTable extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(table + " created");
+ printInformation(table + " created");
}
@Override
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
index be4e846620..594c49ba5b 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.cli.AreYouSure;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -39,24 +40,16 @@ public class DeleteTable extends Command {
/**
* Delete a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
- * @param force Force operation.
+ * @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 schema.
* @param table The name of the table.
*/
public DeleteTable(
- String url,
- boolean ignoreVersions,
- boolean force,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions);
- this.force = force;
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context);
+ this.force = context.force();
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -89,9 +82,9 @@ public class DeleteTable extends Command {
}
if (deleted) {
- System.out.println(table + " deleted.");
+ printInformation(table + " deleted.");
} else {
- System.out.println(table + " not deleted.");
+ printInformation(table + " not deleted.");
}
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java
index 2d1a900baa..9996a7d475 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListIndexes.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import java.util.Arrays;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.indexes.Index;
/** Displays the index of a table. */
@@ -32,21 +33,15 @@ public class ListIndexes extends TableCommand {
/**
* Displays the index of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
* @param table The name of the table.
*/
public ListIndexes(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions, metalake, catalog);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context, metalake, catalog);
this.schema = schema;
this.table = table;
}
@@ -77,6 +72,6 @@ public class ListIndexes extends TableCommand {
.append(System.lineSeparator()));
}
- System.out.print(all);
+ printResults(all.toString());
}
}
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 61ebf5652d..1b9f6fbbbb 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
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
import java.util.Map;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,21 +41,15 @@ public class ListTableProperties extends ListProperties {
/**
* List the properties of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
* @param table The name of the table.
*/
public ListTableProperties(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
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 515fb28678..e1389ed9d1 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
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
+import org.apache.gravitino.cli.CommandContext;
/** List the names of all tables in a schema. */
public class ListTables extends TableCommand {
@@ -33,15 +34,13 @@ public class ListTables extends TableCommand {
/**
* List the names of all tables in a schema.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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.
*/
- public ListTables(
- String url, boolean ignoreVersions, String metalake, String catalog,
String schema) {
- super(url, ignoreVersions, metalake, catalog);
+ public ListTables(CommandContext context, String metalake, String catalog,
String schema) {
+ super(context, metalake, catalog);
this.schema = schema;
}
@@ -66,6 +65,6 @@ public class ListTables extends TableCommand {
? "No tables exist."
: Joiner.on(System.lineSeparator()).join(tableNames);
- System.out.println(all);
+ printResults(all);
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTableProperty.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTableProperty.java
index af370ce64b..6197a16205 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTableProperty.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveTableProperty.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,8 +41,7 @@ public class RemoveTableProperty extends Command {
/**
* Remove a property of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
@@ -49,14 +49,13 @@ public class RemoveTableProperty extends Command {
* @param property The name of the property.
*/
public RemoveTableProperty(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String property) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -84,7 +83,7 @@ public class RemoveTableProperty extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(property + " property removed.");
+ printInformation(property + " property removed.");
}
@Override
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTableProperty.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTableProperty.java
index 54ab88f343..53b121e1d3 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTableProperty.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetTableProperty.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -41,8 +42,7 @@ public class SetTableProperty extends Command {
/**
* Set a property of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
@@ -51,15 +51,14 @@ public class SetTableProperty extends Command {
* @param value The value of the property.
*/
public SetTableProperty(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String property,
String value) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -88,7 +87,7 @@ public class SetTableProperty extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(table + " property set.");
+ printInformation(table + " property set.");
}
@Override
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 0a89076f65..1e4ef0b91f 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
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.Table;
/** Displays the audit information of a table. */
@@ -31,21 +32,15 @@ public class TableAudit extends TableCommand {
/**
* Displays the audit information of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 table The name of the table.
*/
public TableAudit(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions, metalake, catalog);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context, metalake, catalog);
this.schema = schema;
this.table = table;
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableCommand.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableCommand.java
index 8ade3c11a7..471baad1c9 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableCommand.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableCommand.java
@@ -19,6 +19,7 @@
package org.apache.gravitino.cli.commands;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -33,6 +34,12 @@ public class TableCommand extends AuditCommand {
protected final String metalake;
protected final String catalog;
+ public TableCommand(CommandContext context, String metalake, String catalog)
{
+ super(context);
+ this.metalake = metalake;
+ this.catalog = catalog;
+ }
+
/**
* Common code for all table commands.
*
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 0f38218f7c..8ac9fb4fb6 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
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.Table;
/** Displays the details of a table. */
@@ -31,21 +32,15 @@ public class TableDetails extends TableCommand {
/**
* Displays the details of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 table The name of the table.
*/
public TableDetails(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions, metalake, catalog);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context, metalake, catalog);
this.schema = schema;
this.table = table;
}
@@ -62,6 +57,6 @@ public class TableDetails extends TableCommand {
exitWithError(exp.getMessage());
}
- System.out.println(gTable.name() + "," + gTable.comment());
+ printInformation(gTable.name() + "," + gTable.comment());
}
}
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 72a0f3ef3f..958715ead5 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
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.expressions.distributions.Distribution;
/** Displays the details of a table's distirbution. */
@@ -31,21 +32,15 @@ public class TableDistribution extends TableCommand {
/**
* Displays the details of a table's distirbution.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 table The name of the table.
*/
public TableDistribution(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions, metalake, catalog);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context, metalake, catalog);
this.schema = schema;
this.table = table;
}
@@ -62,6 +57,6 @@ public class TableDistribution extends TableCommand {
exitWithError(exp.getMessage());
}
- System.out.println(distribution.strategy() + "," + distribution.number());
+ printInformation(distribution.strategy() + "," + distribution.number());
}
}
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 bbf86303d5..352386383b 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
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.expressions.transforms.Transform;
import org.apache.gravitino.rel.partitions.Partition;
@@ -32,21 +33,15 @@ public class TablePartition extends TableCommand {
/**
* Displays the details of a table's partition.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 table The name of the table.
*/
public TablePartition(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions, metalake, catalog);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context, metalake, catalog);
this.schema = schema;
this.table = table;
}
@@ -64,10 +59,10 @@ public class TablePartition extends TableCommand {
for (Transform transform : transforms) {
Partition[] partitions = transform.assignments();
if (partitions.length == 0) {
- System.out.println("None");
+ printInformation("None");
} else {
for (Partition partition : partitions) {
- System.out.println(partition.name() + "," + partition.properties());
+ printResults(partition.name() + "," + partition.properties());
}
}
}
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 54fc1cca27..2d352b16b3 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
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.rel.expressions.sorts.SortOrder;
/** Displays the details of a table's sort order. */
@@ -31,21 +32,15 @@ public class TableSortOrder extends TableCommand {
/**
* Displays the details of a table's sort order.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 table The name of the table.
*/
public TableSortOrder(
- String url,
- boolean ignoreVersions,
- String metalake,
- String catalog,
- String schema,
- String table) {
- super(url, ignoreVersions, metalake, catalog);
+ CommandContext context, String metalake, String catalog, String schema,
String table) {
+ super(context, metalake, catalog);
this.schema = schema;
this.table = table;
}
@@ -62,8 +57,10 @@ public class TableSortOrder extends TableCommand {
exitWithError(exp.getMessage());
}
for (SortOrder sortOrder : sortOrders) {
- System.out.printf(
- "%s,%s,%s%n", sortOrder.expression(), sortOrder.direction(),
sortOrder.nullOrdering());
+ String result =
+ String.format(
+ "%s,%s,%s", sortOrder.expression(), sortOrder.direction(),
sortOrder.nullOrdering());
+ printResults(result);
}
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableComment.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableComment.java
index c71795a9ec..8983b40c06 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableComment.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableComment.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,8 +41,7 @@ public class UpdateTableComment extends Command {
/**
* Update the comment of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
@@ -49,14 +49,13 @@ public class UpdateTableComment extends Command {
* @param comment New metalake comment.
*/
public UpdateTableComment(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String comment) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -85,6 +84,6 @@ public class UpdateTableComment extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(table + " comment changed.");
+ printInformation(table + " comment changed.");
}
}
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableName.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableName.java
index 51a5b68722..0756e7124f 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableName.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateTableName.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.cli.commands;
import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.CommandContext;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -40,8 +41,7 @@ public class UpdateTableName extends Command {
/**
* Update the name of a table.
*
- * @param url The URL of the Gravitino server.
- * @param ignoreVersions If true don't check the client/server versions
match.
+ * @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 schema.
@@ -49,14 +49,13 @@ public class UpdateTableName extends Command {
* @param name The new table name.
*/
public UpdateTableName(
- String url,
- boolean ignoreVersions,
+ CommandContext context,
String metalake,
String catalog,
String schema,
String table,
String name) {
- super(url, ignoreVersions);
+ super(context);
this.metalake = metalake;
this.catalog = catalog;
this.schema = schema;
@@ -85,6 +84,6 @@ public class UpdateTableName extends Command {
exitWithError(exp.getMessage());
}
- System.out.println(table + " name changed.");
+ printInformation(table + " name changed.");
}
}
diff --git
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java
index f068332045..77166babd2 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestTableCommands.java
@@ -21,6 +21,9 @@ package org.apache.gravitino.cli;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -93,8 +96,7 @@ class TestTableCommands {
mockCommandLine, mockOptions, CommandEntities.TABLE,
CommandActions.LIST));
doReturn(mockList)
.when(commandLine)
- .newListTables(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema");
+ .newListTables(any(CommandContext.class), eq("metalake_demo"),
eq("catalog"), eq("schema"));
doReturn(mockList).when(mockList).validate();
commandLine.handleCommandLine();
verify(mockList).handle();
@@ -115,7 +117,11 @@ class TestTableCommands {
doReturn(mockDetails)
.when(commandLine)
.newTableDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockDetails).when(mockDetails).validate();
commandLine.handleCommandLine();
verify(mockDetails).handle();
@@ -136,7 +142,11 @@ class TestTableCommands {
doReturn(mockIndex)
.when(commandLine)
.newListIndexes(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockIndex).when(mockIndex).validate();
commandLine.handleCommandLine();
verify(mockIndex).handle();
@@ -157,7 +167,11 @@ class TestTableCommands {
doReturn(mockPartition)
.when(commandLine)
.newTablePartition(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockPartition).when(mockPartition).validate();
commandLine.handleCommandLine();
verify(mockPartition).handle();
@@ -178,7 +192,11 @@ class TestTableCommands {
doReturn(mockDistribution)
.when(commandLine)
.newTableDistribution(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockDistribution).when(mockDistribution).validate();
commandLine.handleCommandLine();
verify(mockDistribution).handle();
@@ -201,7 +219,11 @@ class TestTableCommands {
doReturn(mockSortOrder)
.when(commandLine)
.newTableSortOrder(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockSortOrder).when(mockSortOrder).validate();
commandLine.handleCommandLine();
verify(mockSortOrder).handle();
@@ -222,7 +244,11 @@ class TestTableCommands {
doReturn(mockAudit)
.when(commandLine)
.newTableAudit(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockAudit).when(mockAudit).validate();
commandLine.handleCommandLine();
verify(mockAudit).handle();
@@ -242,13 +268,11 @@ class TestTableCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTable(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -269,13 +293,11 @@ class TestTableCommands {
doReturn(mockDelete)
.when(commandLine)
.newDeleteTable(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- true,
- "metalake_demo",
- "catalog",
- "schema",
- "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockDelete).when(mockDelete).validate();
commandLine.handleCommandLine();
verify(mockDelete).handle();
@@ -296,7 +318,11 @@ class TestTableCommands {
doReturn(mockListProperties)
.when(commandLine)
.newListTableProperties(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", "users");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"));
doReturn(mockListProperties).when(mockListProperties).validate();
commandLine.handleCommandLine();
verify(mockListProperties).handle();
@@ -321,14 +347,13 @@ class TestTableCommands {
doReturn(mockSetProperties)
.when(commandLine)
.newSetTableProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "user",
- "property",
- "value");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("user"),
+ eq("property"),
+ eq("value"));
doReturn(mockSetProperties).when(mockSetProperties).validate();
commandLine.handleCommandLine();
verify(mockSetProperties).handle();
@@ -337,18 +362,12 @@ class TestTableCommands {
@Test
void testSetTablePropertyCommandWithoutPropertyAndValue() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTableProperty spySetProperty =
spy(
new SetTableProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "table",
- null,
- null));
-
+ mockContext, "metalake_demo", "catalog", "schema", "table",
null, null));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
@@ -358,17 +377,12 @@ class TestTableCommands {
@Test
void testSetTablePropertyCommandWithoutProperty() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTableProperty spySetProperty =
spy(
new SetTableProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "table",
- null,
- "value"));
+ mockContext, "metalake_demo", "catalog", "schema", "table",
null, "value"));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
@@ -379,17 +393,12 @@ class TestTableCommands {
@Test
void testSetTablePropertyCommandWithoutValue() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
SetTableProperty spySetProperty =
spy(
new SetTableProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "table",
- "property",
- null));
+ mockContext, "metalake_demo", "catalog", "schema", "table",
"property", null));
assertThrows(RuntimeException.class, spySetProperty::validate);
verify(spySetProperty, never()).handle();
@@ -414,13 +423,12 @@ class TestTableCommands {
doReturn(mockSetProperties)
.when(commandLine)
.newRemoveTableProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "users",
- "property");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"),
+ eq("property"));
doReturn(mockSetProperties).when(mockSetProperties).validate();
commandLine.handleCommandLine();
verify(mockSetProperties).handle();
@@ -429,16 +437,12 @@ class TestTableCommands {
@Test
void testRemoveTablePropertyCommandWithoutProperty() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
RemoveTableProperty spyRemoveProperty =
spy(
new RemoveTableProperty(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "table",
- null));
+ mockContext, "metalake_demo", "catalog", "schema", "table",
null));
assertThrows(RuntimeException.class, spyRemoveProperty::validate);
verify(spyRemoveProperty, never()).handle();
@@ -462,13 +466,12 @@ class TestTableCommands {
doReturn(mockUpdate)
.when(commandLine)
.newUpdateTableComment(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "users",
- "New comment");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"),
+ eq("New comment"));
doReturn(mockUpdate).when(mockUpdate).validate();
commandLine.handleCommandLine();
verify(mockUpdate).handle();
@@ -490,13 +493,12 @@ class TestTableCommands {
doReturn(mockUpdate)
.when(commandLine)
.newUpdateTableName(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "users",
- "people");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"),
+ eq("people"));
doReturn(mockUpdate).when(mockUpdate).validate();
commandLine.handleCommandLine();
verify(mockUpdate).handle();
@@ -520,14 +522,13 @@ class TestTableCommands {
doReturn(mockCreate)
.when(commandLine)
.newCreateTable(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "users",
- "users.csv",
- "comment");
+ any(CommandContext.class),
+ eq("metalake_demo"),
+ eq("catalog"),
+ eq("schema"),
+ eq("users"),
+ eq("users.csv"),
+ eq("comment"));
doReturn(mockCreate).when(mockCreate).validate();
commandLine.handleCommandLine();
verify(mockCreate).handle();
@@ -536,17 +537,12 @@ class TestTableCommands {
@Test
void testCreateTableWithoutFile() {
Main.useExit = false;
+ CommandContext mockContext = mock(CommandContext.class);
+ when(mockContext.url()).thenReturn(GravitinoCommandLine.DEFAULT_URL);
CreateTable spyCreate =
spy(
new CreateTable(
- GravitinoCommandLine.DEFAULT_URL,
- false,
- "metalake_demo",
- "catalog",
- "schema",
- "table",
- null,
- "comment"));
+ mockContext, "metalake_demo", "catalog", "schema", "table",
null, "comment"));
assertThrows(RuntimeException.class, spyCreate::validate);
verify(spyCreate, never()).handle();
@@ -569,7 +565,7 @@ class TestTableCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
- .newListTables(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", null, null);
+ .newListTables(any(CommandContext.class), eq("metalake_demo"),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -597,7 +593,7 @@ class TestTableCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
- .newListTables(GravitinoCommandLine.DEFAULT_URL, false,
"metalake_demo", "catalog", null);
+ .newListTables(any(CommandContext.class), eq("metalake_demo"),
eq("catalog"), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -622,7 +618,7 @@ class TestTableCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newTableDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", null,
null, null);
+ any(CommandContext.class), eq("metalake_demo"), isNull(),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -651,7 +647,7 @@ class TestTableCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newTableDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", null, null);
+ any(CommandContext.class), eq("metalake_demo"), eq("catalog"),
isNull(), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,
@@ -680,7 +676,7 @@ class TestTableCommands {
assertThrows(RuntimeException.class, commandLine::handleCommandLine);
verify(commandLine, never())
.newTableDetails(
- GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo",
"catalog", "schema", null);
+ any(CommandContext.class), eq("metalake_demo"), eq("catalog"),
eq("schema"), isNull());
String output = new String(errContent.toByteArray(),
StandardCharsets.UTF_8).trim();
assertEquals(
output,