Skip to content

Commit 44f5ab3

Browse files
authored
[#6027] improvement(CLI): fix Gravitino CLI get wrong catalogName (#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: #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. ```
1 parent 0c516e2 commit 44f5ab3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

clients/cli/src/main/java/org/apache/gravitino/cli/ErrorMessages.java

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ErrorMessages {
3030
public static final String UNKNOWN_TABLE = "Unknown table name.";
3131
public static final String MALFORMED_NAME = "Malformed entity name.";
3232
public static final String MISSING_NAME = "Missing --name option.";
33+
public static final String MISSING_METALAKE = "Missing --metalake option.";
3334
public static final String MISSING_GROUP = "Missing --group option.";
3435
public static final String MISSING_USER = "Missing --user option.";
3536
public static final String MISSING_ROLE = "Missing --role option.";

clients/cli/src/main/java/org/apache/gravitino/cli/FullName.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ public String getMetalakeName() {
7373
}
7474
}
7575

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

8178
return null;
8279
}

clients/cli/src/test/java/org/apache/gravitino/cli/TestFulllName.java

+24
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,28 @@ public void testMalformedName() throws ParseException {
212212
String output = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
213213
assertEquals(output, ErrorMessages.MALFORMED_NAME);
214214
}
215+
216+
@Test
217+
@SuppressWarnings("DefaultCharset")
218+
public void testGetMetalake() throws ParseException {
219+
String[] args = {
220+
"table", "list", "-i", "-m", "demo_metalake", "--name", "Hive_catalog.default"
221+
};
222+
CommandLine commandLine = new DefaultParser().parse(options, args);
223+
FullName fullName = new FullName(commandLine);
224+
String metalakeName = fullName.getMetalakeName();
225+
assertEquals(metalakeName, "demo_metalake");
226+
}
227+
228+
@Test
229+
@SuppressWarnings("DefaultCharset")
230+
public void testGetMetalakeWithoutMetalakeOption() throws ParseException {
231+
String[] args = {"table", "list", "-i", "--name", "Hive_catalog.default"};
232+
CommandLine commandLine = new DefaultParser().parse(options, args);
233+
FullName fullName = new FullName(commandLine);
234+
String metalakeName = fullName.getMetalakeName();
235+
assertNull(metalakeName);
236+
String errOutput = new String(errContent.toByteArray(), StandardCharsets.UTF_8).trim();
237+
assertEquals(errOutput, ErrorMessages.MISSING_METALAKE);
238+
}
215239
}

0 commit comments

Comments
 (0)