From b5e08c0cee6d0294ccf05e8c4037f25d288d7c40 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 13:56:51 +1000 Subject: [PATCH 01/49] Added firest part of CLI code. --- build.gradle.kts | 2 +- clients/cli/README.md | 114 +++++++++++ clients/cli/build.gradle.kts | 59 ++++++ clients/cli/errors.sh | 51 +++++ clients/cli/examples.sh | 111 ++++++++++ .../apache/gravitino/cli/CommandActions.java | 54 +++++ .../apache/gravitino/cli/CommandEntities.java | 52 +++++ .../apache/gravitino/cli/ErrorMessages.java | 32 +++ .../org/apache/gravitino/cli/FullName.java | 123 +++++++++++ .../gravitino/cli/GravitinoCommandLine.java | 191 ++++++++++++++++++ .../gravitino/cli/GravitinoOptions.java | 99 +++++++++ .../java/org/apache/gravitino/cli/Main.java | 132 ++++++++++++ .../cli/commands/AllMetalakeDetails.java | 57 ++++++ .../cli/commands/CatalogDetails.java | 69 +++++++ .../gravitino/cli/commands/Command.java | 60 ++++++ .../gravitino/cli/commands/ListCatalogs.java | 66 ++++++ .../gravitino/cli/commands/ListColumns.java | 81 ++++++++ .../gravitino/cli/commands/ListMetalakes.java | 58 ++++++ .../gravitino/cli/commands/ListSchema.java | 73 +++++++ .../gravitino/cli/commands/ListTables.java | 64 ++++++ .../cli/commands/MetalakeDetails.java | 57 ++++++ .../gravitino/cli/commands/SchemaDetails.java | 76 +++++++ .../gravitino/cli/commands/TableCommand.java | 75 +++++++ .../gravitino/cli/commands/TableDetails.java | 60 ++++++ .../gravitino/cli/commands/Version.java | 49 +++++ .../gravitino/cli/TestCommandActions.java | 69 +++++++ .../gravitino/cli/TestCommandEntities.java | 67 ++++++ .../apache/gravitino/cli/TestFulllName.java | 182 +++++++++++++++++ .../gravitino/cli/TestGravitinoOptions.java | 59 ++++++ .../org/apache/gravitino/cli/TestMain.java | 117 +++++++++++ settings.gradle.kts | 3 +- 31 files changed, 2360 insertions(+), 2 deletions(-) create mode 100644 clients/cli/README.md create mode 100644 clients/cli/build.gradle.kts create mode 100644 clients/cli/errors.sh create mode 100755 clients/cli/examples.sh create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/Main.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableCommand.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java create mode 100644 clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java create mode 100644 clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java create mode 100644 clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java create mode 100644 clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java create mode 100644 clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java diff --git a/build.gradle.kts b/build.gradle.kts index 73cbdd80f24..dfac198af9e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -349,7 +349,7 @@ subprojects { options.locale = "en_US" val projectName = project.name - if (projectName == "common" || projectName == "api" || projectName == "client-java" || projectName == "filesystem-hadoop3") { + if (projectName == "common" || projectName == "api" || projectName == "client-java" || projectName == "client-cli" || projectName == "filesystem-hadoop3") { options { (this as CoreJavadocOptions).addStringOption("Xwerror", "-quiet") isFailOnError = true diff --git a/clients/cli/README.md b/clients/cli/README.md new file mode 100644 index 00000000000..f6f52693cf9 --- /dev/null +++ b/clients/cli/README.md @@ -0,0 +1,114 @@ +# Apache Gravitino CLI + +Apache Gravitino CLI is a command-line tool that interacts with the Gravitino server to manage and query entities like metalakes, catalogs, schemas, and tables. The tool provides options for listing information about Gravitino entities and in future versions support creating, deleting, and updating these entities. + +## Table of Contents + +- [Features](#features) +- [Installation](#installation) +- [Usage](#usage) +- [Commands](#commands) +- [Running Tests](#running-tests) +- [Contributing](#contributing) +- [License](#license) + +## Features + +- Retrieve server version +- Provide help on usage +- Manage Gravitino entities such as Metalakes, Catalogs, Schemas, and Tables +- List details about Graviotino entities + +## Installation + +### Prerequisites + +Before you can build and run this project, it is suggested you have the following installed: + +- Java 11 or higher + +### Build the Project + +1. Clone the entire Gravitino repository: + + ```bash + git clone https://github.com/apache/gravitino + ``` + +2. Build the CLI sub-project using Gradle: + + ```bash + ./gradlew :clients:cli:build + ``` +3. Create an alias: + + ```bash + alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar' + ``` +3. Test the command: + ```bash + gcli --help + ``` + +## Usage + +To run the Gravitino CLI, use the following command structure: + +```bash +java -jar gravitino-cli.jar [options] +Options +-h, --help: Display help information +-v, --version: Display the Gravitino server version +-u, --url : Specify the Gravitino server URL (default: http://localhost:8090) +-m, --metalake : Specify the Metalake to operate on +-c, --catalog : Specify the Catalog to operate on +-s, --schema : Specify the Schema to operate on +-t, --table : Specify the Table to operate on +-x, --command : Specify the action (list, details, create, delete, or update) +``` + +## 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 + +### Examples +List All Metalakes + +```bash +gcli list +``` + +Get Details of a Specific Metalake + +```bash +gcli metalake details -name my-metalake +``` + +List Tables in a Catalog + +```bash +gcli metalake list -name my-metalake.my-catalog +``` + +## Running Tests + +This project includes a suite of unit tests to verify its functionality. + +To run the tests, execute the following command: + +```bash +./gradlew :clients:cli:test +``` + +## Contributing + +We welcome contributions to the Gravitino CLI! + +## License + +This project is licensed under the Apache License 2.0. diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts new file mode 100644 index 00000000000..5e518e100de --- /dev/null +++ b/clients/cli/build.gradle.kts @@ -0,0 +1,59 @@ +/* + * 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. + */ +plugins { + `maven-publish` + id("java") + id("idea") +} + +dependencies { + implementation(project(":clients:client-java")) + implementation(project(":api")) + implementation(project(":common")) + implementation("commons-cli:commons-cli:1.9.0") + implementation("org.slf4j:slf4j-api:2.0.16") + implementation("org.slf4j:slf4j-simple:2.0.16") + + testImplementation(libs.junit.jupiter.api) + testImplementation(libs.junit.jupiter.params) + testImplementation(libs.mockito.core) + + testRuntimeOnly(libs.junit.jupiter.engine) +} + +tasks.build { + dependsOn("javadoc") +} + +tasks.clean { + delete("target") + delete("tmp") +} + +tasks.jar { + manifest { + attributes["Main-Class"] = "org.apache.gravitino.cli.Main" + } + val dependencies = configurations + .runtimeClasspath + .get() + .map(::zipTree) + from(dependencies) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE +} diff --git a/clients/cli/errors.sh b/clients/cli/errors.sh new file mode 100644 index 00000000000..bc67633c06a --- /dev/null +++ b/clients/cli/errors.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# +# 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. +# + +# Some of these examples assume you have the Apache Gravitino playground running. + +alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar' + +# No such command +gcli unknown + +# unknown command and entiry +gcli unknown unknown + +# unknown command and entiry +gcli unknown unknown + +# unknown command +gcli metalake unknown + +# unknown entity +gcli unknown list + +# Name not specified +gcli metalake details + +# Unknown metalake name +gcli metalake details --name unknown + +# Unknown catalog name +gcli catalog details --name metalake_demo.unknown + +# Unknown catalog name +gcli catalog details --name metalake_demo diff --git a/clients/cli/examples.sh b/clients/cli/examples.sh new file mode 100755 index 00000000000..757ef89f017 --- /dev/null +++ b/clients/cli/examples.sh @@ -0,0 +1,111 @@ +# +# 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/CommandActions.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java new file mode 100644 index 00000000000..1077f437c9d --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import java.util.HashSet; + +/** + * The {@code CommandActions} class defines a set of standard commands that can be used in the + * Gravitino CLI. It also can validate if a given command is a valid commands. + */ +public class CommandActions { + public static final String DETAILS = "details"; + public static final String LIST = "list"; + public static final String UPDATE = "update"; + public static final String CREATE = "create"; + public static final String DELETE = "delete"; + + private static final HashSet VALID_COMMANDS = new HashSet<>(); + + static { + VALID_COMMANDS.add(DETAILS); + VALID_COMMANDS.add(LIST); + VALID_COMMANDS.add(UPDATE); + VALID_COMMANDS.add(CREATE); + VALID_COMMANDS.add(DELETE); + } + + /** + * Checks if a given command is a valid command type. + * + * @param command The command to check. + * @return true if the command is valid, false otherwise. + */ + public static boolean isValidCommand(String command) { + return VALID_COMMANDS.contains(command); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java new file mode 100644 index 00000000000..b177acf6c20 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import java.util.HashSet; + +/** + * The {@code CommandEntities} class defines a set of standard entities that can be used in the + * Gravitino CLI. It also can validate if a given entity is a valid entity. + */ +public class CommandEntities { + public static final String METALAKE = "metalake"; + public static final String CATALOG = "catalog"; + public static final String SCHEMA = "schema"; + public static final String TABLE = "table"; + + private static final HashSet VALID_ENTITIES = new HashSet<>(); + + static { + VALID_ENTITIES.add(METALAKE); + VALID_ENTITIES.add(CATALOG); + VALID_ENTITIES.add(SCHEMA); + VALID_ENTITIES.add(TABLE); + } + + /** + * Checks if a given command is a valid entity. + * + * @param entity The entity to check. + * @return true if the command is valid, false otherwise. + */ + public static boolean isValidEntity(String entity) { + return VALID_ENTITIES.contains(entity); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java new file mode 100644 index 00000000000..847b96516c0 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java @@ -0,0 +1,32 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +/* User friendly error messages. */ +public class ErrorMessages { + public static final String UNSUPPORTED_COMMAND = "Unsupported or unknown command."; + public static final String UNKNOWN_ENTITY = "Unknown entity."; + public static final String UNKNOWN_METALAKE = "Unknown metalake name."; + public static final String UNKNOWN_CATALOG = "Unknown catalog name."; + public static final String UNKNOWN_SCHEMA = "Unknown schema name."; + public static final String UNKNOWN_TABLE = "Unknown table name."; + public static final String MALFORMED_NAME = "Malformed entity name."; + public static final String MISSING_NAME = "Missing name."; +} 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 new file mode 100644 index 00000000000..15a94699fba --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java @@ -0,0 +1,123 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import org.apache.commons.cli.CommandLine; + +/** + * Extracts different arts of a full name (dot seperated) from the command line input. This includes + * metalake, catalog, schema, and table names. + */ +public class FullName { + CommandLine line; + + /** + * Constructor for the {@code FullName} class. + * + * @param line The parsed command line arguments. + */ + public FullName(CommandLine line) { + this.line = line; + } + + /** + * Retrieves the metalake name from the command line options, environment variables, or the first + * part of the full name. + * + * @return The metalake name, or null if not found. + */ + public String getMetalakeName() { + String 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) { + return metalakeEnv; + // Extract the metalake name from the full name option + } else if (line.hasOption(GravitinoOptions.NAME)) { + return line.getOptionValue(GravitinoOptions.NAME).split("\\.")[0]; + } + + return null; + } + + /** + * Retrieves the catalog name from the command line or 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); + } + + /** + * Retrieves the schema name from the command line or 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); + } + + /** + * Retrieves the table name from the command line or 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); + } + + /** + * 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)) { + String[] names = line.getOptionValue(GravitinoOptions.NAME).split("\\."); + + /* Adjust position if metalake is part of the full name. */ + String metalakeEnv = System.getenv("GRAVITINO_METALAKE"); + if (metalakeEnv != null) { + position = position - 1; + } + + if (names.length < position) { + System.err.println(ErrorMessages.MALFORMED_NAME); + return null; + } + + return names[position]; + } + + System.err.println(ErrorMessages.MISSING_NAME); + return null; + } +} 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 new file mode 100644 index 00000000000..0a91a2e596a --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java @@ -0,0 +1,191 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.gravitino.cli.commands.AllMetalakeDetails; +import org.apache.gravitino.cli.commands.CatalogDetails; +import org.apache.gravitino.cli.commands.ListCatalogs; +import org.apache.gravitino.cli.commands.ListColumns; +import org.apache.gravitino.cli.commands.ListMetalakes; +import org.apache.gravitino.cli.commands.ListSchema; +import org.apache.gravitino.cli.commands.ListTables; +import org.apache.gravitino.cli.commands.MetalakeDetails; +import org.apache.gravitino.cli.commands.SchemaDetails; +import org.apache.gravitino.cli.commands.TableDetails; +import org.apache.gravitino.cli.commands.Version; + +/* Gravitino Command line */ +public class GravitinoCommandLine { + + private CommandLine line; + private Options options; + private String entity; + private String command; + + public static final String CMD = "gcli"; // recommended name + public static final String DEFAULT_URL = "http://localhost:8090"; + + /** + * Gravitino Command line. + * + * @param line Parsed command line object. + * @param options Available options for the CLI. + * @param entity The entity to apply the command to e.g. metlake, catalog, schema, table etc etc. + * @param command The type of command to run i.e. list, details, update, delete, or create. + */ + public GravitinoCommandLine(CommandLine line, Options options, String entity, String command) { + this.line = line; + this.options = options; + this.entity = entity; + this.command = command; + } + + /** Handles the parsed command line arguments and executes the corresponding actions. */ + public void handleCommandLine() { + /* Display command usage. */ + if (line.hasOption(GravitinoOptions.HELP)) { + GravitinoCommandLine.displayHelp(options); + } + /* Display Gravitino version. */ + else if (line.hasOption(GravitinoOptions.VERSION)) { + new Version(getUrl()).handle(); + } else { + executeCommand(); + } + } + + /** + * Displays the help message for the command line tool. + * + * @param options The command options. + */ + public static void displayHelp(Options options) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp(CMD, options); + } + + /** Executes the appropriate command based on the command type. */ + private void executeCommand() { + if (entity != null) { + if (entity.equals(CommandEntities.TABLE)) { + handleTableCommand(); + } else if (entity.equals(CommandEntities.SCHEMA)) { + handleSchemaCommand(); + } else if (entity.equals(CommandEntities.CATALOG)) { + handleCatalogCommand(); + } else if (entity.equals(CommandEntities.METALAKE)) { + handleMetalakeCommand(); + } + } else { + handleGeneralCommand(); + } + } + + /** + * Handles the command execution for Metalakes based on command type and the command line options. + */ + protected void handleMetalakeCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + + if (CommandActions.DETAILS.equals(command)) { + new MetalakeDetails(url, metalake).handle(); + } else if (CommandActions.LIST.equals(command)) { + new ListCatalogs(url, metalake).handle(); + } + } + + /** + * Handles the command execution for Catalogs based on command type and the command line options. + */ + protected void handleCatalogCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String catalog = name.getCatalogName(); + + if (CommandActions.DETAILS.equals(command)) { + new CatalogDetails(url, metalake, catalog).handle(); + } else if (CommandActions.LIST.equals(command)) { + new ListSchema(url, metalake, catalog).handle(); + } + } + + /** + * Handles the command execution for Schemas based on command type and the command line options. + */ + protected void handleSchemaCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + + if (CommandActions.DETAILS.equals(command)) { + new SchemaDetails(url, metalake, catalog, schema).handle(); + } else if (CommandActions.LIST.equals(command)) { + new ListTables(url, metalake, catalog, schema).handle(); + } + } + + /** + * Handles the command execution for Tables based on command type and the command line options. + */ + protected void handleTableCommand() { + String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + String table = name.getTableName(); + + if (CommandActions.DETAILS.equals(command)) { + new TableDetails(url, metalake, catalog, schema, table).handle(); + } else if (CommandActions.LIST.equals(command)) { + new ListColumns(url, metalake, catalog, schema, table).handle(); + } + } + + /** Handles the command execution based on command type and the command line options. */ + protected void handleGeneralCommand() { + String url = getUrl(); + + if (CommandActions.DETAILS.equals(command)) { + new AllMetalakeDetails(url).handle(); + } else if (CommandActions.LIST.equals(command)) { + new ListMetalakes(url).handle(); + } + } + + /** + * Gets the Gravitino URL from the command line options, or returns the default URL. + * + * @return The Gravitino URL to be used. + */ + protected String getUrl() { + return line.hasOption(GravitinoOptions.URL) + ? line.getOptionValue(GravitinoOptions.URL) + : DEFAULT_URL; + } +} 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 new file mode 100644 index 00000000000..cf4bcd47b41 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java @@ -0,0 +1,99 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import org.apache.commons.cli.Option; +import org.apache.commons.cli.Options; + +/* Gravitino Command line options */ +public class GravitinoOptions { + public static final String HELP = "help"; + public static final String VERSION = "version"; + 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"; + public static final String UPDATE = "update"; + public static final String DELETE = "delete"; + + /** + * Builds and returns the CLI options for Gravitino. + * + * @return Valid CLI command options. + */ + public Options options() { + Options options = new Options(); + + // Add options using helper method to avoid repetition + options.addOption(createSimpleOption("h", HELP, "command help information")); + options.addOption(createSimpleOption("v", VERSION, "Gravitino version")); + options.addOption(createArgOption("u", URL, "Gravitino URL")); + 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 + 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")); + options.addOption(createSimpleOption("U", UPDATE, "update an entity")); + options.addOption(createSimpleOption("R", DELETE, "delete an entity")); + + return options; + } + + /** + * Helper method to create an Option that does not require arguments. + * + * @param shortName The option name as a single letter + * @param longName The long option name. + * @param description The option description. + * @return The Option object. + */ + public Option createSimpleOption(String shortName, String longName, String description) { + return new Option(shortName, longName, false, description); + } + + /** + * Helper method to create an Option that requires an argument. + * + * @param shortName The option name as a single letter + * @param longName The long option name. + * @param description The option description. + * @return The Option object. + */ + public Option createArgOption(String shortName, String longName, String description) { + return new Option(shortName, longName, true, description); + } +} 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 new file mode 100644 index 00000000000..47a01a2a587 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java @@ -0,0 +1,132 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; + +/* Entry point for teh Gravitino command line. */ +public class Main { + + public static void main(String[] args) { + CommandLineParser parser = new DefaultParser(); + Options options = new GravitinoOptions().options(); + + try { + CommandLine line = parser.parse(options, args); + String command = resolveCommand(line); + String entity = resolveEntity(line); + GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); + commandLine.handleCommandLine(); + } catch (ParseException exp) { + System.err.println("Error parsing command line: " + exp.getMessage()); + GravitinoCommandLine.displayHelp(options); + } + } + + /** + * Determines the command based on the command line input. + * + * @param line Parsed command line object. + * @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. */ + if (line.hasOption(GravitinoOptions.LIST)) { + return CommandActions.LIST; + } else if (line.hasOption(GravitinoOptions.DETAILS)) { + return CommandActions.DETAILS; + } else if (line.hasOption(GravitinoOptions.CREATE)) { + return CommandActions.CREATE; + } else if (line.hasOption(GravitinoOptions.DELETE)) { + return CommandActions.DELETE; + } else if (line.hasOption(GravitinoOptions.UPDATE)) { + 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. */ + } + } + + /** + * Determines the entity to act upon based on the command line input. + * + * @param line Parsed command line object. + * @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. */ + String[] args = line.getArgs(); + + if (args.length == 2) { + String entity = args[0]; + if (CommandEntities.isValidEntity(entity)) { + return entity; + } else { + System.err.println(ErrorMessages.UNKNOWN_ENTITY); + return null; + } + } + + return null; + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java new file mode 100644 index 00000000000..6884caf41d4 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java @@ -0,0 +1,57 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Metalake; +import org.apache.gravitino.client.GravitinoAdminClient; + +public class AllMetalakeDetails extends Command { + + /** + * Parameters needed to list all metalakes. + * + * @param url The URL of the Gravitino server. + */ + public AllMetalakeDetails(String url) { + super(url); + } + + /** Displays the name and comment of all metalakes. */ + public void handle() { + Metalake[] metalakes = new Metalake[0]; + try { + GravitinoAdminClient client = buildAdminClient(); + metalakes = client.listMetalakes(); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < metalakes.length; i++) { + if (i > 0) { + all.append(","); + } + all.append(metalakes[i].name() + "," + metalakes[i].comment() + System.lineSeparator()); + } + + System.out.print(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java new file mode 100644 index 00000000000..85b31f5ae6b --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java @@ -0,0 +1,69 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Catalog; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +public class CatalogDetails extends Command { + + protected String metalake; + protected String catalog; + + /** + * Displays the name and comment of a catalog. + * + * @param url The URL of the Gravitino server. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + */ + public CatalogDetails(String url, String metalake, String catalog) { + super(url); + this.metalake = metalake; + this.catalog = catalog; + } + + /** Displays the name and details of a specified catalog. */ + public void handle() { + Catalog result = null; + + try { + GravitinoClient client = buildClient(metalake); + result = client.loadMetalake(metalake).loadCatalog(catalog); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (result != null) { + System.out.println( + result.name() + "," + result.type() + "," + result.provider() + "," + result.comment()); + } + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java new file mode 100644 index 00000000000..8dd84bf41b2 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.client.GravitinoAdminClient; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/* The base for all commands. */ +public abstract class Command { + private final String url; + + /** + * Command constructor. + * + * @param url The URL of the Gravitino server. + */ + protected Command(String url) { + this.url = url; + } + /** All commands have a handle method to handle and run the required command. */ + public abstract void handle(); + + /** + * Builds a {@link GravitinoClient} instance with the provided server URL and metalake. + * + * @param metalake The name of the metalake. + * @return A configured {@link GravitinoClient} instance. + * @throws NoSuchMetalakeException if the specified metalake does not exist. + */ + protected GravitinoClient buildClient(String metalake) throws NoSuchMetalakeException { + return GravitinoClient.builder(url).withMetalake(metalake).withVersionCheckDisabled().build(); + } + + /** + * Builds a {@link GravitinoAdminClient} instance with the server URL. + * + * @return A configured {@link GravitinoAdminClient} instance. + */ + protected GravitinoAdminClient buildAdminClient() { + return GravitinoAdminClient.builder(url).withVersionCheckDisabled().build(); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java new file mode 100644 index 00000000000..e00c79520b4 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -0,0 +1,66 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/* Lists all catalogs in a metalake. */ +public class ListCatalogs extends Command { + + protected String metalake; + + /** + * Lists all catalogs in a metalake. + * + * @param url The URL of the Gravitino server. + * @param metalake The name of the metalake. + */ + public ListCatalogs(String url, String metalake) { + super(url); + this.metalake = metalake; + } + + /** Lists all catalogs in a metalake. */ + public void handle() { + String[] catalogs = new String[0]; + try { + GravitinoClient client = buildClient(metalake); + catalogs = client.listCatalogs(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < catalogs.length; i++) { + if (i > 0) { + all.append(","); + } + all.append(catalogs[i]); + } + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java new file mode 100644 index 00000000000..3e7cbcf674f --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java @@ -0,0 +1,81 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.rel.Column; + +/** Displays the details of a table's columns. */ +public class ListColumns extends TableCommand { + + protected String schema; + protected String table; + + /** + * Displays the details of a table's columns. + * + * @param url The URL of the Gravitino server. + * @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 ListColumns(String url, String metalake, String catalog, String schema, String table) { + super(url, metalake, catalog); + this.schema = schema; + this.table = table; + } + + /** Displays the details of a table's columns. */ + public void handle() { + Column[] columns = null; + + try { + NameIdentifier name = NameIdentifier.of(schema, table); + columns = tableCatalog().loadTable(name).columns(); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < columns.length; i++) { + String name = columns[i].name(); + String dataType = columns[i].dataType().simpleString(); + String comment = columns[i].comment(); + String nullable = columns[i].nullable() ? "null" : ""; + String autoIncrement = columns[i].autoIncrement() ? "auto" : ""; + // TODO default values + all.append( + name + + "," + + dataType + + "," + + comment + + "," + + nullable + + "," + + autoIncrement + + System.lineSeparator()); + } + + System.out.print(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java new file mode 100644 index 00000000000..8f7a73a89d9 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -0,0 +1,58 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Metalake; +import org.apache.gravitino.client.GravitinoAdminClient; + +/** Lists all metalakes. */ +public class ListMetalakes extends Command { + + /** + * List all metalakes. + * + * @param url The URL of the Gravitino server. + */ + public ListMetalakes(String url) { + super(url); + } + + /** Lists all metalakes. */ + public void handle() { + Metalake[] metalakes = new Metalake[0]; + try { + GravitinoAdminClient client = buildAdminClient(); + metalakes = client.listMetalakes(); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < metalakes.length; i++) { + if (i > 0) { + all.append(","); + } + all.append(metalakes[i].name()); + } + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java new file mode 100644 index 00000000000..00845836d5f --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java @@ -0,0 +1,73 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** List all schema names in a schema. */ +public class ListSchema extends Command { + + protected String metalake; + protected String catalog; + + /** + * Lists all schemas in a catalog. + * + * @param url The URL of the Gravitino server. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + */ + public ListSchema(String url, String metalake, String catalog) { + super(url); + this.metalake = metalake; + this.catalog = catalog; + } + + /** List all schema names in a schema. */ + public void handle() { + String[] schemas = new String[0]; + try { + GravitinoClient client = buildClient(metalake); + schemas = client.loadCatalog(catalog).asSchemas().listSchemas(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < schemas.length; i++) { + if (i > 0) { + all.append(","); + } + all.append(schemas[i]); + } + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java new file mode 100644 index 00000000000..22c1e1329d7 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java @@ -0,0 +1,64 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; + +/** List the names of all tables in a schema. */ +public class ListTables extends TableCommand { + + protected String schema; + + /** + * List the names of all tables in a schema. + * + * @param url The URL of the Gravitino server. + * @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, String metalake, String catalog, String schema) { + super(url, metalake, catalog); + this.schema = schema; + } + + /** List the names of all tables in a schema. */ + public void handle() { + NameIdentifier[] tables = null; + Namespace name = Namespace.of(schema); + try { + tables = tableCatalog().listTables(name); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + StringBuilder all = new StringBuilder(); + for (int i = 0; i < tables.length; i++) { + if (i > 0) { + all.append(","); + } + all.append(tables[i].name()); + } + + System.out.println(all.toString()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java new file mode 100644 index 00000000000..575a11d8089 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java @@ -0,0 +1,57 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; + +/** Displays the details of a metalake. */ +public class MetalakeDetails extends Command { + protected String metalake; + + /** + * Displays metalake details. + * + * @param url The URL of the Gravitino server. + * @param metalake The name of the metalake. + */ + public MetalakeDetails(String url, String metalake) { + super(url); + this.metalake = metalake; + } + + /** Displays the name and comment of a metalake. */ + public void handle() { + String comment = ""; + try { + GravitinoClient client = buildClient(metalake); + comment = client.loadMetalake(metalake).comment(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(metalake + "," + comment); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java new file mode 100644 index 00000000000..6972e3dba58 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java @@ -0,0 +1,76 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.Schema; +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; + +/** Displays the details of schema. */ +public class SchemaDetails extends Command { + + protected String metalake; + protected String catalog; + protected String schema; + + /** + * Displays the details of a schema. + * + * @param url The URL of the Gravitino server. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schenma. + */ + public SchemaDetails(String url, String metalake, String catalog, String schema) { + super(url); + this.metalake = metalake; + this.catalog = catalog; + this.schema = schema; + } + + /** Displays the name and comments of schema. */ + public void handle() { + Schema result = null; + + try { + GravitinoClient client = buildClient(metalake); + result = client.loadMetalake(metalake).loadCatalog(catalog).asSchemas().loadSchema(schema); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + return; + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + return; + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + return; + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + if (result != null) { + System.out.println(result.name() + "," + result.comment()); + } + } +} 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 new file mode 100644 index 00000000000..f4059ba508e --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableCommand.java @@ -0,0 +1,75 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.cli.ErrorMessages; +import org.apache.gravitino.client.GravitinoClient; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchMetalakeException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.rel.TableCatalog; + +/* Common code for all table commands. */ +public class TableCommand extends Command { + + protected String metalake; + protected String catalog; + + /** + * Common code for all table commands. + * + * @param url The URL of the Gravitino server. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + */ + public TableCommand(String url, String metalake, String catalog) { + super(url); + this.metalake = metalake; + this.catalog = catalog; + } + + /* Overridden in parent - do nothing */ + public void handle() {} + + /** + * Returns the table catalog for a given metalake and catalog. + * + * @return The TableCatalog or null if an error occurs. + */ + public TableCatalog tableCatalog() { + try { + GravitinoClient client = buildClient(metalake); + return client.loadMetalake(metalake).loadCatalog(catalog).asTableCatalog(); + } catch (NoSuchMetalakeException err) { + System.err.println(ErrorMessages.UNKNOWN_METALAKE); + } catch (NoSuchCatalogException err) { + System.err.println(ErrorMessages.UNKNOWN_CATALOG); + } catch (NoSuchSchemaException err) { + System.err.println(ErrorMessages.UNKNOWN_SCHEMA); + } catch (NoSuchTableException err) { + System.err.println(ErrorMessages.UNKNOWN_TABLE); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + } + + return null; + } +} 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 new file mode 100644 index 00000000000..67679b7a0a5 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDetails.java @@ -0,0 +1,60 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.rel.Table; + +/** Displays the details of a table. */ +public class TableDetails extends TableCommand { + + protected String schema; + protected String table; + + /** + * Displays the details of a table. + * + * @param url The URL of the Gravitino server. + * @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, String metalake, String catalog, String schema, String table) { + super(url, metalake, catalog); + this.schema = schema; + this.table = table; + } + + /** Displays the details of a table. */ + public void handle() { + Table gTable = null; + + try { + NameIdentifier name = NameIdentifier.of(table); + gTable = tableCatalog().loadTable(name); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(gTable.name() + "," + gTable.comment()); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java new file mode 100644 index 00000000000..96efe6acdf9 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.client.GravitinoAdminClient; + +/** Displays the Gravitino server version. */ +public class Version extends Command { + + /** + * Displays the server version. + * + * @param url The URL of the Gravitino server. + */ + public Version(String url) { + super(url); + } + + /** Displays the server version. */ + public void handle() { + String version = "unknown"; + try { + GravitinoAdminClient client = buildAdminClient(); + version = client.serverVersion().version(); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println("Apache Gravitino " + version); + } +} diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java new file mode 100644 index 00000000000..a79f9961fb1 --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java @@ -0,0 +1,69 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public class TestCommandActions { + + @Test + public void ValidCommands() { + assertTrue( + CommandActions.isValidCommand(CommandActions.DETAILS), "DETAILS should be a valid command"); + assertTrue( + CommandActions.isValidCommand(CommandActions.LIST), "LIST should be a valid command"); + assertTrue( + CommandActions.isValidCommand(CommandActions.UPDATE), "UPDATE should be a valid command"); + assertTrue( + CommandActions.isValidCommand(CommandActions.CREATE), "CREATE should be a valid command"); + assertTrue( + CommandActions.isValidCommand(CommandActions.DELETE), "DELETE should be a valid command"); + } + + @Test + public void invalidCommand() { + assertFalse( + CommandActions.isValidCommand("invalidCommand"), "An invalid command should return false"); + } + + @Test + public void nullCommand() { + assertFalse( + CommandActions.isValidCommand(null), + "Null should return false as it's not a valid command"); + } + + @Test + public void emptyCommand() { + assertFalse( + CommandActions.isValidCommand(""), + "Empty string should return false as it's not a valid command"); + } + + @Test + public void caseSensitive() { + assertFalse( + CommandActions.isValidCommand("DETAILS".toUpperCase()), + "Commands should be case-sensitive"); + } +} diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java new file mode 100644 index 00000000000..1ce61cd6f3f --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java @@ -0,0 +1,67 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public class TestCommandEntities { + + @Test + public void validEntities() { + assertTrue( + CommandEntities.isValidEntity(CommandEntities.METALAKE), + "METALAKE should be a valid entity"); + assertTrue( + CommandEntities.isValidEntity(CommandEntities.CATALOG), "CATALOG should be a valid entity"); + assertTrue( + CommandEntities.isValidEntity(CommandEntities.SCHEMA), "SCHEMA should be a valid entity"); + assertTrue( + CommandEntities.isValidEntity(CommandEntities.TABLE), "TABLE should be a valid entity"); + } + + @Test + public void invalidEntity() { + assertFalse( + CommandEntities.isValidEntity("invalidEntity"), "An invalid command should return false"); + } + + @Test + public void nullEntity() { + assertFalse( + CommandEntities.isValidEntity(null), "Null should return false as it's not a valid entity"); + } + + @Test + public void emptyEntity() { + assertFalse( + CommandEntities.isValidEntity(""), + "Empty string should return false as it's not a valid entity"); + } + + @Test + public void caseSensitive() { + assertFalse( + CommandEntities.isValidEntity("DETAILS".toUpperCase()), + "Entities should be case-sensitive"); + } +} 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 new file mode 100644 index 00000000000..07582b9cfb7 --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java @@ -0,0 +1,182 @@ +/* + * 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. + */ + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.apache.gravitino.cli.FullName; +import org.apache.gravitino.cli.GravitinoOptions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class TestFulllName { + + private Options options; + private static final Map DEFAULTS = new HashMap<>(System.getenv()); + private static Map envMap; + + /* Used to simulate setting environment variables. */ + @BeforeAll + public static void accessFields() throws Exception { + envMap = new HashMap<>(); + Class clazz = Class.forName("java.lang.ProcessEnvironment"); + Field environmentField = clazz.getDeclaredField("theEnvironment"); + Field unmodifiableEnvironmentField = clazz.getDeclaredField("theUnmodifiableEnvironment"); + removeStaticFinalAndSetValue(environmentField, envMap); + removeStaticFinalAndSetValue(unmodifiableEnvironmentField, envMap); + } + + private static void removeStaticFinalAndSetValue(Field field, Object value) throws Exception { + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, value); + } + + @BeforeEach + public void setUp() { + options = new GravitinoOptions().options(); + envMap.clear(); + envMap.putAll(DEFAULTS); + } + + @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 entityFromEnvironmentVariable() throws Exception { + String[] args = {}; // No command line metalake option + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + + System.getenv().put("GRAVITINO_METALAKE", "metalake_env"); + + String metalakeName = fullName.getMetalakeName(); + assertEquals("metalake_env", metalakeName); + } + + @Test + public void entityFromFullNameOption() throws Exception { + String[] args = {"--name", "metalakeA.catalogB.schemaC.tableD"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + + String metalakeName = fullName.getMetalakeName(); + assertEquals("metalakeA", metalakeName); + String catalogName = fullName.getCatalogName(); + assertEquals("catalogB", catalogName); + String schemaName = fullName.getSchemaName(); + assertEquals("schemaC", schemaName); + String tableName = fullName.getTableName(); + assertEquals("tableD", tableName); + } + + @Test + public void entityFromFullNameOptionWithoutMetalake() throws Exception { + String[] args = {"--name", "catalogB.schemaC.tableD"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + + System.getenv().put("GRAVITINO_METALAKE", "metalake_env"); + + String metalakeName = fullName.getMetalakeName(); + assertEquals("metalake_env", metalakeName); + String catalogName = fullName.getCatalogName(); + assertEquals("catalogB", catalogName); + String schemaName = fullName.getSchemaName(); + assertEquals("schemaC", schemaName); + String tableName = fullName.getTableName(); + assertEquals("tableD", tableName); + } + + @Test + public void entityNotFound() throws Exception { + String[] args = {}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + + String metalakeName = fullName.getMetalakeName(); + 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"}; + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + String tableName = fullName.getTableName(); + assertNull(tableName); + } + + @Test + public void missingName() throws Exception { + String[] args = {}; // No name provided + CommandLine commandLine = new DefaultParser().parse(options, args); + FullName fullName = new FullName(commandLine); + + String namePart = fullName.getNamePart(GravitinoOptions.TABLE, 3); + assertNull(namePart); + } +} diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java new file mode 100644 index 00000000000..6fd12276d16 --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestGravitinoOptions.java @@ -0,0 +1,59 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.apache.commons.cli.Option; +import org.junit.jupiter.api.Test; + +public class TestGravitinoOptions { + + @Test + public void testCreateSimpleOption() { + GravitinoOptions gravitinoOptions = new GravitinoOptions(); + Option helpOption = + gravitinoOptions.createSimpleOption("h", GravitinoOptions.HELP, "help message"); + + assertEquals("h", helpOption.getOpt(), "Simple option short name should be 'h'."); + assertEquals("help", helpOption.getLongOpt(), "Simple option long name should be 'help'."); + assertFalse(helpOption.hasArg(), "Simple option should not require an argument."); + assertEquals( + "help message", + helpOption.getDescription(), + "Simple option should have correct description."); + } + + @Test + public void testCreateArgOption() { + GravitinoOptions gravitinoOptions = new GravitinoOptions(); + Option urlOption = gravitinoOptions.createArgOption("u", GravitinoOptions.URL, "url argument"); + + assertEquals("u", urlOption.getOpt(), "Argument option short name should be 'u'."); + assertEquals("url", urlOption.getLongOpt(), "Argument option long name should be 'url'."); + assertTrue(urlOption.hasArg(), "Argument option should require an argument."); + assertEquals( + "url argument", + urlOption.getDescription(), + "Argument option should have correct description."); + } +} 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 new file mode 100644 index 00000000000..cc8d43727ef --- /dev/null +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java @@ -0,0 +1,117 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class TestMain { + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + private final PrintStream originalErr = System.err; + + @BeforeEach + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @AfterEach + public void restoreStreams() { + System.setOut(originalOut); + 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"}; + CommandLine line = parser.parse(options, args); + + String command = Main.resolveCommand(line); + assertEquals(CommandActions.DETAILS, command); + String entity = Main.resolveEntity(line); + assertEquals(CommandEntities.METALAKE, entity); + } + + @Test + public void defaultToDetails() throws ParseException { + Options options = new GravitinoOptions().options(); + CommandLineParser parser = new DefaultParser(); + String[] args = {}; + CommandLine line = parser.parse(options, args); + + String command = Main.resolveCommand(line); + assertEquals(CommandActions.DETAILS, command); + String entity = Main.resolveEntity(line); + assertNull(entity); + } + + @Test + public void withHelpOption() throws ParseException { + Options options = new GravitinoOptions().options(); + CommandLineParser parser = new DefaultParser(); + String[] args = {"--help"}; + CommandLine line = parser.parse(options, args); + + GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, null, "help"); + commandLine.handleCommandLine(); + + assertTrue(outContent.toString().contains("usage:")); // Expected help output + } + + @Test + public void parseError() { + String[] args = {"--invalidOption"}; + + Main.main(args); + + assertTrue(errContent.toString().contains("Error parsing command line")); // Expect error + assertTrue(outContent.toString().contains("usage:")); // Expect help output + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index e98f81d39c0..1a67c28b540 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -46,7 +46,8 @@ include( "clients:client-java-runtime", "clients:filesystem-hadoop3", "clients:filesystem-hadoop3-runtime", - "clients:client-python" + "clients:client-python", + "clients:cli", ) include("iceberg:iceberg-common") include("iceberg:iceberg-rest-server") From 655d13380881b28eff0be3e17fe7a36ae7b043d1 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 14:05:50 +1000 Subject: [PATCH 02/49] update CLI option with output --- clients/cli/README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/clients/cli/README.md b/clients/cli/README.md index f6f52693cf9..10f97fd730b 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -55,16 +55,23 @@ Before you can build and run this project, it is suggested you have the followin To run the Gravitino CLI, use the following command structure: ```bash -java -jar gravitino-cli.jar [options] +usage: gcli [options] Options --h, --help: Display help information --v, --version: Display the Gravitino server version --u, --url : Specify the Gravitino server URL (default: http://localhost:8090) --m, --metalake : Specify the Metalake to operate on --c, --catalog : Specify the Catalog to operate on --s, --schema : Specify the Schema to operate on --t, --table : Specify the Table to operate on --x, --command : Specify the action (list, details, create, delete, or update) + -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 version + -x,--command one of: list, details, create, delete, or update ``` ## Commands From 4a29c8bcfe771455f824bd5ad0eac39f7f7da491 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 15:12:47 +1000 Subject: [PATCH 03/49] Add missing license header --- clients/cli/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/clients/cli/README.md b/clients/cli/README.md index 10f97fd730b..3e089c20a4d 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -1,3 +1,22 @@ + + # Apache Gravitino CLI Apache Gravitino CLI is a command-line tool that interacts with the Gravitino server to manage and query entities like metalakes, catalogs, schemas, and tables. The tool provides options for listing information about Gravitino entities and in future versions support creating, deleting, and updating these entities. From 1b12effa7724db980eb14be3bb62e256161a3193 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 15:13:01 +1000 Subject: [PATCH 04/49] Add default --- .../main/java/org/apache/gravitino/cli/GravitinoOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cf4bcd47b41..ae04739933b 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 @@ -51,7 +51,7 @@ public Options options() { // Add options using helper method to avoid repetition options.addOption(createSimpleOption("h", HELP, "command help information")); options.addOption(createSimpleOption("v", VERSION, "Gravitino version")); - options.addOption(createArgOption("u", URL, "Gravitino URL")); + 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")); From 75de71e537bc526565f7eb17bf87f836c302e3bf Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 15:32:57 +1000 Subject: [PATCH 05/49] Spotless on Java 11 --- settings.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 1a67c28b540..d219a0cdf72 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -47,7 +47,7 @@ include( "clients:filesystem-hadoop3", "clients:filesystem-hadoop3-runtime", "clients:client-python", - "clients:cli", + "clients:cli" ) include("iceberg:iceberg-common") include("iceberg:iceberg-rest-server") From 5172afa25d027ee46fdaf5f881fb63d112d476f7 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 16:08:18 +1000 Subject: [PATCH 06/49] Ignore warnings in test with Java 11 --- .../src/test/java/org/apache/gravitino/cli/TestMain.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 cc8d43727ef..425dd3f8b9d 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 @@ -25,6 +25,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; @@ -93,7 +94,8 @@ public void defaultToDetails() throws ParseException { } @Test - public void withHelpOption() throws ParseException { + @SuppressWarnings("DefaultCharset") + public void withHelpOption() throws ParseException, UnsupportedEncodingException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); String[] args = {"--help"}; @@ -106,7 +108,8 @@ public void withHelpOption() throws ParseException { } @Test - public void parseError() { + @SuppressWarnings("DefaultCharset") + public void parseError() throws UnsupportedEncodingException { String[] args = {"--invalidOption"}; Main.main(args); From 0dc885668eca2fbeb87a50cf61d617bda03fa704 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 16:39:59 +1000 Subject: [PATCH 07/49] Disable two tests on JAVA 17 --- .../src/test/java/org/apache/gravitino/cli/TestFulllName.java | 2 ++ 1 file changed, 2 insertions(+) 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 07582b9cfb7..fc3141423b2 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 @@ -75,6 +75,7 @@ public void entityFromCommandLineOption() throws Exception { assertEquals("metalake_demo", metalakeName); } + @DisablesOnJre(JRE.JAVA_17) @Test public void entityFromEnvironmentVariable() throws Exception { String[] args = {}; // No command line metalake option @@ -103,6 +104,7 @@ public void entityFromFullNameOption() throws Exception { assertEquals("tableD", tableName); } + @DisablesOnJre(JRE.JAVA_17) @Test public void entityFromFullNameOptionWithoutMetalake() throws Exception { String[] args = {"--name", "catalogB.schemaC.tableD"}; From 24dee9e5efc26e5a5d53097ba7e778dea4536e7e Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 16:52:43 +1000 Subject: [PATCH 08/49] disabling two tests for now --- .../src/test/java/org/apache/gravitino/cli/TestFulllName.java | 4 ++-- 1 file changed, 2 insertions(+), 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 fc3141423b2..57651031dea 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 @@ -75,7 +75,7 @@ public void entityFromCommandLineOption() throws Exception { assertEquals("metalake_demo", metalakeName); } - @DisablesOnJre(JRE.JAVA_17) + @DDisable("Issues on Java 11 and 17") @Test public void entityFromEnvironmentVariable() throws Exception { String[] args = {}; // No command line metalake option @@ -104,7 +104,7 @@ public void entityFromFullNameOption() throws Exception { assertEquals("tableD", tableName); } - @DisablesOnJre(JRE.JAVA_17) + @DDisable("Issues on Java 11 and 17") @Test public void entityFromFullNameOptionWithoutMetalake() throws Exception { String[] args = {"--name", "catalogB.schemaC.tableD"}; From 0ddbb7d94bf48a0a9798c2c6cb8a595e27caff0e Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 16:58:01 +1000 Subject: [PATCH 09/49] fix disabled tests --- .../test/java/org/apache/gravitino/cli/TestFulllName.java | 5 +++-- 1 file changed, 3 insertions(+), 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 57651031dea..e2796fb8779 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 @@ -31,6 +31,7 @@ import org.apache.gravitino.cli.GravitinoOptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class TestFulllName { @@ -75,7 +76,7 @@ public void entityFromCommandLineOption() throws Exception { assertEquals("metalake_demo", metalakeName); } - @DDisable("Issues on Java 11 and 17") + @Disabled("Issues on Java 11 and 17") @Test public void entityFromEnvironmentVariable() throws Exception { String[] args = {}; // No command line metalake option @@ -104,7 +105,7 @@ public void entityFromFullNameOption() throws Exception { assertEquals("tableD", tableName); } - @DDisable("Issues on Java 11 and 17") + @Disabled("Issues on Java 11 and 17") @Test public void entityFromFullNameOptionWithoutMetalake() throws Exception { String[] args = {"--name", "catalogB.schemaC.tableD"}; From 4b95dd3d1daae9001bf825047704ba0b9968dffc Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 17:47:17 +1000 Subject: [PATCH 10/49] Still having issues on Java 17 --- .../src/test/java/org/apache/gravitino/cli/TestFulllName.java | 3 +-- 1 file changed, 1 insertion(+), 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 e2796fb8779..c905f34f6a5 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 @@ -41,7 +41,6 @@ public class TestFulllName { private static Map envMap; /* Used to simulate setting environment variables. */ - @BeforeAll public static void accessFields() throws Exception { envMap = new HashMap<>(); Class clazz = Class.forName("java.lang.ProcessEnvironment"); @@ -56,7 +55,7 @@ private static void removeStaticFinalAndSetValue(Field field, Object value) thro Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, value); + field.set(null, value); } @BeforeEach From f76fa16b1f392b8e3cf0db6f6fa9d0d15cf7043d Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 2 Oct 2024 22:07:29 +1000 Subject: [PATCH 11/49] remove two tests as Java 17 is still giving issues --- .../apache/gravitino/cli/TestFulllName.java | 60 ------------------- 1 file changed, 60 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 c905f34f6a5..6cc56249424 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 @@ -20,49 +20,21 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Options; import org.apache.gravitino.cli.FullName; import org.apache.gravitino.cli.GravitinoOptions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class TestFulllName { private Options options; - private static final Map DEFAULTS = new HashMap<>(System.getenv()); - private static Map envMap; - - /* Used to simulate setting environment variables. */ - public static void accessFields() throws Exception { - envMap = new HashMap<>(); - Class clazz = Class.forName("java.lang.ProcessEnvironment"); - Field environmentField = clazz.getDeclaredField("theEnvironment"); - Field unmodifiableEnvironmentField = clazz.getDeclaredField("theUnmodifiableEnvironment"); - removeStaticFinalAndSetValue(environmentField, envMap); - removeStaticFinalAndSetValue(unmodifiableEnvironmentField, envMap); - } - - private static void removeStaticFinalAndSetValue(Field field, Object value) throws Exception { - field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, value); - } @BeforeEach public void setUp() { options = new GravitinoOptions().options(); - envMap.clear(); - envMap.putAll(DEFAULTS); } @Test @@ -75,19 +47,6 @@ public void entityFromCommandLineOption() throws Exception { assertEquals("metalake_demo", metalakeName); } - @Disabled("Issues on Java 11 and 17") - @Test - public void entityFromEnvironmentVariable() throws Exception { - String[] args = {}; // No command line metalake option - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - System.getenv().put("GRAVITINO_METALAKE", "metalake_env"); - - String metalakeName = fullName.getMetalakeName(); - assertEquals("metalake_env", metalakeName); - } - @Test public void entityFromFullNameOption() throws Exception { String[] args = {"--name", "metalakeA.catalogB.schemaC.tableD"}; @@ -104,25 +63,6 @@ public void entityFromFullNameOption() throws Exception { assertEquals("tableD", tableName); } - @Disabled("Issues on Java 11 and 17") - @Test - public void entityFromFullNameOptionWithoutMetalake() throws Exception { - String[] args = {"--name", "catalogB.schemaC.tableD"}; - CommandLine commandLine = new DefaultParser().parse(options, args); - FullName fullName = new FullName(commandLine); - - System.getenv().put("GRAVITINO_METALAKE", "metalake_env"); - - String metalakeName = fullName.getMetalakeName(); - assertEquals("metalake_env", metalakeName); - String catalogName = fullName.getCatalogName(); - assertEquals("catalogB", catalogName); - String schemaName = fullName.getSchemaName(); - assertEquals("schemaC", schemaName); - String tableName = fullName.getTableName(); - assertEquals("tableD", tableName); - } - @Test public void entityNotFound() throws Exception { String[] args = {}; From 8cbc605872c287c90b0fcf49464ffa299f390446 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 3 Oct 2024 08:38:26 +1000 Subject: [PATCH 12/49] No need to copy CLI for IT tests --- build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle.kts b/build.gradle.kts index dfac198af9e..42b6352b23f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -756,6 +756,7 @@ tasks { subprojects.forEach() { if (!it.name.startsWith("catalog") && !it.name.startsWith("client") && + !it.name.startsWith("cli") && !it.name.startsWith("authorization") && !it.name.startsWith("filesystem") && !it.name.startsWith("spark") && From fa2cdaf73c39a00d6b4e7417231c0948847af793 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 9 Oct 2024 08:54:43 -0600 Subject: [PATCH 13/49] remove unneeded call --- .../java/org/apache/gravitino/cli/commands/CatalogDetails.java | 2 +- .../java/org/apache/gravitino/cli/commands/SchemaDetails.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java index 85b31f5ae6b..408d3d81fe6 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java @@ -49,7 +49,7 @@ public void handle() { try { GravitinoClient client = buildClient(metalake); - result = client.loadMetalake(metalake).loadCatalog(catalog); + result = client.loadCatalog(catalog); } catch (NoSuchMetalakeException err) { System.err.println(ErrorMessages.UNKNOWN_METALAKE); return; diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java index 6972e3dba58..255d540c3df 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java @@ -54,7 +54,7 @@ public void handle() { try { GravitinoClient client = buildClient(metalake); - result = client.loadMetalake(metalake).loadCatalog(catalog).asSchemas().loadSchema(schema); + result = client.loadCatalog(catalog).asSchemas().loadSchema(schema); } catch (NoSuchMetalakeException err) { System.err.println(ErrorMessages.UNKNOWN_METALAKE); return; From 68f7fa23eeb32f74b0fc017fcc0a55e0791ae07a Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Fri, 11 Oct 2024 12:41:01 -0600 Subject: [PATCH 14/49] change version command into client and server version commands --- .../gravitino/cli/GravitinoCommandLine.java | 7 ++- .../gravitino/cli/GravitinoOptions.java | 4 +- .../gravitino/cli/commands/ClientVersion.java | 48 +++++++++++++++++++ .../{Version.java => ServerVersion.java} | 4 +- 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java rename clients/cli/src/main/java/org/apache/gravitino/cli/commands/{Version.java => ServerVersion.java} (94%) 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 0a91a2e596a..b72db743ef7 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 @@ -24,6 +24,7 @@ import org.apache.commons.cli.Options; import org.apache.gravitino.cli.commands.AllMetalakeDetails; import org.apache.gravitino.cli.commands.CatalogDetails; +import org.apache.gravitino.cli.commands.ClientVersion; import org.apache.gravitino.cli.commands.ListCatalogs; import org.apache.gravitino.cli.commands.ListColumns; import org.apache.gravitino.cli.commands.ListMetalakes; @@ -31,8 +32,8 @@ import org.apache.gravitino.cli.commands.ListTables; import org.apache.gravitino.cli.commands.MetalakeDetails; import org.apache.gravitino.cli.commands.SchemaDetails; +import org.apache.gravitino.cli.commands.ServerVersion; import org.apache.gravitino.cli.commands.TableDetails; -import org.apache.gravitino.cli.commands.Version; /* Gravitino Command line */ public class GravitinoCommandLine { @@ -68,7 +69,9 @@ public void handleCommandLine() { } /* Display Gravitino version. */ else if (line.hasOption(GravitinoOptions.VERSION)) { - new Version(getUrl()).handle(); + new ClientVersion(getUrl()).handle(); + } else if (line.hasOption(GravitinoOptions.SERVER)) { + new ServerVersion(getUrl()).handle(); } else { executeCommand(); } 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 ae04739933b..270e0b35637 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 @@ -26,6 +26,7 @@ public class GravitinoOptions { public static final String HELP = "help"; 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"; @@ -50,7 +51,8 @@ public Options options() { // Add options using helper method to avoid repetition options.addOption(createSimpleOption("h", HELP, "command help information")); - options.addOption(createSimpleOption("v", VERSION, "Gravitino version")); + 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")); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java new file mode 100644 index 00000000000..e8cdc55b666 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package org.apache.gravitino.cli.commands; + +import org.apache.gravitino.client.GravitinoAdminClient; + +/** Displays the Gravitino client version. */ +public class ClientVersion extends Command { + + /** + * Displays the client version. + * + * @param url The URL of the Gravitino server. + */ + public ClientVersion(String url) { + super(url); + } + + /** Displays the client version. */ + public void handle() { + String version = "unknown"; + try { + GravitinoAdminClient client = buildAdminClient(); + version = client.clientVersion().version(); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + System.out.println("Apache Gravitino " + version); + } +} diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java similarity index 94% rename from clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java rename to clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java index 96efe6acdf9..f9da822d49d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Version.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java @@ -22,14 +22,14 @@ import org.apache.gravitino.client.GravitinoAdminClient; /** Displays the Gravitino server version. */ -public class Version extends Command { +public class ServerVersion extends Command { /** * Displays the server version. * * @param url The URL of the Gravitino server. */ - public Version(String url) { + public ServerVersion(String url) { super(url); } From e2ebb7a98395854400f6dc8e9af1d054d917e82c Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Fri, 11 Oct 2024 12:51:24 -0600 Subject: [PATCH 15/49] list entities and commands --- clients/cli/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clients/cli/README.md b/clients/cli/README.md index 3e089c20a4d..fc61816fb68 100644 --- a/clients/cli/README.md +++ b/clients/cli/README.md @@ -74,7 +74,7 @@ Before you can build and run this project, it is suggested you have the followin To run the Gravitino CLI, use the following command structure: ```bash -usage: gcli [options] +usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options] Options -c,--catalog catalog name -C,--create create an entity @@ -89,7 +89,8 @@ Options -t,--table table name -u,--url Gravitino URL (default: http://localhost:8090) -U,--update update an entity - -v,--version Gravitino version + -v,--version Gravitino client version + -r,--server Gravitino server version -x,--command one of: list, details, create, delete, or update ``` From 0e82c8f64a65cef4d78a85c117fd83708856c1c4 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Fri, 11 Oct 2024 12:52:05 -0600 Subject: [PATCH 16/49] Cache the metalake environment variable --- .../src/main/java/org/apache/gravitino/cli/FullName.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 15a94699fba..a337a56b189 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 @@ -26,7 +26,8 @@ * metalake, catalog, schema, and table names. */ public class FullName { - CommandLine line; + private CommandLine line; + private String metalakeEnv; /** * Constructor for the {@code FullName} class. @@ -44,7 +45,10 @@ public FullName(CommandLine line) { * @return The metalake name, or null if not found. */ public String getMetalakeName() { - String metalakeEnv = System.getenv("GRAVITINO_METALAKE"); + // Cache the metalake environment variable + if (metalakeEnv == null) { + metalakeEnv = System.getenv("GRAVITINO_METALAKE"); + } // Check if the metalake name is specified as a command line option if (line.hasOption(GravitinoOptions.METALAKE)) { From 7b97750f8f26d425b5a67e1ee285f48509308123 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Fri, 11 Oct 2024 16:01:41 -0700 Subject: [PATCH 17/49] use libs --- clients/cli/build.gradle.kts | 6 +++--- gradle/libs.versions.toml | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts index 5e518e100de..ec9175374be 100644 --- a/clients/cli/build.gradle.kts +++ b/clients/cli/build.gradle.kts @@ -26,9 +26,9 @@ dependencies { implementation(project(":clients:client-java")) implementation(project(":api")) implementation(project(":common")) - implementation("commons-cli:commons-cli:1.9.0") - implementation("org.slf4j:slf4j-api:2.0.16") - implementation("org.slf4j:slf4j-simple:2.0.16") + implementation(libs.slf4j.api) + implementation(libs.slf4j.simple) + implementation(libs.commons.cli) testImplementation(libs.junit.jupiter.api) testImplementation(libs.junit.jupiter.params) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 255306c983c..0ec893ab072 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -89,7 +89,7 @@ rat-plugin = '0.8.0' shadow-plugin = "8.1.1" kerby = "2.0.3" node-plugin = "7.0.1" -commons-cli = "1.2" +commons-cli = "1.9.0" sun-activation-version = "1.2.0" error-prone = "3.1.0" woodstox-core = "5.3.0" @@ -118,6 +118,7 @@ junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", v junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit" } junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine"} slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" } +slf4j-simple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" } slf4j-jdk14 = { group = "org.slf4j", name = "slf4j-jdk14", version = "1.7.30" } log4j-slf4j2-impl = { group = "org.apache.logging.log4j", name = "log4j-slf4j2-impl", version.ref = "log4j" } log4j-api = { group = "org.apache.logging.log4j", name = "log4j-api", version.ref = "log4j" } From d678b99bb9c3eae329395986840691549aee3515 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Fri, 11 Oct 2024 17:39:11 -0700 Subject: [PATCH 18/49] Trino Connector uses old deprecated CLI --- clients/cli/build.gradle.kts | 2 +- gradle/libs.versions.toml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts index ec9175374be..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) + 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 5a8c222e74f..2888f220876 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -89,7 +89,8 @@ rat-plugin = '0.8.0' shadow-plugin = "8.1.1" kerby = "2.0.3" node-plugin = "7.0.1" -commons-cli = "1.9.0" +commons-cli = "1.2" +commons-cli-new = "1.9.0" sun-activation-version = "1.2.0" error-prone = "3.1.0" woodstox-core = "5.3.0" @@ -210,6 +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" } 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 10af3d26d6900f7172aaeee57d4e3e9a177311dd Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 16 Oct 2024 08:52:59 -0700 Subject: [PATCH 19/49] 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 20/49] 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 21/49] 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 22/49] 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 23/49] 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 24/49] 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 25/49] 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 9808022e03b48c2d351d01a76d91a49d042c0b07 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 17 Oct 2024 09:48:31 -0700 Subject: [PATCH 26/49] update command options --- clients/cli/docs/README.md | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/clients/cli/docs/README.md b/clients/cli/docs/README.md index da684bd5d36..b974051f79e 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/docs/README.md @@ -76,22 +76,16 @@ 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 + -C,--create create an entity + -D,--details list details about an entity + -f,--name full entity name (dot separated) + -h,--help command help information + -L,--list list entity children + -r,--server Gravitino server version + -R,--delete delete an entity + -u,--url Gravitino URL (default: http://localhost:8090) + -U,--update update an entity + -v,--version Gravitino client version ``` ## Commands From 954b351d2ec913f704c6c320a3874a629735b07b Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 16:43:01 +1100 Subject: [PATCH 27/49] Make executable and runnable from bin directory. update command format. --- clients/cli/bin/errors.sh | 17 ++++---- clients/cli/bin/examples.sh | 87 +++++++++++++++++++------------------ 2 files changed, 54 insertions(+), 50 deletions(-) mode change 100644 => 100755 clients/cli/bin/errors.sh diff --git a/clients/cli/bin/errors.sh b/clients/cli/bin/errors.sh old mode 100644 new mode 100755 index 38eb99e1f74..ce3a18da848 --- a/clients/cli/bin/errors.sh +++ b/clients/cli/bin/errors.sh @@ -21,28 +21,29 @@ # Some of these examples assume you have the Apache Gravitino playground running. -alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar' +shopt -s expand_aliases +alias gcli='java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' # No such command 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 index bb8994e03eb..00462cca380 100755 --- a/clients/cli/bin/examples.sh +++ b/clients/cli/bin/examples.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file @@ -17,12 +19,11 @@ # 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' +shopt -s expand_aliases +alias gcli='java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' # display help gcli --help @@ -31,73 +32,75 @@ gcli --help gcli --version # metalake details -gcli --details +gcli details # metalake list -gcli --list +gcli list # list all catalogs in a metalake -gcli metalake --list --name metalake_demo +gcli metalake list --metalake 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 +gcli catalog list --metalake metalake_demo --name catalog_iceberg +gcli catalog list --metalake metalake_demo --name catalog_mysql +gcli catalog list --metalake metalake_demo --name catalog_postgres +gcli catalog list --metalake metalake_demo --name 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 +gcli catalog details --metalake metalake_demo --name catalog_iceberg +gcli catalog details --metalake metalake_demo --name catalog_mysql +gcli catalog details --metalake metalake_demo --name catalog_postgres +gcli catalog details --metalake metalake_demo --name 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 +gcli schema list --metalake metalake_demo --name catalog_postgres.hr +gcli schema list --metalake metalake_demo --name catalog_mysql.db +gcli schema list --metalake metalake_demo --name 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 +gcli schema details --metalake metalake_demo --name catalog_postgres.hr +gcli schema details --metalake metalake_demo --name catalog_mysql.db +gcli schema details --metalake metalake_demo --name 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 +gcli table list --metalake metalake_demo --name catalog_postgres.hr.departments +gcli table list --metalake metalake_demo --name catalog_mysql.db.iceberg_tables +gcli table list --metalake metalake_demo --name catalog_hive.sales.products # Exmaples where metalake is set in an evironment variable export GRAVITINO_METALAKE=metalake_demo # metalake details -gcli metalake --details +gcli metalake details # list all catalogs in a metalake -gcli metalake --list +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 +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 +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 +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 +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 +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 + +unset GRAVITINO_METALAKE From 808fffc8d8fc656605705b3bb60c591793b99de2 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 16:43:42 +1100 Subject: [PATCH 28/49] revert back to using two args and fix command format --- clients/cli/docs/README.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/clients/cli/docs/README.md b/clients/cli/docs/README.md index b974051f79e..fc9801bf5a9 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/docs/README.md @@ -76,44 +76,40 @@ 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,--create create an entity - -D,--details list details about an entity -f,--name full entity name (dot separated) -h,--help command help information -L,--list list entity children -r,--server Gravitino server version - -R,--delete delete an entity -u,--url Gravitino URL (default: http://localhost:8090) - -U,--update update an entity -v,--version Gravitino client version ``` ## 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 --metalake my-metalake ``` List Tables in a Catalog ```bash -gcli metalake --list -name my-metalake +gcli metalake list --metalake my-metalake ``` ## Running Tests From 848a38187f882362f734dc1780be8caef585cb47 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 16:44:55 +1100 Subject: [PATCH 29/49] remove meatlake form name and add back metalake option --- .../org/apache/gravitino/cli/FullName.java | 26 ++++++++----------- .../gravitino/cli/GravitinoOptions.java | 14 ++-------- .../java/org/apache/gravitino/cli/Main.java | 22 +++++++--------- .../apache/gravitino/cli/TestFulllName.java | 2 +- .../org/apache/gravitino/cli/TestMain.java | 2 +- 5 files changed, 25 insertions(+), 41 deletions(-) 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 dcae8c1619a..5d8d9c1c258 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 @@ -39,12 +39,17 @@ public FullName(CommandLine line) { } /** - * Retrieves the metalake name from the command line options, environment variables, or the first - * part of the full name. + * Retrieves the metalake name from the command line options, the GRAVITINO_METALAKE environment + * variable. * * @return The metalake name, or null if not found. */ public String getMetalakeName() { + // If specified on the command line use that + if (line.hasOption(GravitinoOptions.METALAKE)) { + return line.getOptionValue(GravitinoOptions.METALAKE); + } + // Cache the metalake environment variable if (metalakeEnv == null) { metalakeEnv = System.getenv("GRAVITINO_METALAKE"); @@ -53,9 +58,6 @@ public String getMetalakeName() { // 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)) { - return line.getOptionValue(GravitinoOptions.NAME).split("\\.")[0]; } return null; @@ -67,7 +69,7 @@ public String getMetalakeName() { * @return The catalog name, or null if not found. */ public String getCatalogName() { - return getNamePart(1); + return getNamePart(0); } /** @@ -76,7 +78,7 @@ public String getCatalogName() { * @return The schema name, or null if not found. */ public String getSchemaName() { - return getNamePart(2); + return getNamePart(1); } /** @@ -85,7 +87,7 @@ public String getSchemaName() { * @return The table name, or null if not found. */ public String getTableName() { - return getNamePart(3); + return getNamePart(2); } /** @@ -100,13 +102,7 @@ public String getNamePart(int position) { if (line.hasOption(GravitinoOptions.NAME)) { String[] names = line.getOptionValue(GravitinoOptions.NAME).split("\\."); - /* Adjust position if metalake is part of the full name. */ - String metalakeEnv = System.getenv("GRAVITINO_METALAKE"); - if (metalakeEnv != null) { - position = position - 1; - } - - if (names.length < position) { + if (names.length <= position) { System.err.println(ErrorMessages.MALFORMED_NAME); return null; } 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 bcb2a95abc7..1d96b1d298e 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 @@ -29,11 +29,7 @@ public class GravitinoOptions { public static final String SERVER = "server"; public static final String URL = "url"; public static final String NAME = "name"; - public static final String LIST = "list"; - public static final String DETAILS = "details"; - public static final String CREATE = "create"; - public static final String UPDATE = "update"; - public static final String DELETE = "delete"; + public static final String METALAKE = "metalake"; /** * Builds and returns the CLI options for Gravitino. @@ -49,13 +45,7 @@ public Options options() { options.addOption(createSimpleOption("r", SERVER, "Gravitino server version")); options.addOption(createArgOption("u", URL, "Gravitino URL (default: http://localhost:8090)")); options.addOption(createArgOption("f", NAME, "full entity name (dot separated)")); - - // 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")); - options.addOption(createSimpleOption("U", UPDATE, "update an entity")); - options.addOption(createSimpleOption("R", DELETE, "delete an entity")); + options.addOption(createArgOption("m", METALAKE, "Metalake")); return options; } 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 b36a57be147..7ed1407cec9 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,17 +51,15 @@ public static void main(String[] args) { * @return The command, one of 'details', 'list', 'create', 'delete' or 'update'. */ protected static String resolveCommand(CommandLine line) { - /* Passed as --list, --details --create --delete or --update. */ - if (line.hasOption(GravitinoOptions.LIST)) { - return CommandActions.LIST; - } else if (line.hasOption(GravitinoOptions.DETAILS)) { - return CommandActions.DETAILS; - } else if (line.hasOption(GravitinoOptions.CREATE)) { - return CommandActions.CREATE; - } else if (line.hasOption(GravitinoOptions.DELETE)) { - return CommandActions.DELETE; - } else if (line.hasOption(GravitinoOptions.UPDATE)) { - return CommandActions.UPDATE; + + /* As the bare second argument. */ + String[] args = line.getArgs(); + + if (args.length >= 2) { + String action = args[1]; + if (CommandActions.isValidCommand(action)) { + return action; + } } return CommandActions.DETAILS; /* Default to 'details' command. */ @@ -77,7 +75,7 @@ protected static String resolveEntity(CommandLine line) { /* As the bare first argument. */ String[] args = line.getArgs(); - if (args.length > 0) { + if (args.length >= 1) { 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 d360e5d473e..a537784372b 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 @@ -39,7 +39,7 @@ public void setUp() { @Test public void entityFromFullNameOption() throws Exception { - String[] args = {"--name", "metalakeA.catalogB.schemaC.tableD"}; + String[] args = {"--metalake", "metalakeA", "--name", "catalogB.schemaC.tableD"}; 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 304d50b3bc0..c70800232ee 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 @@ -58,7 +58,7 @@ public void restoreStreams() { 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 2fe9a8075de9e0b8688b16d1efbdf8eef7e253bd Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 16:45:28 +1100 Subject: [PATCH 30/49] add Gravitino URL as an environment variable --- .../gravitino/cli/GravitinoCommandLine.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 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 b72db743ef7..d2fbc216a40 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 @@ -42,6 +42,7 @@ public class GravitinoCommandLine { private Options options; private String entity; private String command; + private String urlEnv; public static final String CMD = "gcli"; // recommended name public static final String DEFAULT_URL = "http://localhost:8090"; @@ -182,13 +183,28 @@ protected void handleGeneralCommand() { } /** - * Gets the Gravitino URL from the command line options, or returns the default URL. + * Retrieves the Gravitinno URL from the command line options or the GRAVITINO_URL environment + * variable. * - * @return The Gravitino URL to be used. + * @return The Gravitinno URL, or null if not found. */ - protected String getUrl() { - return line.hasOption(GravitinoOptions.URL) - ? line.getOptionValue(GravitinoOptions.URL) - : DEFAULT_URL; + public String getUrl() { + // If specified on the command line use that + if (line.hasOption(GravitinoOptions.URL)) { + return line.getOptionValue(GravitinoOptions.URL); + } + + // Cache the Gravitino URL environment variable + if (urlEnv == null) { + urlEnv = System.getenv("GRAVITINO_URL"); + } + + // If set return the Gravitino URL environment variable + if (urlEnv != null) { + return urlEnv; + } + + // Return the default localhost URL + return DEFAULT_URL; } } From 526d305affd834f4ee29500532336e29f74f6c9d Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 16:49:32 +1100 Subject: [PATCH 31/49] update README to mention environment variables --- clients/cli/docs/README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clients/cli/docs/README.md b/clients/cli/docs/README.md index fc9801bf5a9..cde73920c2b 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/docs/README.md @@ -17,7 +17,7 @@ under the License. --> -# Apache Gravitino CLI +# Apache Gravitino Command Line Interface Apache Gravitino CLI is a command-line tool that interacts with the Gravitino server to manage and query entities like metalakes, catalogs, schemas, and tables. The tool provides options for listing information about Gravitino entities and in future versions support creating, deleting, and updating these entities. @@ -112,6 +112,24 @@ List Tables in a Catalog gcli metalake list --metalake my-metalake ``` +### Setting the Metalake name + +As dealing with one Metalake is a typical scenario, you can set the Metalake name in several ways. + +1. Passed in on the command line via the `--metalake` parameter. +2. Set via the 'GRAVITINO_METALAKE' environment variable. + +The command line option overrides the environment variable. + +### Setting the Gravitino URL + +As you need to set the Gravitino URL for every command, you can set the URL in several ways. + +1. Passed in on the command line via the `--url` parameter. +2. Set via the 'GRAVITINO_URL' environment variable. + +The command line option overrides the environment variable. + ## Running Tests This project includes a suite of unit tests to verify its functionality. From d2ded4c98c2d3d238f014952fdc8aeee5078478f Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 17:58:11 +1100 Subject: [PATCH 32/49] improved description of met lake name and add to options docs --- clients/cli/docs/README.md | 12 ++++++------ .../org/apache/gravitino/cli/GravitinoOptions.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clients/cli/docs/README.md b/clients/cli/docs/README.md index cde73920c2b..8d382a9cbe4 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/docs/README.md @@ -76,12 +76,12 @@ To run the Gravitino CLI, use the following command structure: ```bash usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options] Options - -f,--name full entity name (dot separated) - -h,--help command help information - -L,--list list entity children - -r,--server Gravitino server version - -u,--url Gravitino URL (default: http://localhost:8090) - -v,--version Gravitino client version + -f,--name full entity name (dot separated) + -h,--help command help information + -m,--metalake Metalake name + -r,--server Gravitino server version + -u,--url Gravitino URL (default: http://localhost:8090) + -v,--version Gravitino client version ``` ## Commands 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 1d96b1d298e..cb3398e4015 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 @@ -45,7 +45,7 @@ public Options options() { options.addOption(createSimpleOption("r", SERVER, "Gravitino server version")); options.addOption(createArgOption("u", URL, "Gravitino URL (default: http://localhost:8090)")); options.addOption(createArgOption("f", NAME, "full entity name (dot separated)")); - options.addOption(createArgOption("m", METALAKE, "Metalake")); + options.addOption(createArgOption("m", METALAKE, "Metalake name")); return options; } From cb5a5d7934b91fe30ba7aa17248e35c4c2294b77 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 22 Oct 2024 18:12:29 +1100 Subject: [PATCH 33/49] remove version number from alias --- clients/cli/docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/cli/docs/README.md b/clients/cli/docs/README.md index 8d382a9cbe4..9d9437377eb 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/docs/README.md @@ -62,7 +62,7 @@ Before you can build and run this project, it is suggested you have the followin 3. Create an alias: ```bash - alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar' + alias gcli='java -jar clients/cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' ``` 3. Test the command: ```bash From 71107fd503da81542c4e6015531513b9329d7298 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 09:56:41 +1100 Subject: [PATCH 34/49] order in alphabetical order --- clients/cli/build.gradle.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts index 3b0434b64b8..0dca3989448 100644 --- a/clients/cli/build.gradle.kts +++ b/clients/cli/build.gradle.kts @@ -23,12 +23,12 @@ plugins { } dependencies { - implementation(project(":clients:client-java")) - implementation(project(":api")) - implementation(project(":common")) + implementation(libs.commons.cli.new) implementation(libs.slf4j.api) implementation(libs.slf4j.simple) - implementation(libs.commons.cli.new) + implementation(project(":api")) + implementation(project(":clients:client-java")) + implementation(project(":common")) testImplementation(libs.junit.jupiter.api) testImplementation(libs.junit.jupiter.params) From a6aeb4220f9372d2946881773523e443570ea3bc Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 10:08:53 +1100 Subject: [PATCH 35/49] add final where needed --- .../main/java/org/apache/gravitino/cli/FullName.java | 6 ++++-- .../apache/gravitino/cli/GravitinoCommandLine.java | 12 +++++++----- .../gravitino/cli/commands/CatalogDetails.java | 4 ++-- .../apache/gravitino/cli/commands/ListCatalogs.java | 2 +- .../apache/gravitino/cli/commands/ListColumns.java | 4 ++-- .../apache/gravitino/cli/commands/ListSchema.java | 4 ++-- .../apache/gravitino/cli/commands/ListTables.java | 2 +- .../gravitino/cli/commands/MetalakeDetails.java | 2 +- .../apache/gravitino/cli/commands/SchemaDetails.java | 6 +++--- .../apache/gravitino/cli/commands/TableCommand.java | 4 ++-- .../apache/gravitino/cli/commands/TableDetails.java | 4 ++-- 11 files changed, 27 insertions(+), 23 deletions(-) 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 5d8d9c1c258..32df42f48c9 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 @@ -26,8 +26,9 @@ * metalake, catalog, schema, and table names. */ public class FullName { - private CommandLine line; + private final CommandLine line; private String metalakeEnv; + private boolean matalakeSet = false; /** * Constructor for the {@code FullName} class. @@ -51,8 +52,9 @@ public String getMetalakeName() { } // Cache the metalake environment variable - if (metalakeEnv == null) { + if (metalakeEnv == null && !matalakeSet) { metalakeEnv = System.getenv("GRAVITINO_METALAKE"); + matalakeSet = true; } // Check if the metalake name is set as an environment variable 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 d2fbc216a40..7229ebfd81a 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 @@ -38,11 +38,12 @@ /* Gravitino Command line */ public class GravitinoCommandLine { - private CommandLine line; - private Options options; - private String entity; - private String command; + private final CommandLine line; + private final Options options; + private final String entity; + private final String command; private String urlEnv; + private boolean urlSet = false; public static final String CMD = "gcli"; // recommended name public static final String DEFAULT_URL = "http://localhost:8090"; @@ -195,8 +196,9 @@ public String getUrl() { } // Cache the Gravitino URL environment variable - if (urlEnv == null) { + if (urlEnv == null && !urlSet) { urlEnv = System.getenv("GRAVITINO_URL"); + urlSet = true; } // If set return the Gravitino URL environment variable diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java index 408d3d81fe6..194f33250dc 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java @@ -27,8 +27,8 @@ public class CatalogDetails extends Command { - protected String metalake; - protected String catalog; + protected final String metalake; + protected final String catalog; /** * Displays the name and comment of a catalog. diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java index e00c79520b4..1e36879646b 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -26,7 +26,7 @@ /* Lists all catalogs in a metalake. */ public class ListCatalogs extends Command { - protected String metalake; + protected final String metalake; /** * Lists all catalogs in a metalake. diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java index 3e7cbcf674f..ef1816937b3 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java @@ -25,8 +25,8 @@ /** Displays the details of a table's columns. */ public class ListColumns extends TableCommand { - protected String schema; - protected String table; + protected final String schema; + protected final String table; /** * Displays the details of a table's columns. diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java index 00845836d5f..f1b32c75fba 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java @@ -27,8 +27,8 @@ /** List all schema names in a schema. */ public class ListSchema extends Command { - protected String metalake; - protected String catalog; + protected final String metalake; + protected final String catalog; /** * Lists all schemas in a catalog. 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 22c1e1329d7..834919ddebd 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 @@ -25,7 +25,7 @@ /** List the names of all tables in a schema. */ public class ListTables extends TableCommand { - protected String schema; + protected final String schema; /** * List the names of all tables in a schema. diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java index 575a11d8089..caaef188dec 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java @@ -25,7 +25,7 @@ /** Displays the details of a metalake. */ public class MetalakeDetails extends Command { - protected String metalake; + protected final String metalake; /** * Displays metalake details. diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java index 255d540c3df..e2b9147b808 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java @@ -29,9 +29,9 @@ /** Displays the details of schema. */ public class SchemaDetails extends Command { - protected String metalake; - protected String catalog; - protected String schema; + protected final String metalake; + protected final String catalog; + protected final String schema; /** * Displays the details of a schema. 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 f4059ba508e..0c09086eaa4 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 @@ -30,8 +30,8 @@ /* Common code for all table commands. */ public class TableCommand extends Command { - protected String metalake; - protected String catalog; + protected final String metalake; + protected final String 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 67679b7a0a5..43625fd77b3 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 @@ -25,8 +25,8 @@ /** Displays the details of a table. */ public class TableDetails extends TableCommand { - protected String schema; - protected String table; + protected final String schema; + protected final String table; /** * Displays the details of a table. From ce3ddc16ac505b12fc1f422f37595ef683926033 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 10:44:30 +1100 Subject: [PATCH 36/49] made private --- .../org/apache/gravitino/cli/GravitinoCommandLine.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 7229ebfd81a..263adfdd443 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 @@ -109,7 +109,7 @@ private void executeCommand() { /** * Handles the command execution for Metalakes based on command type and the command line options. */ - protected void handleMetalakeCommand() { + private void handleMetalakeCommand() { String url = getUrl(); FullName name = new FullName(line); String metalake = name.getMetalakeName(); @@ -124,7 +124,7 @@ protected void handleMetalakeCommand() { /** * Handles the command execution for Catalogs based on command type and the command line options. */ - protected void handleCatalogCommand() { + private void handleCatalogCommand() { String url = getUrl(); FullName name = new FullName(line); String metalake = name.getMetalakeName(); @@ -140,7 +140,7 @@ protected void handleCatalogCommand() { /** * Handles the command execution for Schemas based on command type and the command line options. */ - protected void handleSchemaCommand() { + private void handleSchemaCommand() { String url = getUrl(); FullName name = new FullName(line); String metalake = name.getMetalakeName(); @@ -157,7 +157,7 @@ protected void handleSchemaCommand() { /** * Handles the command execution for Tables based on command type and the command line options. */ - protected void handleTableCommand() { + private void handleTableCommand() { String url = getUrl(); FullName name = new FullName(line); String metalake = name.getMetalakeName(); @@ -173,7 +173,7 @@ protected void handleTableCommand() { } /** Handles the command execution based on command type and the command line options. */ - protected void handleGeneralCommand() { + private void handleGeneralCommand() { String url = getUrl(); if (CommandActions.DETAILS.equals(command)) { From 70aaaf99fc955b4a849c34dcfcb5fa433110ca4e Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 10:52:49 +1100 Subject: [PATCH 37/49] use Joiner instead of StringBuilder --- clients/cli/build.gradle.kts | 1 + .../gravitino/cli/commands/AllMetalakeDetails.java | 12 +++++++----- .../apache/gravitino/cli/commands/ListCatalogs.java | 9 ++------- .../apache/gravitino/cli/commands/ListMetalakes.java | 12 +++++++----- .../apache/gravitino/cli/commands/ListSchema.java | 9 ++------- .../apache/gravitino/cli/commands/ListTables.java | 12 +++++++----- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/clients/cli/build.gradle.kts b/clients/cli/build.gradle.kts index 0dca3989448..9ce570ef88a 100644 --- a/clients/cli/build.gradle.kts +++ b/clients/cli/build.gradle.kts @@ -24,6 +24,7 @@ plugins { dependencies { implementation(libs.commons.cli.new) + implementation(libs.guava) implementation(libs.slf4j.api) implementation(libs.slf4j.simple) implementation(project(":api")) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java index 6884caf41d4..69b5b4f4f54 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java @@ -19,6 +19,9 @@ package org.apache.gravitino.cli.commands; +import com.google.common.base.Joiner; +import java.util.ArrayList; +import java.util.List; import org.apache.gravitino.Metalake; import org.apache.gravitino.client.GravitinoAdminClient; @@ -44,14 +47,13 @@ public void handle() { return; } - StringBuilder all = new StringBuilder(); + List metalakeDetails = new ArrayList<>(); for (int i = 0; i < metalakes.length; i++) { - if (i > 0) { - all.append(","); - } - all.append(metalakes[i].name() + "," + metalakes[i].comment() + System.lineSeparator()); + metalakeDetails.add(metalakes[i].name() + "," + metalakes[i].comment()); } + String all = Joiner.on(System.lineSeparator()).join(metalakeDetails); + System.out.print(all.toString()); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java index 1e36879646b..87417f71cdb 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -19,6 +19,7 @@ package org.apache.gravitino.cli.commands; +import com.google.common.base.Joiner; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchMetalakeException; @@ -53,13 +54,7 @@ public void handle() { return; } - StringBuilder all = new StringBuilder(); - for (int i = 0; i < catalogs.length; i++) { - if (i > 0) { - all.append(","); - } - all.append(catalogs[i]); - } + String all = Joiner.on(",").join(catalogs); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java index 8f7a73a89d9..a85c9ff3207 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -19,6 +19,9 @@ package org.apache.gravitino.cli.commands; +import com.google.common.base.Joiner; +import java.util.ArrayList; +import java.util.List; import org.apache.gravitino.Metalake; import org.apache.gravitino.client.GravitinoAdminClient; @@ -45,14 +48,13 @@ public void handle() { return; } - StringBuilder all = new StringBuilder(); + List metalakeNames = new ArrayList<>(); for (int i = 0; i < metalakes.length; i++) { - if (i > 0) { - all.append(","); - } - all.append(metalakes[i].name()); + metalakeNames.add(metalakes[i].name()); } + String all = Joiner.on(System.lineSeparator()).join(metalakeNames); + System.out.println(all.toString()); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java index f1b32c75fba..efe3e3136b4 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java @@ -19,6 +19,7 @@ package org.apache.gravitino.cli.commands; +import com.google.common.base.Joiner; import org.apache.gravitino.cli.ErrorMessages; import org.apache.gravitino.client.GravitinoClient; import org.apache.gravitino.exceptions.NoSuchCatalogException; @@ -60,13 +61,7 @@ public void handle() { return; } - StringBuilder all = new StringBuilder(); - for (int i = 0; i < schemas.length; i++) { - if (i > 0) { - all.append(","); - } - all.append(schemas[i]); - } + String all = Joiner.on(",").join(schemas); System.out.println(all.toString()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListTables.java index 834919ddebd..9d83ba2c903 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 @@ -19,6 +19,9 @@ package org.apache.gravitino.cli.commands; +import com.google.common.base.Joiner; +import java.util.ArrayList; +import java.util.List; import org.apache.gravitino.NameIdentifier; import org.apache.gravitino.Namespace; @@ -51,14 +54,13 @@ public void handle() { return; } - StringBuilder all = new StringBuilder(); + List tableNames = new ArrayList<>(); for (int i = 0; i < tables.length; i++) { - if (i > 0) { - all.append(","); - } - all.append(tables[i].name()); + tableNames.add(tables[i].name()); } + String all = Joiner.on(System.lineSeparator()).join(tableNames); + System.out.println(all.toString()); } } From 22ca1913281df71a38d703ba677a9adbe76fb1e8 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 11:18:39 +1100 Subject: [PATCH 38/49] update commands --- clients/cli/bin/errors.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/cli/bin/errors.sh b/clients/cli/bin/errors.sh index ce3a18da848..03690e89738 100755 --- a/clients/cli/bin/errors.sh +++ b/clients/cli/bin/errors.sh @@ -40,10 +40,10 @@ gcli unknown list gcli metalake details # Unknown metalake name -gcli metalake details --name unknown +gcli metalake details --metalake unknown # Unknown catalog name -gcli catalog details --name metalake_demo.unknown +gcli catalog details --metalake metalake_demo --name unknown # Missing catalog name -gcli catalog details --name metalake_demo +gcli catalog details --metalake metalake_demo From ab52cf20384405a3708ab4965c629aacc2cbdeb2 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 11:18:58 +1100 Subject: [PATCH 39/49] improve command line error handling --- .../java/org/apache/gravitino/cli/Main.java | 15 +++++++++++---- .../java/org/apache/gravitino/cli/TestMain.java | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 6 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 7ed1407cec9..8e806319631 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 @@ -34,10 +34,12 @@ public static void main(String[] args) { try { CommandLine line = parser.parse(options, args); - String command = resolveCommand(line); String entity = resolveEntity(line); - GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); - commandLine.handleCommandLine(); + String command = resolveCommand(line); + if (entity != null && command != null) { + GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); + commandLine.handleCommandLine(); + } } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); GravitinoCommandLine.displayHelp(options); @@ -62,7 +64,12 @@ protected static String resolveCommand(CommandLine line) { } } - return CommandActions.DETAILS; /* Default to 'details' command. */ + if (args.length == 1) { + return CommandActions.DETAILS; /* Default to 'details' command. */ + } + + System.err.println(ErrorMessages.UNSUPPORTED_COMMAND); + return null; } /** 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 c70800232ee..967b2b36202 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 @@ -68,15 +68,28 @@ public void withTwoArgsOnly() throws ParseException { } @Test - public void defaultToDetails() throws ParseException { + public void defaultToDetailsOneArg() throws ParseException { Options options = new GravitinoOptions().options(); CommandLineParser parser = new DefaultParser(); - String[] args = {}; + String[] args = {"metalake"}; CommandLine line = parser.parse(options, args); String command = Main.resolveCommand(line); assertEquals(CommandActions.DETAILS, command); String entity = Main.resolveEntity(line); + assertEquals(CommandEntities.METALAKE, entity); + } + + @Test + public void withNoArgs() throws ParseException { + Options options = new GravitinoOptions().options(); + CommandLineParser parser = new DefaultParser(); + String[] args = {}; + CommandLine line = parser.parse(options, args); + + String command = Main.resolveCommand(line); + assertNull(command); + String entity = Main.resolveEntity(line); assertNull(entity); } From bd579441bc76bf4b9d58d83ae039e4fbf410862a Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 11:28:28 +1100 Subject: [PATCH 40/49] add executable shell script --- clients/cli/bin/gcli.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 clients/cli/bin/gcli.sh diff --git a/clients/cli/bin/gcli.sh b/clients/cli/bin/gcli.sh new file mode 100755 index 00000000000..f0b36c10746 --- /dev/null +++ b/clients/cli/bin/gcli.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# +# 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. +# + +java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar "$@" \ No newline at end of file From 445cd41afc236cea1951c87eed94ec33b4deb93f Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 11:29:45 +1100 Subject: [PATCH 41/49] put back README and make it developer focused --- clients/cli/{docs => }/README.md | 71 -------------------------------- 1 file changed, 71 deletions(-) rename clients/cli/{docs => }/README.md (54%) diff --git a/clients/cli/docs/README.md b/clients/cli/README.md similarity index 54% rename from clients/cli/docs/README.md rename to clients/cli/README.md index 9d9437377eb..38f5b03dd1c 100644 --- a/clients/cli/docs/README.md +++ b/clients/cli/README.md @@ -23,21 +23,11 @@ Apache Gravitino CLI is a command-line tool that interacts with the Gravitino se ## Table of Contents -- [Features](#features) - [Installation](#installation) -- [Usage](#usage) -- [Commands](#commands) - [Running Tests](#running-tests) - [Contributing](#contributing) - [License](#license) -## Features - -- Retrieve server version -- Provide help on usage -- Manage Gravitino entities such as Metalakes, Catalogs, Schemas, and Tables -- List details about Gravitino entities - ## Installation ### Prerequisites @@ -69,67 +59,6 @@ Before you can build and run this project, it is suggested you have the followin gcli --help ``` -## Usage - -To run the Gravitino CLI, use the following command structure: - -```bash -usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options] -Options - -f,--name full entity name (dot separated) - -h,--help command help information - -m,--metalake Metalake name - -r,--server Gravitino server version - -u,--url Gravitino URL (default: http://localhost:8090) - -v,--version Gravitino client version -``` - -## 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 - -### Examples -List All Metalakes - -```bash -gcli list -``` - -Get Details of a Specific Metalake - -```bash -gcli metalake details --metalake my-metalake -``` - -List Tables in a Catalog - -```bash -gcli metalake list --metalake my-metalake -``` - -### Setting the Metalake name - -As dealing with one Metalake is a typical scenario, you can set the Metalake name in several ways. - -1. Passed in on the command line via the `--metalake` parameter. -2. Set via the 'GRAVITINO_METALAKE' environment variable. - -The command line option overrides the environment variable. - -### Setting the Gravitino URL - -As you need to set the Gravitino URL for every command, you can set the URL in several ways. - -1. Passed in on the command line via the `--url` parameter. -2. Set via the 'GRAVITINO_URL' environment variable. - -The command line option overrides the environment variable. - ## Running Tests This project includes a suite of unit tests to verify its functionality. From 7ea71254c4725ae1699bafda61c377e5fcbe858b Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 12:40:14 +1100 Subject: [PATCH 42/49] support ignore option to ignore client/server version mismatch --- .../gravitino/cli/GravitinoCommandLine.java | 29 +++++++++++-------- .../gravitino/cli/GravitinoOptions.java | 2 ++ .../cli/commands/AllMetalakeDetails.java | 5 ++-- .../cli/commands/CatalogDetails.java | 5 ++-- .../gravitino/cli/commands/ClientVersion.java | 5 ++-- .../gravitino/cli/commands/Command.java | 18 ++++++++++-- .../gravitino/cli/commands/ListCatalogs.java | 5 ++-- .../gravitino/cli/commands/ListColumns.java | 11 +++++-- .../gravitino/cli/commands/ListMetalakes.java | 5 ++-- .../gravitino/cli/commands/ListSchema.java | 5 ++-- .../gravitino/cli/commands/ListTables.java | 6 ++-- .../cli/commands/MetalakeDetails.java | 5 ++-- .../gravitino/cli/commands/SchemaDetails.java | 6 ++-- .../gravitino/cli/commands/ServerVersion.java | 5 ++-- .../gravitino/cli/commands/TableCommand.java | 5 ++-- .../gravitino/cli/commands/TableDetails.java | 11 +++++-- 16 files changed, 87 insertions(+), 41 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 263adfdd443..23fc2acb65d 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 @@ -44,6 +44,7 @@ public class GravitinoCommandLine { private final String command; private String urlEnv; private boolean urlSet = false; + private boolean ignore = false; public static final String CMD = "gcli"; // recommended name public static final String DEFAULT_URL = "http://localhost:8090"; @@ -65,15 +66,19 @@ public GravitinoCommandLine(CommandLine line, Options options, String entity, St /** Handles the parsed command line arguments and executes the corresponding actions. */ public void handleCommandLine() { + if (line.hasOption(GravitinoOptions.IGNORE)) { + ignore = true; + } + /* Display command usage. */ if (line.hasOption(GravitinoOptions.HELP)) { GravitinoCommandLine.displayHelp(options); } /* Display Gravitino version. */ else if (line.hasOption(GravitinoOptions.VERSION)) { - new ClientVersion(getUrl()).handle(); + new ClientVersion(getUrl(), ignore).handle(); } else if (line.hasOption(GravitinoOptions.SERVER)) { - new ServerVersion(getUrl()).handle(); + new ServerVersion(getUrl(), ignore).handle(); } else { executeCommand(); } @@ -115,9 +120,9 @@ private void handleMetalakeCommand() { String metalake = name.getMetalakeName(); if (CommandActions.DETAILS.equals(command)) { - new MetalakeDetails(url, metalake).handle(); + new MetalakeDetails(url, ignore, metalake).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListCatalogs(url, metalake).handle(); + new ListCatalogs(url, ignore, metalake).handle(); } } @@ -131,9 +136,9 @@ private void handleCatalogCommand() { String catalog = name.getCatalogName(); if (CommandActions.DETAILS.equals(command)) { - new CatalogDetails(url, metalake, catalog).handle(); + new CatalogDetails(url, ignore, metalake, catalog).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListSchema(url, metalake, catalog).handle(); + new ListSchema(url, ignore, metalake, catalog).handle(); } } @@ -148,9 +153,9 @@ private void handleSchemaCommand() { String schema = name.getSchemaName(); if (CommandActions.DETAILS.equals(command)) { - new SchemaDetails(url, metalake, catalog, schema).handle(); + new SchemaDetails(url, ignore, metalake, catalog, schema).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListTables(url, metalake, catalog, schema).handle(); + new ListTables(url, ignore, metalake, catalog, schema).handle(); } } @@ -166,9 +171,9 @@ private void handleTableCommand() { String table = name.getTableName(); if (CommandActions.DETAILS.equals(command)) { - new TableDetails(url, metalake, catalog, schema, table).handle(); + new TableDetails(url, ignore, metalake, catalog, schema, table).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListColumns(url, metalake, catalog, schema, table).handle(); + new ListColumns(url, ignore, metalake, catalog, schema, table).handle(); } } @@ -177,9 +182,9 @@ private void handleGeneralCommand() { String url = getUrl(); if (CommandActions.DETAILS.equals(command)) { - new AllMetalakeDetails(url).handle(); + new AllMetalakeDetails(url, ignore).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListMetalakes(url).handle(); + new ListMetalakes(url, ignore).handle(); } } 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 cb3398e4015..9f8d1579a8a 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 @@ -30,6 +30,7 @@ public class GravitinoOptions { public static final String URL = "url"; public static final String NAME = "name"; public static final String METALAKE = "metalake"; + public static final String IGNORE = "ignore"; /** * Builds and returns the CLI options for Gravitino. @@ -46,6 +47,7 @@ public Options options() { options.addOption(createArgOption("u", URL, "Gravitino URL (default: http://localhost:8090)")); options.addOption(createArgOption("f", NAME, "full entity name (dot separated)")); options.addOption(createArgOption("m", METALAKE, "Metalake name")); + options.addOption(createSimpleOption("i", IGNORE, "Ignore client/sever version check")); return options; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java index 69b5b4f4f54..91d5b1c1bc9 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java @@ -31,9 +31,10 @@ public class AllMetalakeDetails extends Command { * Parameters needed to list all metalakes. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. */ - public AllMetalakeDetails(String url) { - super(url); + public AllMetalakeDetails(String url, boolean ignoreVersions) { + super(url, ignoreVersions); } /** Displays the name and comment of all metalakes. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java index 194f33250dc..6df117d0c90 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogDetails.java @@ -34,11 +34,12 @@ public class CatalogDetails extends Command { * Displays the name and comment of a catalog. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @param metalake The name of the metalake. * @param catalog The name of the catalog. */ - public CatalogDetails(String url, String metalake, String catalog) { - super(url); + public CatalogDetails(String url, boolean ignoreVersions, String metalake, String catalog) { + super(url, ignoreVersions); this.metalake = metalake; this.catalog = catalog; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java index e8cdc55b666..6bfa41be415 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ClientVersion.java @@ -28,9 +28,10 @@ public class ClientVersion extends Command { * Displays the client version. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. */ - public ClientVersion(String url) { - super(url); + public ClientVersion(String url, boolean ignoreVersions) { + super(url, ignoreVersions); } /** Displays the client version. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java index 8dd84bf41b2..040bd71417d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java @@ -26,15 +26,19 @@ /* The base for all commands. */ public abstract class Command { private final String url; + private final boolean ignoreVersions; /** * Command constructor. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. */ - protected Command(String url) { + public Command(String url, boolean ignoreVersions) { this.url = url; + this.ignoreVersions = ignoreVersions; } + /** All commands have a handle method to handle and run the required command. */ public abstract void handle(); @@ -46,7 +50,11 @@ protected Command(String url) { * @throws NoSuchMetalakeException if the specified metalake does not exist. */ protected GravitinoClient buildClient(String metalake) throws NoSuchMetalakeException { - return GravitinoClient.builder(url).withMetalake(metalake).withVersionCheckDisabled().build(); + if (ignoreVersions) { + return GravitinoClient.builder(url).withMetalake(metalake).withVersionCheckDisabled().build(); + } else { + return GravitinoClient.builder(url).withMetalake(metalake).build(); + } } /** @@ -55,6 +63,10 @@ protected GravitinoClient buildClient(String metalake) throws NoSuchMetalakeExce * @return A configured {@link GravitinoAdminClient} instance. */ protected GravitinoAdminClient buildAdminClient() { - return GravitinoAdminClient.builder(url).withVersionCheckDisabled().build(); + if (ignoreVersions) { + return GravitinoAdminClient.builder(url).withVersionCheckDisabled().build(); + } else { + return GravitinoAdminClient.builder(url).build(); + } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java index 87417f71cdb..48c27e8220c 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -33,10 +33,11 @@ public class ListCatalogs extends Command { * Lists all catalogs in a metalake. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @param metalake The name of the metalake. */ - public ListCatalogs(String url, String metalake) { - super(url); + public ListCatalogs(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); this.metalake = metalake; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java index ef1816937b3..4b352b5576c 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListColumns.java @@ -32,13 +32,20 @@ public class ListColumns extends TableCommand { * Displays the details of a table's columns. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @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 ListColumns(String url, String metalake, String catalog, String schema, String table) { - super(url, metalake, catalog); + public ListColumns( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String table) { + super(url, ignoreVersions, metalake, catalog); this.schema = schema; this.table = table; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java index a85c9ff3207..e218bea2af1 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -32,9 +32,10 @@ public class ListMetalakes extends Command { * List all metalakes. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. */ - public ListMetalakes(String url) { - super(url); + public ListMetalakes(String url, boolean ignoreVersions) { + super(url, ignoreVersions); } /** Lists all metalakes. */ diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java index efe3e3136b4..a4d18a924b6 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListSchema.java @@ -35,11 +35,12 @@ public class ListSchema extends Command { * Lists all schemas in a catalog. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @param metalake The name of the metalake. * @param catalog The name of the catalog. */ - public ListSchema(String url, String metalake, String catalog) { - super(url); + public ListSchema(String url, boolean ignoreVersions, String metalake, String catalog) { + super(url, ignoreVersions); this.metalake = metalake; this.catalog = catalog; } 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 9d83ba2c903..d1124c48b07 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 @@ -34,12 +34,14 @@ 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 metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of the schenma. */ - public ListTables(String url, String metalake, String catalog, String schema) { - super(url, metalake, catalog); + public ListTables( + String url, boolean ignoreVersions, String metalake, String catalog, String schema) { + super(url, ignoreVersions, metalake, catalog); this.schema = schema; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java index caaef188dec..46d61de8c42 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java @@ -31,10 +31,11 @@ public class MetalakeDetails extends Command { * Displays metalake details. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @param metalake The name of the metalake. */ - public MetalakeDetails(String url, String metalake) { - super(url); + public MetalakeDetails(String url, boolean ignoreVersions, String metalake) { + super(url, ignoreVersions); this.metalake = metalake; } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java index e2b9147b808..9229d152d3d 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaDetails.java @@ -37,12 +37,14 @@ public class SchemaDetails extends Command { * Displays the details of a schema. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @param metalake The name of the metalake. * @param catalog The name of the catalog. * @param schema The name of the schenma. */ - public SchemaDetails(String url, String metalake, String catalog, String schema) { - super(url); + public SchemaDetails( + String url, boolean ignoreVersions, String metalake, String catalog, String schema) { + super(url, ignoreVersions); this.metalake = metalake; this.catalog = catalog; this.schema = schema; diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java index f9da822d49d..456226732f9 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ServerVersion.java @@ -28,9 +28,10 @@ public class ServerVersion extends Command { * Displays the server version. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. */ - public ServerVersion(String url) { - super(url); + public ServerVersion(String url, boolean ignoreVersions) { + super(url, ignoreVersions); } /** Displays the server version. */ 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 0c09086eaa4..cecff12f4e9 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 @@ -37,11 +37,12 @@ public class TableCommand extends Command { * Common code for all table commands. * * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. * @param metalake The name of the metalake. * @param catalog The name of the catalog. */ - public TableCommand(String url, String metalake, String catalog) { - super(url); + public TableCommand(String url, boolean ignoreVersions, String metalake, String catalog) { + super(url, ignoreVersions); this.metalake = metalake; this.catalog = catalog; } 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 43625fd77b3..fb31585292c 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 @@ -32,13 +32,20 @@ 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 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, String metalake, String catalog, String schema, String table) { - super(url, metalake, catalog); + public TableDetails( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String table) { + super(url, ignoreVersions, metalake, catalog); this.schema = schema; this.table = table; } From 0a8844ea784f40b43881e0685258bca2cd9fa1cd Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 13:13:12 +1100 Subject: [PATCH 43/49] move list commands up one entity --- .../apache/gravitino/cli/CommandEntities.java | 2 + .../gravitino/cli/GravitinoCommandLine.java | 48 ++++++++++--------- .../gravitino/cli/TestCommandEntities.java | 2 + 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java index b177acf6c20..66e67930469 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandEntities.java @@ -30,6 +30,7 @@ public class CommandEntities { public static final String CATALOG = "catalog"; public static final String SCHEMA = "schema"; public static final String TABLE = "table"; + public static final String COLUMN = "column"; private static final HashSet VALID_ENTITIES = new HashSet<>(); @@ -38,6 +39,7 @@ public class CommandEntities { VALID_ENTITIES.add(CATALOG); VALID_ENTITIES.add(SCHEMA); VALID_ENTITIES.add(TABLE); + VALID_ENTITIES.add(COLUMN); } /** 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 23fc2acb65d..dacf811b4e3 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 @@ -22,7 +22,6 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; -import org.apache.gravitino.cli.commands.AllMetalakeDetails; import org.apache.gravitino.cli.commands.CatalogDetails; import org.apache.gravitino.cli.commands.ClientVersion; import org.apache.gravitino.cli.commands.ListCatalogs; @@ -96,18 +95,16 @@ public static void displayHelp(Options options) { /** Executes the appropriate command based on the command type. */ private void executeCommand() { - if (entity != null) { - if (entity.equals(CommandEntities.TABLE)) { - handleTableCommand(); - } else if (entity.equals(CommandEntities.SCHEMA)) { - handleSchemaCommand(); - } else if (entity.equals(CommandEntities.CATALOG)) { - handleCatalogCommand(); - } else if (entity.equals(CommandEntities.METALAKE)) { - handleMetalakeCommand(); - } - } else { - handleGeneralCommand(); + if (entity.equals(CommandEntities.COLUMN)) { + handleColumnCommand(); + } else if (entity.equals(CommandEntities.TABLE)) { + handleTableCommand(); + } else if (entity.equals(CommandEntities.SCHEMA)) { + handleSchemaCommand(); + } else if (entity.equals(CommandEntities.CATALOG)) { + handleCatalogCommand(); + } else if (entity.equals(CommandEntities.METALAKE)) { + handleMetalakeCommand(); } } @@ -122,7 +119,7 @@ private void handleMetalakeCommand() { if (CommandActions.DETAILS.equals(command)) { new MetalakeDetails(url, ignore, metalake).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListCatalogs(url, ignore, metalake).handle(); + new ListMetalakes(url, ignore).handle(); } } @@ -138,7 +135,7 @@ private void handleCatalogCommand() { if (CommandActions.DETAILS.equals(command)) { new CatalogDetails(url, ignore, metalake, catalog).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListSchema(url, ignore, metalake, catalog).handle(); + new ListCatalogs(url, ignore, metalake).handle(); } } @@ -155,7 +152,7 @@ private void handleSchemaCommand() { if (CommandActions.DETAILS.equals(command)) { new SchemaDetails(url, ignore, metalake, catalog, schema).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListTables(url, ignore, metalake, catalog, schema).handle(); + new ListSchema(url, ignore, metalake, catalog).handle(); } } @@ -173,18 +170,23 @@ private void handleTableCommand() { if (CommandActions.DETAILS.equals(command)) { new TableDetails(url, ignore, metalake, catalog, schema, table).handle(); } else if (CommandActions.LIST.equals(command)) { - new ListColumns(url, ignore, metalake, catalog, schema, table).handle(); + new ListTables(url, ignore, metalake, catalog, schema).handle(); } } - /** Handles the command execution based on command type and the command line options. */ - private void handleGeneralCommand() { + /** + * Handles the command execution for Columns based on command type and the command line options. + */ + private void handleColumnCommand() { String url = getUrl(); + FullName name = new FullName(line); + String metalake = name.getMetalakeName(); + String catalog = name.getCatalogName(); + String schema = name.getSchemaName(); + String table = name.getTableName(); - if (CommandActions.DETAILS.equals(command)) { - new AllMetalakeDetails(url, ignore).handle(); - } else if (CommandActions.LIST.equals(command)) { - new ListMetalakes(url, ignore).handle(); + if (CommandActions.LIST.equals(command)) { + new ListColumns(url, ignore, metalake, catalog, schema, table).handle(); } } diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java index 1ce61cd6f3f..423834bfcc0 100644 --- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java +++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandEntities.java @@ -37,6 +37,8 @@ public void validEntities() { CommandEntities.isValidEntity(CommandEntities.SCHEMA), "SCHEMA should be a valid entity"); assertTrue( CommandEntities.isValidEntity(CommandEntities.TABLE), "TABLE should be a valid entity"); + assertTrue( + CommandEntities.isValidEntity(CommandEntities.COLUMN), "COLUMN should be a valid entity"); } @Test From c342d7ec39894216a4cd5ac9b9afdea14b8425fc Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 13:17:49 +1100 Subject: [PATCH 44/49] add comment --- .../main/java/org/apache/gravitino/cli/GravitinoCommandLine.java | 1 + 1 file changed, 1 insertion(+) 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 dacf811b4e3..5f5be22dd0c 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 @@ -65,6 +65,7 @@ public GravitinoCommandLine(CommandLine line, Options options, String entity, St /** Handles the parsed command line arguments and executes the corresponding actions. */ public void handleCommandLine() { + /* Check if you should ignore client/version versions */ if (line.hasOption(GravitinoOptions.IGNORE)) { ignore = true; } From d2b28afbd7a8cad18860328dba8732f7472a75e2 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 13:32:39 +1100 Subject: [PATCH 45/49] no need for class --- .../java/org/apache/gravitino/cli/GravitinoCommandLine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5f5be22dd0c..3876d14bd2b 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 @@ -72,7 +72,7 @@ public void handleCommandLine() { /* Display command usage. */ if (line.hasOption(GravitinoOptions.HELP)) { - GravitinoCommandLine.displayHelp(options); + displayHelp(options); } /* Display Gravitino version. */ else if (line.hasOption(GravitinoOptions.VERSION)) { From 038e1f66f85484623b6c0681c750259b6a3a0543 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 15:43:13 +1100 Subject: [PATCH 46/49] fix command error handling and unwanted output --- .../gravitino/cli/GravitinoCommandLine.java | 23 +++++++++++-------- .../java/org/apache/gravitino/cli/Main.java | 13 +++++++---- .../org/apache/gravitino/cli/TestMain.java | 2 +- 3 files changed, 23 insertions(+), 15 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 3876d14bd2b..e60c7662dc5 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 @@ -65,22 +65,27 @@ public GravitinoCommandLine(CommandLine line, Options options, String entity, St /** Handles the parsed command line arguments and executes the corresponding actions. */ public void handleCommandLine() { - /* Check if you should ignore client/version versions */ + /* Check if you should ignore client/version versions */ if (line.hasOption(GravitinoOptions.IGNORE)) { ignore = true; } + executeCommand(); + } + + /** Handles the parsed command line arguments and executes the corresponding actions. */ + public void handleSimpleLine() { /* Display command usage. */ if (line.hasOption(GravitinoOptions.HELP)) { displayHelp(options); } - /* Display Gravitino version. */ + /* Display Gravitino client version. */ else if (line.hasOption(GravitinoOptions.VERSION)) { new ClientVersion(getUrl(), ignore).handle(); - } else if (line.hasOption(GravitinoOptions.SERVER)) { + } + /* Display Gravitino server version. */ + else if (line.hasOption(GravitinoOptions.SERVER)) { new ServerVersion(getUrl(), ignore).handle(); - } else { - executeCommand(); } } @@ -131,9 +136,9 @@ private void handleCatalogCommand() { String url = getUrl(); FullName name = new FullName(line); String metalake = name.getMetalakeName(); - String catalog = name.getCatalogName(); if (CommandActions.DETAILS.equals(command)) { + String catalog = name.getCatalogName(); new CatalogDetails(url, ignore, metalake, catalog).handle(); } else if (CommandActions.LIST.equals(command)) { new ListCatalogs(url, ignore, metalake).handle(); @@ -148,9 +153,9 @@ private void handleSchemaCommand() { FullName name = new FullName(line); String metalake = name.getMetalakeName(); String catalog = name.getCatalogName(); - String schema = name.getSchemaName(); if (CommandActions.DETAILS.equals(command)) { + String schema = name.getSchemaName(); new SchemaDetails(url, ignore, metalake, catalog, schema).handle(); } else if (CommandActions.LIST.equals(command)) { new ListSchema(url, ignore, metalake, catalog).handle(); @@ -166,9 +171,9 @@ private void handleTableCommand() { String metalake = name.getMetalakeName(); String catalog = name.getCatalogName(); String schema = name.getSchemaName(); - String table = name.getTableName(); if (CommandActions.DETAILS.equals(command)) { + String table = name.getTableName(); new TableDetails(url, ignore, metalake, catalog, schema, table).handle(); } else if (CommandActions.LIST.equals(command)) { new ListTables(url, ignore, metalake, catalog, schema).handle(); @@ -184,9 +189,9 @@ private void handleColumnCommand() { String metalake = name.getMetalakeName(); String catalog = name.getCatalogName(); String schema = name.getSchemaName(); - String table = name.getTableName(); if (CommandActions.LIST.equals(command)) { + String table = name.getTableName(); new ListColumns(url, ignore, metalake, catalog, schema, table).handle(); } } 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 8e806319631..68db676c587 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 @@ -36,9 +36,12 @@ public static void main(String[] args) { CommandLine line = parser.parse(options, args); String entity = resolveEntity(line); String command = resolveCommand(line); + GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); + if (entity != null && command != null) { - GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, entity, command); commandLine.handleCommandLine(); + } else { + commandLine.handleSimpleLine(); } } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); @@ -57,15 +60,15 @@ protected static String resolveCommand(CommandLine line) { /* As the bare second argument. */ String[] args = line.getArgs(); - if (args.length >= 2) { + if (args.length == 2) { String action = args[1]; if (CommandActions.isValidCommand(action)) { return action; } - } - - if (args.length == 1) { + } else if (args.length == 1) { return CommandActions.DETAILS; /* Default to 'details' command. */ + } else if (args.length == 0) { + return null; } System.err.println(ErrorMessages.UNSUPPORTED_COMMAND); 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 967b2b36202..388d5da7396 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 @@ -102,7 +102,7 @@ public void withHelpOption() throws ParseException, UnsupportedEncodingException CommandLine line = parser.parse(options, args); GravitinoCommandLine commandLine = new GravitinoCommandLine(line, options, null, "help"); - commandLine.handleCommandLine(); + commandLine.handleSimpleLine(); assertTrue(outContent.toString().contains("usage:")); // Expected help output } From ce5fa18a8b1084f5357bd3972caeb3d8508d9664 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 16:20:03 +1100 Subject: [PATCH 47/49] remove example scripts --- clients/cli/bin/examples.sh | 66 ++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/clients/cli/bin/examples.sh b/clients/cli/bin/examples.sh index 00462cca380..45b331c5a84 100755 --- a/clients/cli/bin/examples.sh +++ b/clients/cli/bin/examples.sh @@ -31,20 +31,14 @@ gcli --help # display version gcli --version -# metalake details -gcli details +# list all metalakes +gcli metalake list -# metalake list -gcli list +# metalake details +gcli metlake details --metalake metalake_demo -# list all catalogs in a metalake -gcli metalake list --metalake metalake_demo - -# list catalog schema -gcli catalog list --metalake metalake_demo --name catalog_iceberg -gcli catalog list --metalake metalake_demo --name catalog_mysql -gcli catalog list --metalake metalake_demo --name catalog_postgres -gcli catalog list --metalake metalake_demo --name catalog_hive +# list all catalogs +gcli catalog list --metalake metalake_demo # list catalog details gcli catalog details --metalake metalake_demo --name catalog_iceberg @@ -52,20 +46,26 @@ gcli catalog details --metalake metalake_demo --name catalog_mysql gcli catalog details --metalake metalake_demo --name catalog_postgres gcli catalog details --metalake metalake_demo --name catalog_hive -# list schema tables -gcli schema list --metalake metalake_demo --name catalog_postgres.hr -gcli schema list --metalake metalake_demo --name catalog_mysql.db -gcli schema list --metalake metalake_demo --name catalog_hive.sales +# list catalog schemas +gcli schema list --metalake metalake_demo --name catalog_iceberg +gcli schema list --metalake metalake_demo --name catalog_mysql +gcli schema list --metalake metalake_demo --name catalog_postgres +gcli schema list --metalake metalake_demo --name catalog_hive # list schema details gcli schema details --metalake metalake_demo --name catalog_postgres.hr gcli schema details --metalake metalake_demo --name catalog_mysql.db gcli schema details --metalake metalake_demo --name catalog_hive.sales +# list schema tables +gcli table list --metalake metalake_demo --name catalog_postgres.hr +gcli table list --metalake metalake_demo --name catalog_mysql.db +gcli table list --metalake metalake_demo --name catalog_hive.sales + # list table details -gcli table list --metalake metalake_demo --name catalog_postgres.hr.departments -gcli table list --metalake metalake_demo --name catalog_mysql.db.iceberg_tables -gcli table list --metalake metalake_demo --name catalog_hive.sales.products +gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments +gcli column list --metalake metalake_demo --name catalog_mysql.db.iceberg_tables +gcli column list --metalake metalake_demo --name catalog_hive.sales.products # Exmaples where metalake is set in an evironment variable export GRAVITINO_METALAKE=metalake_demo @@ -73,34 +73,34 @@ export GRAVITINO_METALAKE=metalake_demo # metalake details gcli metalake details -# list all catalogs in a metalake +# 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 catalog schema +gcli schema list --name catalog_iceberg +gcli schema list --name catalog_mysql +gcli schema list --name catalog_postgres +gcli schema list --name catalog_hive # 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 schema tables +gcli table list --name catalog_postgres.hr +gcli table list --name catalog_mysql.db +gcli table list --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 +gcli column list --name catalog_postgres.hr.departments +gcli column list --name catalog_mysql.db.iceberg_tables +gcli column list --name catalog_hive.sales.products unset GRAVITINO_METALAKE From 069f425535230ab93b0d2a8d550be1cd9b368745 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Wed, 23 Oct 2024 16:20:42 +1100 Subject: [PATCH 48/49] add CLI documentation --- docs/cli.md | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/index.md | 5 +- 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 docs/cli.md diff --git a/docs/cli.md b/docs/cli.md new file mode 100644 index 00000000000..98a311fefed --- /dev/null +++ b/docs/cli.md @@ -0,0 +1,155 @@ +--- +title: 'Apache Gravitino Command Line Interface' +slug: /cli +keyword: cli +last_update: + date: 2024-10-23 + author: justinmclean +license: 'This software is licensed under the Apache License version 2.' +--- + +This document primarily outlines how users can manage metadata within Apache Gravitino using the Command Line Interface (CLI). The CLI is accessible via a terminal window as an alternative to writing code or using the REST interface. + +Currently, you can view basic metadata information for metalakes, catalogs, schema, and tables. The ability to create, update, and delete metalakes and support additional entities in planned in the near future. + +## Running the CLI + +You can set up an alias for the command like so: + +```bash +alias gcli='java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' +``` + +Or use the `gcli.sh` script found in the `clients/cli/bin/` directory to run the CLI. + +## Usage + + To run the Gravitino CLI, use the following command structure: + + ```bash + usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options] + Options + -f,--name full entity name (dot separated) + -h,--help command help information + -i,--ignore Ignore client/sever version check + -m,--metalake Metalake name + -r,--server Gravitino server version + -u,--url Gravitino URL (default: http://localhost:8090) + -v,--version Gravitino client version + ``` + +## 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 + +### Setting the Metalake name + +As dealing with one Metalake is a typical scenario, you can set the Metalake name in several ways. + +1. Passed in on the command line via the `--metalake` parameter. +2. Set via the `GRAVITINO_METALAKE` environment variable. + +The command line option overrides the environment variable. + +## Setting the Gravitino URL + +As you need to set the Gravitino URL for every command, you can set the URL in several ways. + +1. Passed in on the command line via the `--url` parameter. +2. Set via the 'GRAVITINO_URL' environment variable. + +The command line option overrides the environment variable. + +## Manage metadata + +All the commands are performed by using the [Java API](api/java-api) internally. + +### Display help + +To display help on command usage: + +```bash +gcli --help +``` + +### Display client version + +To display the client version: + +```bash +gcli --version +``` + +### Display server version + +To display the server version: + +```bash +gcli --server +``` + +### Client/server version mismatch + +If the client and server are running different versions of the Gravitino software then you need an additional `--ignore` option for the command to run. + +### Metalake + +#### Show all metalakes + +```bash +gcli metalake list +``` + +#### Show a metalake details + +```bash +gcli metalake details --metalake metalake_demo +``` + +### Catalog + +#### Show all catalogs in a metalake + +```bash +gcli catalog list --metalake metalake_demo +``` + +#### Show a catalogs details + +```bash +gcli catalog details --metalake metalake_demo --name catalog_postgres +``` + +### Schema + +#### Show all schemas in a catalog + +```bash +gcli schema list --metalake metalake_demo --name catalog_postgres +``` + +#### Show a schema details + +```bash +gcli schema details --metalake metalake_demo --name catalog_postgres.hr +``` + +### Table + +#### Show all tables + +```bash +gcli table list --metalake metalake_demo --name catalog_postgres.hr +``` + +#### Show tables details + +```bash +gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments +``` diff --git a/docs/index.md b/docs/index.md index f2d7584e134..2e683453b8b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -61,7 +61,10 @@ Also, you can find the complete REST API definition in [Gravitino Open API](./api/rest/gravitino-rest-api), Java SDK definition in [Gravitino Java doc](pathname:///docs/0.7.0-incubating-SNAPSHOT/api/java/index.html). -Gravitino provides a web UI to manage the metadata. Visit the web UI in the browser via `http://:8090`. See [Gravitino web UI](./webui.md) for details. +Gravitino also provides a web UI to manage the metadata. Visit the web UI in the browser via `http://:8090`. +See [Gravitino web UI](./webui.md) for details. + +Gravitino also provides a Command Line Interface (CLI) to manage the metadata. See [Gravitino CLI](./cli.md) for details. Gravitino currently supports the following catalogs: From 0accd4d63b50120ebef83fc85b24ab0cce563d7f Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Thu, 24 Oct 2024 15:35:22 +1100 Subject: [PATCH 49/49] no message --- clients/cli/bin/errors.sh | 49 ----------------- clients/cli/bin/examples.sh | 106 ------------------------------------ 2 files changed, 155 deletions(-) delete mode 100755 clients/cli/bin/errors.sh delete mode 100755 clients/cli/bin/examples.sh diff --git a/clients/cli/bin/errors.sh b/clients/cli/bin/errors.sh deleted file mode 100755 index 03690e89738..00000000000 --- a/clients/cli/bin/errors.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -# -# 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. -# - -# Some of these examples assume you have the Apache Gravitino playground running. - -shopt -s expand_aliases -alias gcli='java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' - -# No such command -gcli unknown - -# unknown command and entiry -gcli unknown unknown - -# unknown command -gcli metalake unknown - -# unknown entity -gcli unknown list - -# Name not specified -gcli metalake details - -# Unknown metalake name -gcli metalake details --metalake unknown - -# Unknown catalog name -gcli catalog details --metalake metalake_demo --name unknown - -# Missing catalog name -gcli catalog details --metalake metalake_demo diff --git a/clients/cli/bin/examples.sh b/clients/cli/bin/examples.sh deleted file mode 100755 index 45b331c5a84..00000000000 --- a/clients/cli/bin/examples.sh +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash - -# -# 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. -# - -# These examples assume you have the Apache Gravitino playground running. - -unset GRAVITINO_METALAKE -shopt -s expand_aliases -alias gcli='java -jar ../../cli/build/libs/gravitino-cli-*-incubating-SNAPSHOT.jar' - -# display help -gcli --help - -# display version -gcli --version - -# list all metalakes -gcli metalake list - -# metalake details -gcli metlake details --metalake metalake_demo - -# list all catalogs -gcli catalog list --metalake metalake_demo - -# list catalog details -gcli catalog details --metalake metalake_demo --name catalog_iceberg -gcli catalog details --metalake metalake_demo --name catalog_mysql -gcli catalog details --metalake metalake_demo --name catalog_postgres -gcli catalog details --metalake metalake_demo --name catalog_hive - -# list catalog schemas -gcli schema list --metalake metalake_demo --name catalog_iceberg -gcli schema list --metalake metalake_demo --name catalog_mysql -gcli schema list --metalake metalake_demo --name catalog_postgres -gcli schema list --metalake metalake_demo --name catalog_hive - -# list schema details -gcli schema details --metalake metalake_demo --name catalog_postgres.hr -gcli schema details --metalake metalake_demo --name catalog_mysql.db -gcli schema details --metalake metalake_demo --name catalog_hive.sales - -# list schema tables -gcli table list --metalake metalake_demo --name catalog_postgres.hr -gcli table list --metalake metalake_demo --name catalog_mysql.db -gcli table list --metalake metalake_demo --name catalog_hive.sales - -# list table details -gcli column list --metalake metalake_demo --name catalog_postgres.hr.departments -gcli column list --metalake metalake_demo --name catalog_mysql.db.iceberg_tables -gcli column list --metalake metalake_demo --name 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 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 catalog schema -gcli schema list --name catalog_iceberg -gcli schema list --name catalog_mysql -gcli schema list --name catalog_postgres -gcli schema list --name catalog_hive - -# 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 schema tables -gcli table list --name catalog_postgres.hr -gcli table list --name catalog_mysql.db -gcli table list --name catalog_hive.sales - -# list table details -gcli column list --name catalog_postgres.hr.departments -gcli column list --name catalog_mysql.db.iceberg_tables -gcli column list --name catalog_hive.sales.products - -unset GRAVITINO_METALAKE