justinmclean commented on code in PR #5688:
URL: https://github.com/apache/gravitino/pull/5688#discussion_r1861747836
##########
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java:
##########
@@ -140,41 +145,78 @@ private void handleMetalakeCommand() {
String url = getUrl();
FullName name = new FullName(line);
String metalake = name.getMetalakeName();
-
- if (CommandActions.DETAILS.equals(command)) {
- if (line.hasOption(GravitinoOptions.AUDIT)) {
- newMetalakeAudit(url, ignore, metalake).handle();
- } else {
- newMetalakeDetails(url, ignore, metalake).handle();
- }
- } else if (CommandActions.LIST.equals(command)) {
- newListMetalakes(url, ignore).handle();
- } else if (CommandActions.CREATE.equals(command)) {
- String comment = line.getOptionValue(GravitinoOptions.COMMENT);
- newCreateMetalake(url, ignore, metalake, comment).handle();
- } else if (CommandActions.DELETE.equals(command)) {
- boolean force = line.hasOption(GravitinoOptions.FORCE);
- newDeleteMetalake(url, ignore, force, metalake).handle();
- } else if (CommandActions.SET.equals(command)) {
- String property = line.getOptionValue(GravitinoOptions.PROPERTY);
- String value = line.getOptionValue(GravitinoOptions.VALUE);
- newSetMetalakeProperty(url, ignore, metalake, property, value).handle();
- } else if (CommandActions.REMOVE.equals(command)) {
- String property = line.getOptionValue(GravitinoOptions.PROPERTY);
- newRemoveMetalakeProperty(url, ignore, metalake, property).handle();
- } else if (CommandActions.PROPERTIES.equals(command)) {
- newListMetalakeProperties(url, ignore, metalake).handle();
- } else if (CommandActions.UPDATE.equals(command)) {
- if (line.hasOption(GravitinoOptions.COMMENT)) {
- String comment = line.getOptionValue(GravitinoOptions.COMMENT);
- newUpdateMetalakeComment(url, ignore, metalake, comment).handle();
- }
- if (line.hasOption(GravitinoOptions.RENAME)) {
- String newName = line.getOptionValue(GravitinoOptions.RENAME);
- boolean force = line.hasOption(GravitinoOptions.FORCE);
- newUpdateMetalakeName(url, ignore, force, metalake, newName).handle();
+ Map<Set<String>, Runnable> commandMap = new HashMap<>();
+
+ commandMap.put(
+ Sets.newHashSet(CommandActions.DETAILS),
+ () -> {
+ newMetalakeDetails(url, ignore, metalake).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.DETAILS, GravitinoOptions.AUDIT),
+ () -> {
+ newMetalakeAudit(url, ignore, metalake).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.LIST), () -> newListMetalakes(url,
ignore).handle());
+ commandMap.put(
+ Sets.newHashSet(CommandActions.CREATE),
+ () -> {
+ String comment = line.getOptionValue(GravitinoOptions.COMMENT);
+ newCreateMetalake(url, ignore, metalake, comment).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.DELETE),
+ () -> {
+ boolean force = line.hasOption(GravitinoOptions.FORCE);
+ newDeleteMetalake(url, ignore, force, metalake).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.SET, GravitinoOptions.PROPERTY,
GravitinoOptions.VALUE),
+ () -> {
+ String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+ String value = line.getOptionValue(GravitinoOptions.VALUE);
+ newSetMetalakeProperty(url, ignore, metalake, property,
value).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.REMOVE, GravitinoOptions.PROPERTY),
+ () -> {
+ String property = line.getOptionValue(GravitinoOptions.PROPERTY);
+ newRemoveMetalakeProperty(url, ignore, metalake, property).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.PROPERTIES),
+ () -> newListMetalakeProperties(url, ignore, metalake).handle());
+ commandMap.put(
+ Sets.newHashSet(CommandActions.UPDATE, GravitinoOptions.COMMENT),
+ () -> {
+ String comment = line.getOptionValue(GravitinoOptions.COMMENT);
+ newUpdateMetalakeComment(url, ignore, metalake, comment).handle();
+ });
+ commandMap.put(
+ Sets.newHashSet(CommandActions.UPDATE, GravitinoOptions.RENAME),
+ () -> {
+ String newName = line.getOptionValue(GravitinoOptions.RENAME);
+ boolean force = line.hasOption(GravitinoOptions.FORCE);
+ newUpdateMetalakeName(url, ignore, force, metalake,
newName).handle();
+ });
Review Comment:
I looked at a couple of options, and all required building some sort of map.
However, the map is quite small when based on a single entity, and I would
doubt this has any real-world noticeable performance impact. Hand-coded logic
(if/else statements) will always be lighter. We could possibly just build
smaller maps for only sub-commands that have multiple commands, but that would
lose some of the benefits of this option, so I'm not sure that is a viable
option.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]