This is an automated email from the ASF dual-hosted git repository. jmclean pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push: new d1709ae1b [#5280] improvement(cli): Display distribution / bucketing information for Tables in the Gravitino CLI (#5525) d1709ae1b is described below commit d1709ae1b13071f3ec7cf8c87e35616de8599bf4 Author: TungYuChiang <75083792+tungyuchi...@users.noreply.github.com> AuthorDate: Thu Nov 14 11:51:40 2024 +0800 [#5280] improvement(cli): Display distribution / bucketing information for Tables in the Gravitino CLI (#5525) ### What changes were proposed in this pull request? Add --distribution option to display distribution information on Tables. ### Why are the changes needed? This change allows users to retrieve additional distribution information on Tables Closes: #5280 ### Does this PR introduce _any_ user-facing change? Yes, it adds the --distribution option to CLI ### How was this patch tested? Compiled and tested locally. --------- Co-authored-by: Justin Mclean <jus...@classsoftware.com> --- .../apache/gravitino/cli/GravitinoCommandLine.java | 3 + .../org/apache/gravitino/cli/GravitinoOptions.java | 2 + .../gravitino/cli/commands/TableDistribution.java | 68 ++++++++++++++++++++++ docs/cli.md | 4 ++ 4 files changed, 77 insertions(+) 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 520a6cfc3..bb4649a09 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 @@ -76,6 +76,7 @@ import org.apache.gravitino.cli.commands.SetSchemaProperty; import org.apache.gravitino.cli.commands.SetTagProperty; import org.apache.gravitino.cli.commands.TableAudit; import org.apache.gravitino.cli.commands.TableDetails; +import org.apache.gravitino.cli.commands.TableDistribution; import org.apache.gravitino.cli.commands.TagDetails; import org.apache.gravitino.cli.commands.TagEntity; import org.apache.gravitino.cli.commands.UntagEntity; @@ -349,6 +350,8 @@ public class GravitinoCommandLine { if (CommandActions.DETAILS.equals(command)) { if (line.hasOption(GravitinoOptions.AUDIT)) { new TableAudit(url, ignore, metalake, catalog, schema, table).handle(); + } else if (line.hasOption(GravitinoOptions.DISTRIBUTION)) { + new TableDistribution(url, ignore, metalake, catalog, schema, table).handle(); } else { new TableDetails(url, ignore, metalake, catalog, schema, table).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 63668fd3a..5fd34c558 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 @@ -43,6 +43,7 @@ public class GravitinoOptions { public static final String ROLE = "role"; public static final String AUDIT = "audit"; public static final String FORCE = "force"; + public static final String DISTRIBUTION = "distribution"; /** * Builds and returns the CLI options for Gravitino. @@ -61,6 +62,7 @@ public class GravitinoOptions { options.addOption(createArgOption("m", METALAKE, "metalake name")); options.addOption(createSimpleOption("i", IGNORE, "ignore client/sever version check")); options.addOption(createSimpleOption("a", AUDIT, "display audit information")); + options.addOption(createSimpleOption("d", DISTRIBUTION, "Display distribution information")); // Create/update options options.addOption(createArgOption(null, RENAME, "new entity name")); diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java new file mode 100644 index 000000000..7fac9b861 --- /dev/null +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableDistribution.java @@ -0,0 +1,68 @@ +/* + * 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.expressions.distributions.Distribution; + +/** Displays the details of a table's distirbution. */ +public class TableDistribution extends TableCommand { + + protected final String schema; + protected final String table; + + /** + * Displays the details of a table's distirbution. + * + * @param url The URL of the Gravitino server. + * @param ignoreVersions If true don't check the client/server versions match. + * @param metalake The name of the metalake. + * @param catalog The name of the catalog. + * @param schema The name of the schenma. + * @param table The name of the table. + */ + public TableDistribution( + String url, + boolean ignoreVersions, + String metalake, + String catalog, + String schema, + String table) { + super(url, ignoreVersions, metalake, catalog); + this.schema = schema; + this.table = table; + } + + /** Displays the strategy and bucket number of distirbution. */ + @Override + public void handle() { + Distribution distribution; + + try { + NameIdentifier name = NameIdentifier.of(schema, table); + distribution = tableCatalog().loadTable(name).distribution(); + } catch (Exception exp) { + System.err.println(exp.getMessage()); + return; + } + + System.out.println(distribution.strategy() + "," + distribution.number()); + } +} diff --git a/docs/cli.md b/docs/cli.md index 6f7ecb592..54176a66a 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -373,7 +373,11 @@ gcli column list --name catalog_postgres.hr.departments ```bash gcli table details --name catalog_postgres.hr.departments --audit ``` +#### Show tables distribution information +```bash +gcli table details --metalake metalake_demo --name catalog_postgres.hr.departments --distribution +``` #### Delete a table ```bash