Skip to content

Commit

Permalink
Merge branch 'CLI_II' into CLI_III
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmclean committed Oct 17, 2024
2 parents 0ef4695 + 05bc9ed commit d27c59a
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 282 deletions.
12 changes: 0 additions & 12 deletions clients/cli/errors.sh → clients/cli/bin/errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ gcli unknown list
# Name not specified
gcli metalake details

# Too many arguments
gcli metalake details more

# Unknown metalake name
gcli metalake details --name unknown

Expand All @@ -52,12 +49,3 @@ gcli catalog details --name metalake_demo.unknown

# Unknown catalog name
gcli catalog details --name metalake_demo

# Already exists
gcli metalake create -name metalake_demo

# Doesn't exist
gcli metalake delete -name unknown-metalake

# Malformed name
gcli catalog details -name metalake_demo
103 changes: 103 additions & 0 deletions clients/cli/bin/examples.sh
Original file line number Diff line number Diff line change
@@ -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
73 changes: 10 additions & 63 deletions clients/cli/README.md → clients/cli/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,29 @@ 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 [metalake|catalog|schema|table] [list|details|create|delete|update|set|remove|properties] [options]
usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update] [options]
Options
-b,--bootstrap <arg> Kafka bootstrap servers
-c,--catalog <arg> catalog name
-C,--create create an entity
-c,--comment <arg> entity comment
-D,--details list details about an entity
-d,--database <arg> database name
-e,--entity <arg> entity type
-h,--help command help information
-j,--jdbcurl <arg> JDBC URL
-L,--list list entity children
-l,--user <arg> database username
-m,--metastore <arg> Hive metastore URI
-n,--name <arg> full entity name (dot separated)
-P,--properties show an entities properties
-p,--password <arg> database password
-R,--delete delete an entity
-p,--provider <arg> provider one of hadoop, hive, mysql, postgres, iceberg, kafka
-r,--rename <arg> new entity name
-s,--schema <arg> schema name
-t,--table <arg> table name
-u,--user <arg> database username
-R,--delete delete an entity
-u,--url <arg> Gravitino URL (default: http://localhost:8090)
-U,--update update an entity
-v,--value <arg> property value
-w,--warehouse <arg> warehouse name
-x,--command <arg> one of: list, details, create, delete, or update
```

The command line can be used in several ways to achieve the same results, depending on your preference.
```bash
gcli catalog details --name metalake_demo.catalog_postgres
gcli catalog --command details -name metalake_demo.catalog_postgres
gcli --entity catalog --command details -name metalake_demo.catalog_postgres
gcli catalog details --metalake metalake_demo --catalog catalog_postgres
gcli details --metalake metalake_demo --catalog catalog_postgres
gcli --metalake metalake_demo --catalog catalog_postgres
gcli --command details --metalake metalake_demo --catalog catalog_postgres
-z,--password <arg> database password
```
The form `gcli <entity> <action> [options]` is used in this document.

## Commands
The following commands are available for entity management:
Expand All @@ -130,55 +117,15 @@ 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.my_catalog
gcli metalake list -name my-metalake.my-catalog
```

Create a Metalake

```bash
gcli metalake create -name my_metalake -comment "This is my metalake"
```

Create a Catalog

```bash
gcli catalog create -name metalake_demo.iceberg --provider iceberg --metastore thrift://hive-host:9083 --warehouse hdfs://hdfs-host:9000/user/iceberg/warehouse
```

Delete a Catalog

```bash
gcli catalog delete -name my_metalake.my_catalog
```

Rename a Metalake

```bash
gcli metalake update -name metalake_demo -rename demo
```

Update a Metalake's comment
```bash
gcli metalake update -name metalake_demo -comment "new comment"
```
### Setting 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 either as the first part of the entities name or via the `--metalake` parameter.
2. Set via the 'GRAVITINO_METALAKE' environment variable.
3. Placed in the Gravitino configuration file `~/.gravitino` by adding a line like `metalake=metalake_demo`.
The command line option overrides the other options and the environment variable overrides the value in the configuration file.
## Running Tests

This project includes a suite of unit tests to verify its functionality.
Expand Down
2 changes: 1 addition & 1 deletion clients/cli/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ gcli user delete --name metalake_demo --user new_user
gcli group create --name metalake_demo --user new_group
gcli group details --name metalake_demo --user new_group
gcli group list --name metalake_demo
gcli group delete --name metalake_demo --user new_group
gcli group delete --name metalake_demo --user new_group
29 changes: 11 additions & 18 deletions clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,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;
// Check if the metalake name is specified in the configuration file
} else if (config.fileExists()) {
Expand All @@ -76,46 +73,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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -68,18 +62,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("n", 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"));
Expand All @@ -89,7 +74,7 @@ public Options options() {

// Create/update options
options.addOption(createArgOption("r", RENAME, "new entity name"));
options.addOption(createArgOption("d", COMMENT, "entity comment"));
options.addOption(createArgOption("c", COMMENT, "entity comment"));
options.addOption(createArgOption("p", PROPERTY, "property name"));
options.addOption(createArgOption("v", VALUE, "property value"));
options.addOption(
Expand All @@ -99,8 +84,8 @@ public Options options() {
options.addOption(createArgOption("w", WAREHOUSE, "warehouse name"));
options.addOption(createArgOption("b", BOOTSTRAP, "Kafka bootstrap servers"));
options.addOption(createArgOption("j", JDBCURL, "JDBC URL"));
options.addOption(createArgOption("u", USER, "database username"));
options.addOption(createArgOption("p", PASSWORD, "database password"));
options.addOption(createArgOption("l", USER, "database username"));
options.addOption(createArgOption("z", PASSWORD, "database password"));
options.addOption(createArgOption("d", DATABASE, "database name"));
options.addOption(createArgOption("g", GROUP, "group name"));

Expand Down
Loading

0 comments on commit d27c59a

Please sign in to comment.