-
Notifications
You must be signed in to change notification settings - Fork 612
Support parametric arguments to FUNCTION
for ClickHouse dialect
#1315
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -999,6 +999,7 @@ impl<'a> Parser<'a> { | |||||
{ | ||||||
Ok(Expr::Function(Function { | ||||||
name: ObjectName(vec![w.to_ident()]), | ||||||
parameters: FunctionArguments::None, | ||||||
args: FunctionArguments::None, | ||||||
null_treatment: None, | ||||||
filter: None, | ||||||
|
@@ -1055,6 +1056,7 @@ impl<'a> Parser<'a> { | |||||
self.expect_token(&Token::RParen)?; | ||||||
Ok(Expr::Function(Function { | ||||||
name: ObjectName(vec![w.to_ident()]), | ||||||
parameters: FunctionArguments::None, | ||||||
args: FunctionArguments::Subquery(query), | ||||||
filter: None, | ||||||
null_treatment: None, | ||||||
|
@@ -1290,6 +1292,7 @@ impl<'a> Parser<'a> { | |||||
self.expect_token(&Token::RParen)?; | ||||||
return Ok(Expr::Function(Function { | ||||||
name, | ||||||
parameters: FunctionArguments::None, | ||||||
args: FunctionArguments::Subquery(subquery), | ||||||
filter: None, | ||||||
null_treatment: None, | ||||||
|
@@ -1298,7 +1301,14 @@ impl<'a> Parser<'a> { | |||||
})); | ||||||
} | ||||||
|
||||||
let args = self.parse_function_argument_list()?; | ||||||
let mut args = self.parse_function_argument_list()?; | ||||||
let mut parameters = FunctionArguments::None; | ||||||
// ClickHouse aggregation support parametric functions like `quantile(0.5)(x)` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// which (0.5) is a parameter to the function. | ||||||
if dialect_of!(self is ClickHouseDialect) && self.consume_token(&Token::LParen) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
we can include generic dialect if no conflicts |
||||||
parameters = FunctionArguments::List(args); | ||||||
args = self.parse_function_argument_list()?; | ||||||
} | ||||||
|
||||||
let within_group = if self.parse_keywords(&[Keyword::WITHIN, Keyword::GROUP]) { | ||||||
self.expect_token(&Token::LParen)?; | ||||||
|
@@ -1347,6 +1357,7 @@ impl<'a> Parser<'a> { | |||||
|
||||||
Ok(Expr::Function(Function { | ||||||
name, | ||||||
parameters, | ||||||
args: FunctionArguments::List(args), | ||||||
null_treatment, | ||||||
filter, | ||||||
|
@@ -1379,6 +1390,7 @@ impl<'a> Parser<'a> { | |||||
}; | ||||||
Ok(Expr::Function(Function { | ||||||
name, | ||||||
parameters: FunctionArguments::None, | ||||||
args, | ||||||
filter: None, | ||||||
over: None, | ||||||
|
@@ -6454,6 +6466,7 @@ impl<'a> Parser<'a> { | |||||
} else { | ||||||
Ok(Statement::Call(Function { | ||||||
name: object_name, | ||||||
parameters: FunctionArguments::None, | ||||||
args: FunctionArguments::None, | ||||||
over: None, | ||||||
filter: None, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,7 @@ fn parse_delimited_identifiers() { | |
assert_eq!( | ||
&Expr::Function(Function { | ||
name: ObjectName(vec![Ident::with_quote('"', "myfun")]), | ||
parameters: FunctionArguments::None, | ||
args: FunctionArguments::List(FunctionArgumentList { | ||
duplicate_treatment: None, | ||
args: vec![], | ||
|
@@ -553,6 +554,11 @@ fn parse_select_star_except() { | |
clickhouse().verified_stmt("SELECT * EXCEPT (prev_status) FROM anomalies"); | ||
} | ||
|
||
#[test] | ||
fn parse_select_parametric_function() { | ||
clickhouse().verified_stmt("SELECT quantile(0.5)(x) FROM t"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we extend the test asserting that the parameter and arguments lists do indeed show up in the |
||
|
||
#[test] | ||
fn parse_select_star_except_no_parens() { | ||
clickhouse().one_statement_parses_to( | ||
|
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.
Can we include a link to the clickhouse docs?
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.
@iffyio Done