Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5960] fix(CLI): Add register and link commands to CLI for model #6066

Merged
merged 4 commits into from
Jan 3, 2025

Conversation

Abyss-lord
Copy link
Contributor

@Abyss-lord Abyss-lord commented Jan 2, 2025

What changes were proposed in this pull request?

Add register and link commands to CLI for model

  • register a model:model create
  • link a model:model update <—uri uri> [--alias aliaA aliaB]

meantime, add two options

  • —uri :The URI of the model version artifact.
  • —alias :The aliases of the model version.

The documentation will be updated after #6047 merge and I will create a new issue.

Why are the changes needed?

Fix: #5960

Does this PR introduce any user-facing change?

NO

How was this patch tested?

register test

# register a model
gcli model create -m demo_metalake --name Hive_catalog.default.model
# register a model with comment
gcli model create -m demo_metalake --name Hive_catalog.default.model --comment comment
# register a model with properties
gcli model create -m demo_metalake --name Hive_catalog.default.model --properties key1=val1 key2=val2
# register a model with properties and comment
gcli model create -m demo_metalake --name Hive_catalog.default.model --properties key1=val1 klinkey2=val2 --comment comment

link test

# link a model 
gcli model update -m demo_metalake --name Hive_catalog.default.model --uri file:///tmp/file
# link a model with alias
gcli model update -m demo_metalake --name Hive_catalog.default.model --uri file:///tmp/file  --alias aliasA aliasB
# link a model with all component
gcli model update -m demo_metalake --name Hive_catalog.default.model --uri file:///tmp/file  --alias aliasA aliasB --comment comment --properties key1=val1 key2=val2
# link a model without uri
gcli model update -m demo_metalake --name Hive_catalog.default.model

@Abyss-lord
Copy link
Contributor Author

H @justinmclean @tengqm , could you please review this PR when you have time? I’d really appreciate your feedback.

System.out.println("Successful register " + registeredModel.name() + ".");
} else {
System.err.println("Failed to register model: " + model + ".");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two confusions here:

  • Do we have a protocol regarding where to output error/info messages?
  • Are we always printing something on the command line when some actions were successful?

I am thinking of a scenario where the command line tool is invoked from an upper
layer script. Getting this verbose message are not so "helpful" as we expect.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes errors do to standard output and the program should exit with -1. Scripts can check the exit code to see if something worked. Output like this is helpful to users, as if a command has no output, they don't know if it worked or not.
From https://clig.dev:

  • Return zero exit code on success, non-zero on failure.
  • Send output to stdout.
  • Send messaging to stderr.
  • Display output on success, but keep it brief.

In this case, I probably wouldn't mention the model name on success, but it is probably OK to do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "display output on success ..." is a common practice.

(venv) tmp $ rm q19.zip
(venv) tmp $ rm q19.zip
rm: q19.zip: No such file or directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commands like rm and others that were written 30 or so years ago, they had little output. Thinking about that has changed over those decades. I would suggest we follow the advice in that document. Here it is in full:
"Display output on success, but keep it brief. Traditionally, when nothing is wrong, UNIX commands display no output to the user. This makes sense when they’re being used in scripts, but can make commands appear to be hanging or broken when used by humans. For example, cp will not print anything, even if it takes a long time.
It’s rare that printing nothing at all is the best default behavior, but it’s usually best to err on the side of less."

You note that more modern commands (like git or the GitHub CLI) do output on success and follow this design.

It also suggests that if you want no output, you should add a --quiet flag to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinmclean , Should we add the --quit option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--quiet not --quit :-) There is no need to add it here, as it would impact many commands. We can add it in another issue/PR if we think it is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the --quiet idea.
I am not a big fan of verbose outputs from commands. For example, when I'm doing gcli get something, I'm expecting an output which is the data I'm retrieving. I may go further down this road anticipating a --format option, with which I can dump the output as a JSON. Yes, we can do an --output to dump/redirect this data. But this is not script friendly.

For commands other than get or list, I'm not expecting data from the server.
I'm not expecting an output from the client side tool either (I admit that this is a personal taste and I don't want to argue over this).
The bizarre point is that ... the CLI now has two kinds of outputs.
Sometimes, it produces meaningful (business) data and prints them out
(think the get, list case), other times ... it is producing something verbose,
just for the purpose of producing something.

By the way, the cp command is a synchronous action. It will not return control to
you until it succeeds or fail with an error message. It is not a good example, though I get your points.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have an option for different formats (currently plain and table). However, we would unlikely add a JSON format as the REST interface already provides information in that format. But if there was demand for it or someone wanted to develop that feature, they could. Originally, the CLI prototype was a wrapper on the REST and provided plain text and JSON output, but it was decided to wrap the Java API instead.

Copy link
Member

@justinmclean justinmclean Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note it is also recommended that commands that take time to run produce output so the user knows they are doing something. Again, more modern commands like git will do this. We currently don't have any commands that take a long time to run.

System.out.println("Successful register " + registeredModel.name() + ".");
} else {
System.err.println("Failed to register model: " + model + ".");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "display output on success ..." is a common practice.

(venv) tmp $ rm q19.zip
(venv) tmp $ rm q19.zip
rm: q19.zip: No such file or directory

@Abyss-lord
Copy link
Contributor Author

@justinmclean , I’ve finished updating the code. Please take a look at the PR again when you have time.

Copy link
Member

@justinmclean justinmclean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks again for your contribution.

@justinmclean justinmclean merged commit bfb8568 into apache:main Jan 3, 2025
25 checks passed
@Abyss-lord Abyss-lord deleted the model-command branch January 4, 2025 04:16
Abyss-lord added a commit to Abyss-lord/gravitino that referenced this pull request Jan 4, 2025
…el (apache#6066)

Add register and link commands to CLI for model
- register a model:`model create`
- link a model:`model update <—uri uri> [--alias aliaA aliaB]`

meantime, add two options
- `—uri` :The URI of the model version artifact.
- `—alias` :The aliases of the model version.

The documentation will be updated after apache#6047 merge and I will create a
new issue.

Fix: apache#5960

NO

```bash
gcli model create -m demo_metalake --name Hive_catalog.default.model
gcli model create -m demo_metalake --name Hive_catalog.default.model --comment comment
gcli model create -m demo_metalake --name Hive_catalog.default.model --properties key1=val1 key2=val2
gcli model create -m demo_metalake --name Hive_catalog.default.model --properties key1=val1 klinkey2=val2 --comment comment
```

```bash
gcli model update -m demo_metalake --name Hive_catalog.default.model --uri file:///tmp/file
gcli model update -m demo_metalake --name Hive_catalog.default.model --uri file:///tmp/file  --alias aliasA aliasB
gcli model update -m demo_metalake --name Hive_catalog.default.model --uri file:///tmp/file  --alias aliasA aliasB --comment comment --properties key1=val1 key2=val2
gcli model update -m demo_metalake --name Hive_catalog.default.model
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] Add register/link CLI command for Model
3 participants