Skip to content

Commit

Permalink
[apache#6027] improvement(CLI): fix Gravitino CLI get wrong catalogNa…
Browse files Browse the repository at this point in the history
…me (apache#6048)

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

Fix Gravitino CLI get wrong catalogName when set metalake name by --name
option. A hint is given if the -metalake option is not set.

### Why are the changes needed?

Fix: apache#6027 

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

No

### How was this patch tested?

local test
```bash
gcli table list --name Hive_catalog.default
Missing --metalake option.
```
  • Loading branch information
Abyss-lord authored Dec 31, 2024
1 parent 0c516e2 commit 44f5ab3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ErrorMessages {
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 option.";
public static final String MISSING_METALAKE = "Missing --metalake option.";
public static final String MISSING_GROUP = "Missing --group option.";
public static final String MISSING_USER = "Missing --user option.";
public static final String MISSING_ROLE = "Missing --role option.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public String getMetalakeName() {
}
}

// Extract the metalake name from the full name option
if (line.hasOption(GravitinoOptions.NAME)) {
return line.getOptionValue(GravitinoOptions.NAME).split("\\.")[0];
}
System.err.println(ErrorMessages.MISSING_METALAKE);

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,28 @@ public void testMalformedName() throws ParseException {
String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
assertEquals(output, ErrorMessages.MALFORMED_NAME);
}

@Test
@SuppressWarnings("DefaultCharset")
public void testGetMetalake() throws ParseException {
String[] args = {
"table", "list", "-i", "-m", "demo_metalake", "--name", "Hive_catalog.default"
};
CommandLine commandLine = new DefaultParser().parse(options, args);
FullName fullName = new FullName(commandLine);
String metalakeName = fullName.getMetalakeName();
assertEquals(metalakeName, "demo_metalake");
}

@Test
@SuppressWarnings("DefaultCharset")
public void testGetMetalakeWithoutMetalakeOption() throws ParseException {
String[] args = {"table", "list", "-i", "--name", "Hive_catalog.default"};
CommandLine commandLine = new DefaultParser().parse(options, args);
FullName fullName = new FullName(commandLine);
String metalakeName = fullName.getMetalakeName();
assertNull(metalakeName);
String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
assertEquals(errOutput, ErrorMessages.MISSING_METALAKE);
}
}

0 comments on commit 44f5ab3

Please sign in to comment.