Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to CLI_IV

# Conflicts:
#	clients/cli/docs/README.md
#	clients/cli/examples.sh
#	clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
#	clients/cli/src/main/java/org/apache/gravitino/cli/Main.java
#	clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java
  • Loading branch information
justinmclean committed Oct 17, 2024
2 parents d27c59a + 29c9222 commit a405bfd
Show file tree
Hide file tree
Showing 22 changed files with 1,192 additions and 170 deletions.
71 changes: 64 additions & 7 deletions clients/cli/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,43 @@ 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] [options]
Options
usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update|set|remove|properties] [options]
-b,--bootstrap <arg> Kafka bootstrap servers
-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,--provider <arg> provider one of hadoop, hive, mysql, postgres, iceberg, kafka
-r,--rename <arg> new entity name
-p,--password <arg> database password
-R,--delete delete an entity
-u,--url <arg> Gravitino URL (default: http://localhost:8090)
-r,--rename <arg> new entity name
-s,--schema <arg> schema name
-t,--table <arg> table name
-u,--user <arg> database username
-U,--update update an entity
-v,--value <arg> property value
-w,--warehouse <arg> warehouse name
-z,--password <arg> database password
-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
```
The form `gcli <entity> <action> [options]` is used in this document.

## Commands
The following commands are available for entity management:
Expand All @@ -106,6 +120,9 @@ details: Show detailed information about an entity
create: Create a new entity
delete: Delete an existing entity
update: Update an existing entity
set: Used to set properties and tags
remove: Used to remove properties and tags
properties: Used to list properties

### Examples
List All Metalakes
Expand All @@ -123,9 +140,49 @@ 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
161 changes: 0 additions & 161 deletions clients/cli/examples.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class CommandEntities {
public static final String TABLE = "table";
public static final String USER = "user";
public static final String GROUP = "group";
public static final String TAG = "tag";

private static final HashSet<String> VALID_ENTITIES = new HashSet<>();

Expand All @@ -42,6 +43,7 @@ public class CommandEntities {
VALID_ENTITIES.add(TABLE);
VALID_ENTITIES.add(USER);
VALID_ENTITIES.add(GROUP);
VALID_ENTITIES.add(TAG);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public class ErrorMessages {
public static final String USER_EXISTS = "User already exists.";
public static final String UNKNOWN_GROUP = "Unknown group.";
public static final String GROUP_EXISTS = "Group already exists.";
public static final String UNKNOWN_TAG = "Unknown tag.";
public static final String TAG_EXISTS = "Tag already exists.";
}
62 changes: 60 additions & 2 deletions clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ public String getNamePart(int position) {
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 - 1 < position) {
if (position >= names.length) {
System.err.println(ErrorMessages.MALFORMED_NAME);
return null;
}
Expand All @@ -128,4 +127,63 @@ public String getNamePart(int position) {
System.err.println(ErrorMessages.MISSING_NAME);
return null;
}

/**
* Helper method to determine a specific part of the full name exits.
*
* @param partNo The part of the name to obtain.
* @return True if the part exitsts.
*/
public boolean hasNamePart(int partNo) {
/* Extract the name part from the full name if available. */
if (line.hasOption(GravitinoOptions.NAME)) {
String[] names = line.getOptionValue(GravitinoOptions.NAME).split("\\.");
int length = names.length;
int position = partNo;

/* Adjust position if metalake is part of the full name. */
if (metalakeEnv != null) {
position = position - 1;
}
return position <= length;
}

return false;
}

/**
* Does the metalake name exist?
*
* @return True if the catalog name exists, or false if it does not.
*/
public boolean hasMetalakeName() {
return hasNamePart(1);
}

/**
* Does the catalog name exist?
*
* @return True if the catalog name exists, or false if it does not.
*/
public boolean hasCatalogName() {
return hasNamePart(2);
}

/**
* Does the schema name exist?
*
* @return True if the schema name exists, or false if it does not.
*/
public boolean hasSchemaName() {
return hasNamePart(3);
}

/**
* Does the table name exist?
*
* @return True if the table name exists, or false if it does not.
*/
public boolean hasTableName() {
return hasNamePart(4);
}
}
Loading

0 comments on commit a405bfd

Please sign in to comment.