Repository navigation
Add support for named argument functions - #250
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 . |
| #[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.
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.
Fixed ,
I agree that enum is better.
| FunctionArg::Named(named_arg) => named_arg.fmt(f), | ||
| FunctionArg::Unnamed(unnamed_arg) => unnamed_arg.fmt(f), |
There was a problem hiding this comment.
We use write!(f, "{}", ...) in other places for this.
| // the `=>` | ||
| let _ = self.next_token(); |
There was a problem hiding this comment.
Please use expect_token instead.
| // identifier or keyword | ||
| // identifier or Keyword |
There was a problem hiding this comment.
sorry , by mistake ..
| /// An SQL expression of any type. | ||
| /// | ||
| /// 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.
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.