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

Add statement helper command to cli #1285

Merged

Conversation

matthewmturner
Copy link
Contributor

Which issue does this PR close?

Closes #1227

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label Nov 11, 2021
@matthewmturner
Copy link
Contributor Author

@jimexist this is rough around the edges right now, but i added two commands:
\h and \h function would you just be able to confirm that the approach ive taken so far is generally ok?
then i can work on cleaning it up and adding more function descriptions.

@@ -34,6 +35,8 @@ pub enum Command {
Help,
ListTables,
DescribeTable(String),
FunctionList,
Copy link
Member

Choose a reason for hiding this comment

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

how about using ListFunctions to keep it consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, was going to update that

@matthewmturner
Copy link
Contributor Author

@jimexist is it ok to use the same definitions as psql (only including relevant parts of course)?

@jimexist
Copy link
Member

@jimexist is it ok to use the same definitions as psql (only including relevant parts of course)?

yes please - I think to reduce user memory overhead is the goal here, unless there's a good reason to break that consistency

@matthewmturner matthewmturner marked this pull request as ready for review November 15, 2021 18:41
Copy link
Contributor

@capkurmagati capkurmagati left a comment

Choose a reason for hiding this comment

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

Thanks @matthewmturner. Left two comments. Others look good to me.

@@ -64,6 +67,11 @@ impl Command {
Self::Quit => Err(DataFusionError::Execution(
"Unexpected quit, this should be handled outside".into(),
)),
Self::ListFunctions => display_all_functions(),
Self::SearchFunctions(function) => {
let func = function.parse::<Function>().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems better to return an err message when the parse fails instead of crashing the program.

type Err = ();

fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(match s.to_uppercase().as_str() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The cli crashes when function name surrounded whitespace so how about:

Suggested change
Ok(match s.to_uppercase().as_str() {
Ok(match s.trim().to_uppercase().as_str() {

@matthewmturner
Copy link
Contributor Author

Thanks @matthewmturner. Left two comments. Others look good to me.

@capkurmagati thanks for feedback - agree on those points. ive updated.

@matthewmturner
Copy link
Contributor Author

@jimexist ready when you get the chance

if let Ok(func) = function.parse::<Function>() {
func.function_details()?
} else {
eprintln!("{} is not a supported function", function)
Copy link
Member

Choose a reason for hiding this comment

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

how about you just return error for this case?

pub fn function_details(&self) -> Result<()> {
match self {
Function::Select => {
let details = "
Copy link
Member

Choose a reason for hiding this comment

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

you can use r#" "# to mark multiline raw string

Syntax:
EXPLAIN [ ANALYZE ] statement
";
println!("{}", details)
Copy link
Member

Choose a reason for hiding this comment

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

how about returning the detail and print outside the match?

@matthewmturner
Copy link
Contributor Author

@jimexist thx for review. i believe ive addressed the comments.

Copy link
Member

@jimexist jimexist 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!

Co-authored-by: Jiayu Liu <Jimexist@users.noreply.github.com>
@alamb alamb merged commit 42f8ab1 into apache:master Nov 18, 2021
@alamb
Copy link
Contributor

alamb commented Nov 18, 2021

Thanks @matthewmturner !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

datafusion cli to support listing functions
4 participants