From f90a086c794b59e36cf723efcd81d58318f55097 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 15 Oct 2024 23:18:24 -0700 Subject: [PATCH 01/12] fix spelling error --- clients/cli/errors.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/cli/errors.sh b/clients/cli/errors.sh index 9d0571742de..16ba3d49989 100644 --- a/clients/cli/errors.sh +++ b/clients/cli/errors.sh @@ -26,10 +26,10 @@ alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAP # No such command gcli unknown -# unknown command and entiry +# unknown command and entity gcli unknown unknown -# unknown command and entiry +# unknown command and entity gcli unknown unknown # unknown command From 3c87c3d236208695e0aad943887eda1a71619921 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 08:49:41 -0700 Subject: [PATCH 02/12] add examples not using metalake --- clients/cli/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/clients/cli/README.md b/clients/cli/README.md index b4f7c2cfc88..58101f66a17 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -179,6 +179,26 @@ As dealing with one Metalake is a typical scenario, you can set the Metalake nam The command line option overrides the other options and the environment variable overrides the value in the configuration file. +Once the metalake name is set via one of the preceding methods, if no longer needs to be specified in the command line. + +Show Metalake details + +```bash +gcli metalake details +``` + +List all Catalogs in a Metalake + +```bash +gcli metalake list +``` + +List catalog schemas + +```bash +gcli catalog list --name catalog_iceberg +``` + ## Running Tests This project includes a suite of unit tests to verify its functionality. From 10af3d26d6900f7172aaeee57d4e3e9a177311dd Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 08:52:59 -0700 Subject: [PATCH 03/12] remove duplication and clarify --- clients/cli/errors.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clients/cli/errors.sh b/clients/cli/errors.sh index bc67633c06a..de0ed3baef5 100644 --- a/clients/cli/errors.sh +++ b/clients/cli/errors.sh @@ -29,9 +29,6 @@ gcli unknown # unknown command and entiry gcli unknown unknown -# unknown command and entiry -gcli unknown unknown - # unknown command gcli metalake unknown @@ -47,5 +44,5 @@ gcli metalake details --name unknown # Unknown catalog name gcli catalog details --name metalake_demo.unknown -# Unknown catalog name +# Missing catalog name gcli catalog details --name metalake_demo From f955db2b5d21bbf3d80f60a7be94c6f80d30059d Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 09:16:49 -0700 Subject: [PATCH 04/12] use client shadow jar --- integration-test-common/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test-common/build.gradle.kts b/integration-test-common/build.gradle.kts index a25ad4cff8f..e0678b97d7a 100644 --- a/integration-test-common/build.gradle.kts +++ b/integration-test-common/build.gradle.kts @@ -27,7 +27,7 @@ repositories { dependencies { testImplementation(project(":api")) - testImplementation(project(":clients:client-java")) + testImplementation(project(":clients:client-java", configuration = "shadow")) testImplementation(project(":common")) testImplementation(project(":core")) testImplementation(project(":server")) From 80aef916100f86c0f0935edd2d2c890de03e9731 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 09:53:04 -0700 Subject: [PATCH 05/12] wrong file --- integration-test-common/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test-common/build.gradle.kts b/integration-test-common/build.gradle.kts index e0678b97d7a..a25ad4cff8f 100644 --- a/integration-test-common/build.gradle.kts +++ b/integration-test-common/build.gradle.kts @@ -27,7 +27,7 @@ repositories { dependencies { testImplementation(project(":api")) - testImplementation(project(":clients:client-java", configuration = "shadow")) + testImplementation(project(":clients:client-java")) testImplementation(project(":common")) testImplementation(project(":core")) testImplementation(project(":server")) From 6d897c050149e4ab4629a99f5a9b0148277204ca Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 22:14:02 -0700 Subject: [PATCH 06/12] new -> 19 --- clients/cli/build.gradle.kts | 2 +- gradle/libs.versions.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts index 3b0434b64b8..6e6da9dae41 100644 --- a/clients/cli/build.gradle.kts +++ b/clients/cli/build.gradle.kts @@ -28,7 +28,7 @@ dependencies { implementation(project(":common")) implementation(libs.slf4j.api) implementation(libs.slf4j.simple) - implementation(libs.commons.cli.new) + implementation(libs.commons.cli.19) testImplementation(libs.junit.jupiter.api) testImplementation(libs.junit.jupiter.params) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2888f220876..e19f189c0b5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -90,7 +90,7 @@ shadow-plugin = "8.1.1" kerby = "2.0.3" node-plugin = "7.0.1" commons-cli = "1.2" -commons-cli-new = "1.9.0" +commons-cli-19 = "1.9.0" sun-activation-version = "1.2.0" error-prone = "3.1.0" woodstox-core = "5.3.0" @@ -211,7 +211,7 @@ postgresql-driver = { group = "org.postgresql", name = "postgresql", version.ref minikdc = { group = "org.apache.hadoop", name = "hadoop-minikdc", version.ref = "hadoop-minikdc"} immutables-value = { module = "org.immutables:value", version.ref = "immutables-value" } commons-cli = { group = "commons-cli", name = "commons-cli", version.ref = "commons-cli" } -commons-cli-new = { group = "commons-cli", name = "commons-cli", version.ref = "commons-cli-new" } +commons-cli-19 = { group = "commons-cli", name = "commons-cli", version.ref = "commons-cli-19" } sun-activation = { group = "com.sun.activation", name = "javax.activation", version.ref = "sun-activation-version" } kafka-clients = { group = "org.apache.kafka", name = "kafka-clients", version.ref = "kafka" } kafka = { group = "org.apache.kafka", name = "kafka_2.12", version.ref = "kafka" } From 76aa1fe7f6b40cc695c8ad8b578c9c7ea457ed01 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 22:16:38 -0700 Subject: [PATCH 07/12] fix example command --- clients/cli/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/cli/README.md b/clients/cli/README.md index fc61816fb68..265496bed53 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -119,7 +119,7 @@ gcli metalake details -name my-metalake List Tables in a Catalog ```bash -gcli metalake list -name my-metalake.my-catalog +gcli metalake list -name my-metalake ``` ## Running Tests From affd6ad3e0a9eadba3d4f43e95b9c22994dbad20 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 22:28:32 -0700 Subject: [PATCH 08/12] revert as the suggested name is not value --- clients/cli/build.gradle.kts | 2 +- gradle/libs.versions.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts index 6e6da9dae41..3b0434b64b8 100644 --- a/clients/cli/build.gradle.kts +++ b/clients/cli/build.gradle.kts @@ -28,7 +28,7 @@ dependencies { implementation(project(":common")) implementation(libs.slf4j.api) implementation(libs.slf4j.simple) - implementation(libs.commons.cli.19) + implementation(libs.commons.cli.new) testImplementation(libs.junit.jupiter.api) testImplementation(libs.junit.jupiter.params) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e19f189c0b5..2888f220876 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -90,7 +90,7 @@ shadow-plugin = "8.1.1" kerby = "2.0.3" node-plugin = "7.0.1" commons-cli = "1.2" -commons-cli-19 = "1.9.0" +commons-cli-new = "1.9.0" sun-activation-version = "1.2.0" error-prone = "3.1.0" woodstox-core = "5.3.0" @@ -211,7 +211,7 @@ postgresql-driver = { group = "org.postgresql", name = "postgresql", version.ref minikdc = { group = "org.apache.hadoop", name = "hadoop-minikdc", version.ref = "hadoop-minikdc"} immutables-value = { module = "org.immutables:value", version.ref = "immutables-value" } commons-cli = { group = "commons-cli", name = "commons-cli", version.ref = "commons-cli" } -commons-cli-19 = { group = "commons-cli", name = "commons-cli", version.ref = "commons-cli-19" } +commons-cli-new = { group = "commons-cli", name = "commons-cli", version.ref = "commons-cli-new" } sun-activation = { group = "com.sun.activation", name = "javax.activation", version.ref = "sun-activation-version" } kafka-clients = { group = "org.apache.kafka", name = "kafka-clients", version.ref = "kafka" } kafka = { group = "org.apache.kafka", name = "kafka_2.12", version.ref = "kafka" } From abc2da84c7de366879a5108d36a358b52595b1ea Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 17 Oct 2024 09:13:42 -0700 Subject: [PATCH 09/12] simplify command options --- clients/cli/{ => bin}/errors.sh | 14 +-- clients/cli/bin/examples.sh | 103 ++++++++++++++++ clients/cli/{ => docs}/README.md | 20 ++-- clients/cli/examples.sh | 111 ------------------ .../org/apache/gravitino/cli/FullName.java | 29 ++--- .../gravitino/cli/GravitinoOptions.java | 17 +-- .../java/org/apache/gravitino/cli/Main.java | 48 +------- .../apache/gravitino/cli/TestFulllName.java | 42 +------ .../org/apache/gravitino/cli/TestMain.java | 15 +-- 9 files changed, 138 insertions(+), 261 deletions(-) rename clients/cli/{ => bin}/errors.sh (83%) create mode 100755 clients/cli/bin/examples.sh rename clients/cli/{ => docs}/README.md (91%) delete mode 100755 clients/cli/examples.sh diff --git a/clients/cli/errors.sh b/clients/cli/bin/errors.sh similarity index 83% rename from clients/cli/errors.sh rename to clients/cli/bin/errors.sh index de0ed3baef5..38eb99e1f74 100644 --- a/clients/cli/errors.sh +++ b/clients/cli/bin/errors.sh @@ -27,22 +27,22 @@ alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAP gcli unknown # unknown command and entiry -gcli unknown unknown +gcli unknown --unknown # unknown command -gcli metalake unknown +gcli metalake --unknown # unknown entity -gcli unknown list +gcli unknown --list # Name not specified -gcli metalake details +gcli metalake --details # Unknown metalake name -gcli metalake details --name unknown +gcli metalake --details --name unknown # Unknown catalog name -gcli catalog details --name metalake_demo.unknown +gcli catalog --details --name metalake_demo.unknown # Missing catalog name -gcli catalog details --name metalake_demo +gcli catalog --details --name metalake_demo diff --git a/clients/cli/bin/examples.sh b/clients/cli/bin/examples.sh new file mode 100755 index 00000000000..bb8994e03eb --- /dev/null +++ b/clients/cli/bin/examples.sh @@ -0,0 +1,103 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +#!/bin/bash + +# These examples assume you have the Apache Gravitino playground running. + +unset GRAVITINO_METALAKE +alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar' + +# display help +gcli --help + +# display version +gcli --version + +# metalake details +gcli --details + +# metalake list +gcli --list + +# list all catalogs in a metalake +gcli metalake --list --name metalake_demo + +# list catalog schema +gcli catalog --list --name metalake_demo.catalog_iceberg +gcli catalog --list --name metalake_demo.catalog_mysql +gcli catalog --list --name metalake_demo.catalog_postgres +gcli catalog --list --name metalake_demo.catalog_hive + +# list catalog details +gcli catalog --details --name metalake_demo.catalog_iceberg +gcli catalog --details --name metalake_demo.catalog_mysql +gcli catalog --details --name metalake_demo.catalog_postgres +gcli catalog --details --name metalake_demo.catalog_hive + +# list schema tables +gcli schema --list --name metalake_demo.catalog_postgres.hr +gcli schema --list --name metalake_demo.catalog_mysql.db +gcli schema --list --name metalake_demo.catalog_hive.sales + +# list schema details +gcli schema --details --name metalake_demo.catalog_postgres.hr +gcli schema --details --name metalake_demo.catalog_mysql.db +gcli schema --details --name metalake_demo.catalog_hive.sales + +# list table details +gcli table --list --name metalake_demo.catalog_postgres.hr.departments +gcli table --list --name metalake_demo.catalog_mysql.db.iceberg_tables +gcli table --list --name metalake_demo.catalog_hive.sales.products + +# Exmaples where metalake is set in an evironment variable +export GRAVITINO_METALAKE=metalake_demo + +# metalake details +gcli metalake --details + +# list all catalogs in a metalake +gcli metalake --list + +# list catalog schema +gcli catalog --list --name catalog_iceberg +gcli catalog --list --name catalog_mysql +gcli catalog --list --name catalog_postgres +gcli catalog --list --name catalog_hive + +# list catalog details +gcli catalog --details --name catalog_iceberg +gcli catalog --details --name catalog_mysql +gcli catalog --details --name catalog_postgres +gcli catalog --details --name catalog_hive + +# list schema tables +gcli schema --list --name catalog_postgres.hr +gcli schema --list --name catalog_mysql.db +gcli schema --list --name catalog_hive.sales + +# list schema details +gcli schema --details --name catalog_postgres.hr +gcli schema --details --name catalog_mysql.db +gcli schema --details --name catalog_hive.sales + +# list table details +gcli table --list --name catalog_postgres.hr.departments +gcli table --list --name catalog_mysql.db.iceberg_tables +gcli table --list --name catalog_hive.sales.products diff --git a/clients/cli/README.md b/clients/cli/docs/README.md similarity index 91% rename from clients/cli/README.md rename to clients/cli/docs/README.md index 265496bed53..da684bd5d36 100644 --- a/clients/cli/README.md +++ b/clients/cli/docs/README.md @@ -36,7 +36,7 @@ Apache Gravitino CLI is a command-line tool that interacts with the Gravitino se - Retrieve server version - Provide help on usage - Manage Gravitino entities such as Metalakes, Catalogs, Schemas, and Tables -- List details about Graviotino entities +- List details about Gravitino entities ## Installation @@ -44,7 +44,7 @@ Apache Gravitino CLI is a command-line tool that interacts with the Gravitino se Before you can build and run this project, it is suggested you have the following installed: -- Java 11 or higher +- Java 8 or higher ### Build the Project @@ -97,29 +97,29 @@ Options ## Commands The following commands are available for entity management: -list: List available entities -details: Show detailed information about an entity -create: Create a new entity -delete: Delete an existing entity -update: Update an existing entity +--list: List available entities +--details: Show detailed information about an entity +--create: Create a new entity +--delete: Delete an existing entity +--update: Update an existing entity ### Examples List All Metalakes ```bash -gcli list +gcli --list ``` Get Details of a Specific Metalake ```bash -gcli metalake details -name my-metalake +gcli metalake --details -name my-metalake ``` List Tables in a Catalog ```bash -gcli metalake list -name my-metalake +gcli metalake --list -name my-metalake ``` ## Running Tests diff --git a/clients/cli/examples.sh b/clients/cli/examples.sh deleted file mode 100755 index 757ef89f017..00000000000 --- a/clients/cli/examples.sh +++ /dev/null @@ -1,111 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -#!/bin/bash - -# These examples assume you have the Apache Gravitino playground running. - -unset GRAVITINO_METALAKE -alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar' - -# display help -gcli --help - -# display version -gcli --version - -# metalake details -gcli details - -# metalake list -gcli list - -# metalake details (all these command are equivalent) -gcli metalake details --name metalake_demo -gcli metalake details --metalake metalake_demo -gcli --command details --metalake metalake_demo -gcli metalake --name metalake_demo details -gcli details --name metalake_demo -gcli details --metalake metalake_demo - -# list all catalogs in a metalake -gcli metalake list --name metalake_demo - -# list catalog schema -gcli catalog list --name metalake_demo.catalog_iceberg -gcli catalog list --name metalake_demo.catalog_mysql -gcli catalog list --name metalake_demo.catalog_postgres -gcli catalog list --name metalake_demo.catalog_hive - -# list catalog details -gcli catalog details --name metalake_demo.catalog_iceberg -gcli catalog details --name metalake_demo.catalog_mysql -gcli catalog details --name metalake_demo.catalog_postgres -gcli catalog details --name metalake_demo.catalog_hive - -# list schema tables -gcli schema list --name metalake_demo.catalog_postgres.hr -gcli schema list --name metalake_demo.catalog_mysql.db -gcli schema list --name metalake_demo.catalog_hive.sales - -# list schema details -gcli schema details --name metalake_demo.catalog_postgres.hr -gcli schema details --name metalake_demo.catalog_mysql.db -gcli schema details --name metalake_demo.catalog_hive.sales - -# list table details -gcli table list --name metalake_demo.catalog_postgres.hr.departments -gcli table list --name metalake_demo.catalog_mysql.db.iceberg_tables -gcli table list --name metalake_demo.catalog_hive.sales.products - -# Exmaples where metalake is set in an evironment variable -export GRAVITINO_METALAKE=metalake_demo - -# metalake details -gcli metalake details - -# list all catalogs in a metalake -gcli metalake list - -# list catalog schema -gcli catalog list --name catalog_iceberg -gcli catalog list --name catalog_mysql -gcli catalog list --name catalog_postgres -gcli catalog list --name catalog_hive - -# list catalog details -gcli catalog details --name catalog_iceberg -gcli catalog details --name catalog_mysql -gcli catalog details --name catalog_postgres -gcli catalog details --name catalog_hive - -# list schema tables -gcli schema list --name catalog_postgres.hr -gcli schema list --name catalog_mysql.db -gcli schema list --name catalog_hive.sales - -# list schema details -gcli schema details --name catalog_postgres.hr -gcli schema details --name catalog_mysql.db -gcli schema details --name catalog_hive.sales - -# list table details -gcli table list --name catalog_postgres.hr.departments -gcli table list --name catalog_mysql.db.iceberg_tables -gcli table list --name catalog_hive.sales.products diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java index a337a56b189..dcae8c1619a 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java @@ -50,11 +50,8 @@ public String getMetalakeName() { metalakeEnv = System.getenv("GRAVITINO_METALAKE"); } - // Check if the metalake name is specified as a command line option - if (line.hasOption(GravitinoOptions.METALAKE)) { - return line.getOptionValue(GravitinoOptions.METALAKE); - // Check if the metalake name is set as an environment variable - } else if (metalakeEnv != null) { + // Check if the metalake name is set as an environment variable + if (metalakeEnv != null) { return metalakeEnv; // Extract the metalake name from the full name option } else if (line.hasOption(GravitinoOptions.NAME)) { @@ -65,46 +62,42 @@ public String getMetalakeName() { } /** - * Retrieves the catalog name from the command line or the second part of the full name option. + * Retrieves the catalog name from the second part of the full name option. * * @return The catalog name, or null if not found. */ public String getCatalogName() { - return getNamePart(GravitinoOptions.CATALOG, 1); + return getNamePart(1); } /** - * Retrieves the schema name from the command line or the third part of the full name option. + * Retrieves the schema name from the third part of the full name option. * * @return The schema name, or null if not found. */ public String getSchemaName() { - return getNamePart(GravitinoOptions.SCHEMA, 2); + return getNamePart(2); } /** - * Retrieves the table name from the command line or the fourth part of the full name option. + * Retrieves the table name from the fourth part of the full name option. * * @return The table name, or null if not found. */ public String getTableName() { - return getNamePart(GravitinoOptions.TABLE, 3); + return getNamePart(3); } /** * Helper method to retrieve a specific part of the full name based on the position of the part. * - * @param entity The part of the name to obtain. * @param position The position of the name part in the full name string. * @return The extracted part of the name, or {@code null} if the name part is missing or * malformed. */ - public String getNamePart(String entity, int position) { - /* Check if the name is specified as a command line option. */ - if (line.hasOption(entity)) { - return line.getOptionValue(entity); - /* Extract the name part from the full name if available. */ - } else if (line.hasOption(GravitinoOptions.NAME)) { + public String getNamePart(int position) { + /* Extract the name part from the full name if available. */ + if (line.hasOption(GravitinoOptions.NAME)) { String[] names = line.getOptionValue(GravitinoOptions.NAME).split("\\."); /* Adjust position if metalake is part of the full name. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java index 270e0b35637..bcb2a95abc7 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java @@ -28,13 +28,7 @@ public class GravitinoOptions { public static final String VERSION = "version"; public static final String SERVER = "server"; public static final String URL = "url"; - public static final String METALAKE = "metalake"; - public static final String CATALOG = "catalog"; - public static final String SCHEMA = "schema"; - public static final String TABLE = "table"; public static final String NAME = "name"; - public static final String ENTITY = "entity"; - public static final String COMMAND = "command"; public static final String LIST = "list"; public static final String DETAILS = "details"; public static final String CREATE = "create"; @@ -54,18 +48,9 @@ public Options options() { options.addOption(createSimpleOption("v", VERSION, "Gravitino client version")); options.addOption(createSimpleOption("r", SERVER, "Gravitino server version")); options.addOption(createArgOption("u", URL, "Gravitino URL (default: http://localhost:8090)")); - options.addOption(createArgOption("m", METALAKE, "metalake name")); - options.addOption(createArgOption("c", CATALOG, "catalog name")); - options.addOption(createArgOption("s", SCHEMA, "schema name")); - options.addOption(createArgOption("t", TABLE, "table name")); options.addOption(createArgOption("f", NAME, "full entity name (dot separated)")); - options.addOption(createArgOption("e", ENTITY, "entity type")); - // One way of specifying the command - options.addOption( - createArgOption("x", COMMAND, "one of: list, details, create, delete, or update")); - - // Another way of specifying the command + // specifying the command options.addOption(createSimpleOption("L", LIST, "list entity children")); options.addOption(createSimpleOption("D", DETAILS, "list details about an entity")); options.addOption(createSimpleOption("C", CREATE, "create an entity")); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java index 47a01a2a587..b36a57be147 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java @@ -51,15 +51,7 @@ public static void main(String[] args) { * @return The command, one of 'details', 'list', 'create', 'delete' or 'update'. */ protected static String resolveCommand(CommandLine line) { - /* Can be specified in the form --command XXX. */ - if (line.hasOption(GravitinoOptions.COMMAND)) { - String command = line.getOptionValue(GravitinoOptions.COMMAND); - if (CommandActions.isValidCommand(command)) { - return command; - } - } - - /* Or as --list, --details --create --delete or --update. */ + /* Passed as --list, --details --create --delete or --update. */ if (line.hasOption(GravitinoOptions.LIST)) { return CommandActions.LIST; } else if (line.hasOption(GravitinoOptions.DETAILS)) { @@ -72,20 +64,7 @@ protected static String resolveCommand(CommandLine line) { return CommandActions.UPDATE; } - /* Or as the bare second argument of two arguments. */ - String[] args = line.getArgs(); - - if (args.length == 1 || args.length == 2) { - String command = args[args.length - 1]; - if (CommandActions.isValidCommand(command)) { - return command; - } else { - System.err.println(ErrorMessages.UNSUPPORTED_COMMAND); - return null; - } - } else { - return CommandActions.DETAILS; /* Default to 'details' command. */ - } + return CommandActions.DETAILS; /* Default to 'details' command. */ } /** @@ -95,29 +74,10 @@ protected static String resolveCommand(CommandLine line) { * @return The entity, e.g. metakalake, catalog, schema, table, etc. */ protected static String resolveEntity(CommandLine line) { - /* Can be specified in the form --entity XXX. */ - if (line.hasOption(GravitinoOptions.ENTITY)) { - String entity = line.getOptionValue(GravitinoOptions.ENTITY); - if (CommandEntities.isValidEntity(entity)) { - return entity; - } - } - - /* Or as --metalake, --catalog, --schema, --table etc. */ - if (line.hasOption(GravitinoOptions.METALAKE)) { - return CommandEntities.METALAKE; - } else if (line.hasOption(GravitinoOptions.CATALOG)) { - return CommandEntities.CATALOG; - } else if (line.hasOption(GravitinoOptions.SCHEMA)) { - return CommandEntities.SCHEMA; - } else if (line.hasOption(GravitinoOptions.TABLE)) { - return CommandEntities.TABLE; - } - - /* Or as the bare first argument of two arguments. */ + /* As the bare first argument. */ String[] args = line.getArgs(); - if (args.length == 2) { + if (args.length > 0) { String entity = args[0]; if (CommandEntities.isValidEntity(entity)) { return entity; diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java index 6cc56249424..d360e5d473e 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java @@ -37,16 +37,6 @@ public void setUp() { options = new GravitinoOptions().options(); } - @Test - public void entityFromCommandLineOption() throws Exception { - String[] args = {"--metalake", "metalake_demo"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String metalakeName = fullName.getMetalakeName(); - assertEquals("metalake_demo", metalakeName); - } - @Test public void entityFromFullNameOption() throws Exception { String[] args = {"--name", "metalakeA.catalogB.schemaC.tableD"}; @@ -73,36 +63,6 @@ public void entityNotFound() throws Exception { assertNull(metalakeName); } - @Test - public void catalogFromCommandLineOption() throws Exception { - String[] args = {"--catalog", "catalogA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String catalogName = fullName.getCatalogName(); - assertEquals("catalogA", catalogName); - } - - @Test - public void schemaFromCommandLineOption() throws Exception { - String[] args = {"--schema", "schemaA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String schemaName = fullName.getSchemaName(); - assertEquals("schemaA", schemaName); - } - - @Test - public void tableFromCommandLineOption() throws Exception { - String[] args = {"--table", "tableA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String tableName = fullName.getTableName(); - assertEquals("tableA", tableName); - } - @Test public void malformedName() throws Exception { String[] args = {"--name", "metalake.catalog"}; @@ -118,7 +78,7 @@ public void missingName() throws Exception { CommandLine commandLine = new DefaultParser().parse(options, args); FullName fullName = new FullName(commandLine); - String namePart = fullName.getNamePart(GravitinoOptions.TABLE, 3); + String namePart = fullName.getNamePart(3); assertNull(namePart); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java index 425dd3f8b9d..304d50b3bc0 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java @@ -54,24 +54,11 @@ public void restoreStreams() { System.setErr(originalErr); } - @Test - public void withCommandParameters() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = {"--entity", "metalake", "--command", "list"}; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.LIST, command); - String entity = Main.resolveEntity(line); - assertEquals(CommandEntities.METALAKE, entity); - } - @Test public void withTwoArgsOnly() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); - String[] args = {"metalake", "details"}; + String[] args = {"metalake", "--details"}; CommandLine line = parser.parse(options, args); String command = Main.resolveCommand(line); From 055678bafd33a140423a50a18ece6b312e2d817a Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 17 Oct 2024 09:45:13 -0700 Subject: [PATCH 10/12] fix merge issue and tests --- .../java/org/apache/gravitino/cli/Main.java | 5 +- .../apache/gravitino/cli/TestFulllName.java | 41 -------------- .../org/apache/gravitino/cli/TestMain.java | 53 ++----------------- 3 files changed, 7 insertions(+), 92 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java index 232919f7640..2a437684839 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java @@ -40,7 +40,7 @@ public static void main(String[] args) { return; } String command = resolveCommand(line); - String entity = resolveEntity(line, command != null); + String entity = resolveEntity(line); GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); commandLine.handleCommandLine(); } catch (ParseException exp) { @@ -76,13 +76,12 @@ protected static String resolveCommand(CommandLine line) { * Determines the entity to act upon based on the command line input. * * @param line Parsed command line object. - * @param command true if command is an argument * @return The entity, e.g. metakalake, catalog, schema, table, etc. */ protected static String resolveEntity(CommandLine line) { /* As the bare first argument. */ String[] args = line.getArgs(); - + if (args.length > 0) { String entity = args[0]; if (CommandEntities.isValidEntity(entity)) { diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java index d873d2a2d58..c1bf5262b89 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java @@ -66,48 +66,7 @@ public void entityNotFound() throws Exception { } @Test -<<<<<<< HEAD - public void justName() throws Exception, MissingArgumentException { - String[] args = {"--name"}; - - assertThrows(MissingArgumentException.class, () -> new DefaultParser().parse(options, args)); - } - - @Test - public void catalogFromCommandLineOption() throws Exception { - String[] args = {"--catalog", "catalogA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String catalogName = fullName.getCatalogName(); - assertEquals("catalogA", catalogName); - } - - @Test - public void schemaFromCommandLineOption() throws Exception { - String[] args = {"--schema", "schemaA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String schemaName = fullName.getSchemaName(); - assertEquals("schemaA", schemaName); - } - - @Test - public void tableFromCommandLineOption() throws Exception { - String[] args = {"--table", "tableA"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - String tableName = fullName.getTableName(); - assertEquals("tableA", tableName); - } - - @Test - public void malformedMissingEntityName() throws Exception { -======= public void malformedName() throws Exception { ->>>>>>> CLI String[] args = {"--name", "metalake.catalog"}; CommandLine commandLine = new DefaultParser().parse(options, args); FullName fullName = new FullName(commandLine); diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java index 8c30b9ac6e6..3187c611706 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java @@ -62,7 +62,7 @@ public void withTwoArgsOnly() throws ParseException { String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); + String entity = Main.resolveEntity(line); assertEquals(CommandEntities.METALAKE, entity); } @@ -70,12 +70,12 @@ public void withTwoArgsOnly() throws ParseException { public void defaultToDetails() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); - String[] args = {"--metalake", "metalake_demo"}; + String[] args = {"metalake", "--name", "metalake_demo"}; CommandLine line = parser.parse(options, args); String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, false); + String entity = Main.resolveEntity(line); assertEquals(CommandEntities.METALAKE, entity); } @@ -104,59 +104,16 @@ public void parseError() throws UnsupportedEncodingException { assertTrue(outContent.toString().contains("usage:")); // Expect help output } - @Test - public void catalogWithTwoArgs() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = {"catalog", "details", "--name", "metalake_demo.catalog_postgres"}; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); - assertEquals(CommandEntities.CATALOG, entity); - } - @Test public void catalogWithOneArg() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); - String[] args = {"catalog", "--command", "details", "--name", "metalake_demo.catalog_postgres"}; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); - assertEquals(CommandEntities.CATALOG, entity); - } - - @Test - public void catalogWithEntity() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = { - "--entity", "catalog", "--command", "details", "--name", "metalake_demo.catalog_postgres" - }; - CommandLine line = parser.parse(options, args); - - String command = Main.resolveCommand(line); - assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, false); - assertEquals(CommandEntities.CATALOG, entity); - } - - @Test - public void catalogWithNoName() throws ParseException { - Options options = new GravitinoOptions().options(); - CommandLineParser parser = new DefaultParser(); - String[] args = { - "catalog", "details", "--metalake", "metalake_demo", "--catalog", "catalog_postgres" - }; + String[] args = {"catalog", "--details", "--name", "metalake_demo.catalog_postgres"}; CommandLine line = parser.parse(options, args); String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); - String entity = Main.resolveEntity(line, true); + String entity = Main.resolveEntity(line); assertEquals(CommandEntities.CATALOG, entity); } } From 464a74b26d165520408b6cfff3565767718ef7b3 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 17 Oct 2024 09:51:08 -0700 Subject: [PATCH 11/12] fix imports --- .../src/test/java/org/apache/gravitino/cli/TestFulllName.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java index c1bf5262b89..541c1e45f51 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java @@ -19,11 +19,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.cli.Options; import org.apache.gravitino.cli.FullName; import org.apache.gravitino.cli.GravitinoOptions; From 05bc9ed4299dd5dc2391fe78db47646f8f9107e6 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 17 Oct 2024 09:52:11 -0700 Subject: [PATCH 12/12] update command options --- clients/cli/docs/README.md | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/clients/cli/docs/README.md b/clients/cli/docs/README.md index fc61816fb68..f778615555c 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/docs/README.md @@ -76,22 +76,26 @@ To run the Gravitino CLI, use the following command structure: ```bash usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options] Options - -c,--catalog catalog name - -C,--create create an entity - -D,--details list details about an entity - -e,--entity entity type - -f,--name full entity name (dot separated) - -h,--help command help information - -L,--list list entity children - -m,--metalake metalake name - -R,--delete delete an entity - -s,--schema schema name - -t,--table table name - -u,--url Gravitino URL (default: http://localhost:8090) - -U,--update update an entity - -v,--version Gravitino client version - -r,--server Gravitino server version - -x,--command one of: list, details, create, delete, or update + -b,--bootstrap Kafka bootstrap servers + -C,--create create an entity + -c,--comment entity comment + -D,--details list details about an entity + -d,--database database name + -h,--help command help information + -j,--jdbcurl JDBC URL + -L,--list list entity children + -l,--user database username + -m,--metastore Hive metastore URI + -n,--name full entity name (dot separated) + -P,--properties show an entities properties + -p,--provider provider one of hadoop, hive, mysql, postgres, iceberg, kafka + -r,--rename new entity name + -R,--delete delete an entity + -u,--url Gravitino URL (default: http://localhost:8090) + -U,--update update an entity + -v,--value property value + -w,--warehouse warehouse name + -z,--password database password ``` ## Commands