Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add statement helper command to cli#1285

Merged
alamb merged 8 commits into
apache:masterfrom
matthewmturner:add_statement_helper_command_to_cli
Nov 18, 2021
Merged

Add statement helper command to cli#1285
alamb merged 8 commits into
apache:masterfrom
matthewmturner:add_statement_helper_command_to_cli

Conversation

@matthewmturner

Copy link
Copy Markdown
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?

@matthewmturner

Copy link
Copy Markdown
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.

Comment thread datafusion-cli/src/command.rs Outdated
Help,
ListTables,
DescribeTable(String),
FunctionList,

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

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

@jimexist

Copy link
Copy Markdown
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

@capkurmagati capkurmagati left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread datafusion-cli/src/command.rs Outdated
)),
Self::ListFunctions => display_all_functions(),
Self::SearchFunctions(function) => {
let func = function.parse::<Function>().unwrap();

Copy link
Copy Markdown
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.

Comment thread datafusion-cli/src/functions.rs Outdated
type Err = ();

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@jimexist ready when you get the chance

Comment thread datafusion-cli/src/command.rs Outdated
if let Ok(func) = function.parse::<Function>() {
func.function_details()?
} else {
eprintln!("{} is not a supported function", function)

Copy link
Copy Markdown
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?

Comment thread datafusion-cli/src/functions.rs Outdated
pub fn function_details(&self) -> Result<()> {
match self {
Function::Select => {
let details = "

Copy link
Copy Markdown
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

Comment thread datafusion-cli/src/functions.rs
Comment thread datafusion-cli/src/functions.rs Outdated
Syntax:
EXPLAIN [ ANALYZE ] statement
";
println!("{}", details)

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Comment thread datafusion-cli/src/functions.rs Outdated

@jimexist jimexist left a comment

Copy link
Copy Markdown
Member

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 <[email protected]>
@alamb alamb merged commit 42f8ab1 into apache:master Nov 18, 2021
@alamb

alamb commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

Thanks @matthewmturner !

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.

datafusion cli to support listing functions

4 participants