-
Notifications
You must be signed in to change notification settings - Fork 610
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
Merged
alamb
merged 5 commits into
apache:main
from
git-hulk:feature/clickhouse-function-parametric
Jun 23, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ use core::fmt; | |
|
||
use log::debug; | ||
|
||
use recursion::RecursionCounter; | ||
use IsLateral::*; | ||
use IsOptional::*; | ||
|
||
|
@@ -143,8 +144,6 @@ mod recursion { | |
pub struct DepthGuard {} | ||
} | ||
|
||
use recursion::RecursionCounter; | ||
|
||
#[derive(PartialEq, Eq)] | ||
pub enum IsOptional { | ||
Optional, | ||
|
@@ -999,6 +998,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 +1055,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 +1291,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 +1300,16 @@ 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 aggregations support parametric functions like `HISTOGRAM(0.5, 0.6)(x, y)` | ||
// which (0.5, 0.6) is a parameter to the function. | ||
if dialect_of!(self is ClickHouseDialect | GenericDialect) | ||
&& self.consume_token(&Token::LParen) | ||
{ | ||
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 +1358,7 @@ impl<'a> Parser<'a> { | |
|
||
Ok(Expr::Function(Function { | ||
name, | ||
parameters, | ||
args: FunctionArguments::List(args), | ||
null_treatment, | ||
filter, | ||
|
@@ -1379,6 +1391,7 @@ impl<'a> Parser<'a> { | |
}; | ||
Ok(Expr::Function(Function { | ||
name, | ||
parameters: FunctionArguments::None, | ||
args, | ||
filter: None, | ||
over: None, | ||
|
@@ -6454,6 +6467,7 @@ impl<'a> Parser<'a> { | |
} else { | ||
Ok(Statement::Call(Function { | ||
name: object_name, | ||
parameters: FunctionArguments::None, | ||
args: FunctionArguments::None, | ||
over: None, | ||
filter: None, | ||
|
@@ -8081,7 +8095,7 @@ impl<'a> Parser<'a> { | |
pub fn parse_query_body(&mut self, precedence: u8) -> Result<SetExpr, ParserError> { | ||
// We parse the expression using a Pratt parser, as in `parse_expr()`. | ||
// Start by parsing a restricted SELECT or a `(subquery)`: | ||
let mut expr = if self.parse_keyword(Keyword::SELECT) { | ||
let expr = if self.parse_keyword(Keyword::SELECT) { | ||
SetExpr::Select(self.parse_select().map(Box::new)?) | ||
} else if self.consume_token(&Token::LParen) { | ||
// CTEs are not allowed here, but the parser currently accepts them | ||
|
@@ -8100,6 +8114,17 @@ impl<'a> Parser<'a> { | |
); | ||
}; | ||
|
||
self.parse_remaining_set_exprs(expr, precedence) | ||
} | ||
|
||
/// Parse any extra set expressions that may be present in a query body | ||
/// | ||
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. I also pushed a commit to split up this function in e2ec2a6 to get the deeply nested tests to pass This is the failure without this change: https://github.com/sqlparser-rs/sqlparser-rs/actions/runs/9632995493/job/26566863197
|
||
/// (this is its own function to reduce required stack size in debug builds) | ||
fn parse_remaining_set_exprs( | ||
&mut self, | ||
mut expr: SetExpr, | ||
precedence: u8, | ||
) -> Result<SetExpr, ParserError> { | ||
loop { | ||
// The query can be optionally followed by a set operator: | ||
let op = self.parse_set_operator(&self.peek_token().token); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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