-
Notifications
You must be signed in to change notification settings - Fork 612
[ClickHouse] Add support for WITH FILL to OrderByExpr #1330
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 10 commits
815ee5b
7022e42
47ba442
4068bb3
ec263d2
4b8c6fe
85fae63
4a7167b
7e745c3
44deb69
000e08d
9aaca38
6ee4257
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 |
---|---|---|
|
@@ -7931,7 +7931,7 @@ impl<'a> Parser<'a> { | |
body: self.parse_insert_setexpr_boxed()?, | ||
limit: None, | ||
limit_by: vec![], | ||
order_by: vec![], | ||
order_by: None, | ||
offset: None, | ||
fetch: None, | ||
locks: vec![], | ||
|
@@ -7945,7 +7945,7 @@ impl<'a> Parser<'a> { | |
body: self.parse_update_setexpr_boxed()?, | ||
limit: None, | ||
limit_by: vec![], | ||
order_by: vec![], | ||
order_by: None, | ||
offset: None, | ||
fetch: None, | ||
locks: vec![], | ||
|
@@ -7957,9 +7957,15 @@ impl<'a> Parser<'a> { | |
let body = self.parse_boxed_query_body(0)?; | ||
|
||
let order_by = if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) { | ||
self.parse_comma_separated(Parser::parse_order_by_expr)? | ||
let order_by_exprs = self.parse_comma_separated(Parser::parse_order_by_expr)?; | ||
let interpolate = self.parse_interpolations()?; | ||
|
||
Some(OrderBy { | ||
exprs: order_by_exprs, | ||
interpolate, | ||
}) | ||
} else { | ||
vec![] | ||
None | ||
}; | ||
|
||
let mut limit = None; | ||
|
@@ -9190,7 +9196,7 @@ impl<'a> Parser<'a> { | |
subquery: Box::new(Query { | ||
with: None, | ||
body: Box::new(values), | ||
order_by: vec![], | ||
order_by: None, | ||
limit: None, | ||
limit_by: vec![], | ||
offset: None, | ||
|
@@ -10511,13 +10517,79 @@ impl<'a> Parser<'a> { | |
None | ||
}; | ||
|
||
let with_fill = if dialect_of!(self is ClickHouseDialect | GenericDialect) | ||
&& self.parse_keywords(&[Keyword::WITH, Keyword::FILL]) | ||
{ | ||
Some(self.parse_with_fill()?) | ||
} else { | ||
None | ||
}; | ||
|
||
Ok(OrderByExpr { | ||
expr, | ||
asc, | ||
nulls_first, | ||
with_fill, | ||
}) | ||
} | ||
|
||
// Parse a WITH FILL clause (ClickHouse dialect) | ||
// that follow the WITH FILL keywords in a ORDER BY clause | ||
pub fn parse_with_fill(&mut self) -> Result<WithFill, ParserError> { | ||
let from = if self.parse_keyword(Keyword::FROM) { | ||
Some(self.parse_expr()?) | ||
} else { | ||
None | ||
}; | ||
|
||
let to = if self.parse_keyword(Keyword::TO) { | ||
Some(self.parse_expr()?) | ||
} else { | ||
None | ||
}; | ||
|
||
let step = if self.parse_keyword(Keyword::STEP) { | ||
Some(self.parse_expr()?) | ||
} else { | ||
None | ||
}; | ||
|
||
Ok(WithFill { from, to, step }) | ||
} | ||
|
||
// Parse a set of comma seperated INTERPOLATE expressions (ClickHouse dialect) | ||
// that follow the INTERPOLATE keyword in an ORDER BY clause with the WITH FILL modifier | ||
pub fn parse_interpolations(&mut self) -> Result<Option<Interpolate>, ParserError> { | ||
if dialect_of!(self is ClickHouseDialect | GenericDialect) | ||
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. We can move this dialect check outside the function and to the caller, and have the function only care about the parsing logic. one minor, we can also avoid nesting the function body by returning early if !self.parse_keyword(Keyword::INTERPOLATE) {
return Ok(None)
}
if self.consume_token(...)
Ok(Some(...)) 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. Done in 000e08d. Thanks! |
||
&& self.parse_keyword(Keyword::INTERPOLATE) | ||
{ | ||
if self.consume_token(&Token::LParen) { | ||
let interpolations = self.parse_comma_separated0(|p| p.parse_interpolation())?; | ||
self.expect_token(&Token::RParen)?; | ||
// INTERPOLATE () and INTERPOLATE ( ... ) variants | ||
Ok(Some(Interpolate { | ||
exprs: Some(interpolations), | ||
})) | ||
} else { | ||
// INTERPOLATE | ||
Ok(Some(Interpolate { exprs: None })) | ||
} | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
|
||
// Parse a INTERPOLATE expression (ClickHouse dialect) | ||
pub fn parse_interpolation(&mut self) -> Result<InterpolateExpr, ParserError> { | ||
let column = self.parse_identifier(false)?; | ||
let expr = if self.parse_keyword(Keyword::AS) { | ||
Some(self.parse_expr()?) | ||
} else { | ||
None | ||
}; | ||
Ok(InterpolateExpr { column, expr }) | ||
} | ||
|
||
/// Parse a TOP clause, MSSQL equivalent of LIMIT, | ||
/// that follows after `SELECT [DISTINCT]`. | ||
pub fn parse_top(&mut self) -> Result<Top, ParserError> { | ||
|
Uh oh!
There was an error while loading. Please reload this page.