-
Notifications
You must be signed in to change notification settings - Fork 603
Add support for named argument functions #250
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
Conversation
Sorry about some style changes that made by |
Pull Request Test Coverage Report for Build 191486507
💛 - Coveralls |
I find it weird that you added NamedArgument as a new variant of Expr. This makes the parser accept many weird constructs, which shouldn't be accepted. I expected this to be a new SelectItem-like enum. You can use The argument name is a simple identifier, not an ObjectName. Please check the PR for typos (FUCNTION, rigth, agument, // vs /// (which led to rustfmt reformatting the whole enum))
Surely you meant |
e400c10
to
cc116b9
Compare
Sorry for all the typos , I fixed them (Hope that all of them..) But i don't sure what you means when you say that the named-argument should be |
I said a new enum, a little like SelectItem (currently with two variants: unnamed argument, named argument). |
a6d8f94
to
37a4d49
Compare
I done the changes according to comments . |
src/ast/mod.rs
Outdated
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct FunctionNamedArg { | ||
pub name: Ident, | ||
pub arg: Expr, | ||
} | ||
|
||
impl fmt::Display for FunctionNamedArg { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{} => {}", self.name, self.arg)?; | ||
Ok(()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make this a separate struct, rather than FunctionArg::Named { name, arg }
?
(Another option is to make the argument type a simple struct with an optional name
, and the reason I suggested enum
initially because of the other possible kinds of SQL arguments...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed ,
I agree that enum is better.
src/ast/mod.rs
Outdated
FunctionArg::Named(named_arg) => named_arg.fmt(f), | ||
FunctionArg::Unnamed(unnamed_arg) => unnamed_arg.fmt(f), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use write!(f, "{}", ...)
in other places for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/parser.rs
Outdated
// the `=>` | ||
let _ = self.next_token(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use expect_token
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/tokenizer.rs
Outdated
// identifier or keyword | ||
// identifier or Keyword |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry , by mistake ..
src/ast/mod.rs
Outdated
/// The parser does not distinguish between expressions of different types | ||
/// The parser does not distinguish between qessions of different types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry , by mistake ..
This commit support functions with argument names. the format is : "Select some_function( a => exp, b => exp2 .. ) FROM table1 OR "select * from table(function(a => exp)) f;" see: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#named-argument-assignment-token or example is snwflake db : https://docs.snowflake.com/en/sql-reference/functions/flatten.html
37a4d49
to
b15a7bc
Compare
Thanks! |
This commit supports functions with argument names. the format is : "Select some_function( a => exp, b => exp2 .. ) FROM table1 OR "select * from table(function(a => exp)) f;" see: https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#named-argument-assignment-token or the motivating example from snowflake: https://docs.snowflake.com/en/sql-reference/functions/flatten.html
Add support for named argument function
This commit support functions with argument names.
the format is :
"Select some_function( a => exp, b => exp2 .. ) FROM table1
OR
"select * from table(function(a => exp)) f;"
see:
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#named-argument-assignment-token
or example is snwflake db :
https://docs.snowflake.com/en/sql-reference/functions/flatten.html
This commit does not belong to any branch on this repository.