Skip to content

Commit

Permalink
[apache#5808] fix(CLI): Fix improper exception throwing When a malfor…
Browse files Browse the repository at this point in the history
…med name is passed to the CLI command (apache#5836)

### What changes were proposed in this pull request?

No exception should be thrown when a malformed name is passed to the
CLI. Currently, passing a malformed name causes an
IllegalNamespaceException. I’ve added error messages to inform the user
when necessary arguments are missing.

Additionally, the `FullName.getNamePart()` method no longer prints error
messages, as the information it provides is limited. I think performing
fine-grained argument validation in each method and providing specific
hints is a better way to hint users.

### Why are the changes needed?

Fix: apache#5808 

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

```bash
bin/gcli.sh table  list -i
# output: Missing required argument(s): METALAKE, CATALOG, SCHEMA

bin/gcli.sh table  list -i --metalake demo_metalake
# output: Missing required argument(s): CATALOG, SCHEMA

bin/gcli.sh table  list -i --metalake demo_metalake --name Hive_catalog
# output: Missing required argument(s): SCHEMA

bin/gcli.sh table  list -i --metalake demo_metalake --name Hive_catalog.default
# output: correct result
```
  • Loading branch information
Abyss-lord authored Dec 17, 2024
1 parent eb8fa67 commit 286286d
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
Expand Down Expand Up @@ -321,6 +324,19 @@ private void handleTableCommand() {
Command.setAuthenticationMode(auth, userName);

if (CommandActions.LIST.equals(command)) {
List<String> missingEntities =
Stream.of(
metalake == null ? CommandEntities.METALAKE : null,
catalog == null ? CommandEntities.CATALOG : null,
schema == null ? CommandEntities.SCHEMA : null)
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (!missingEntities.isEmpty()) {
System.err.println(
"Missing required argument(s): " + Joiner.on(", ").join(missingEntities));
return;
}

newListTables(url, ignore, metalake, catalog, schema).handle();
return;
}
Expand Down

0 comments on commit 286286d

Please sign in to comment.