Support parentheses in DISTINCT clause, CURRENT_TIMESTAMP, CURRENT_TIME, and CURRENT_DATE (#391)

* Inital support in current_timestamp

* Support time functions

* Add Test

* Fix PR

* Fix tests

* Add Support for distinct with parentheses

* Fix nightly
This commit is contained in:
yuval-illumex 2022-02-05 13:39:35 +02:00 committed by GitHub
parent ea0eb1be61
commit fbc1d9659b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 92 additions and 0 deletions

View file

@ -408,6 +408,9 @@ impl<'a> Parser<'a> {
self.prev_token();
Ok(Expr::Value(self.parse_value()?))
}
Keyword::CURRENT_TIMESTAMP | Keyword::CURRENT_TIME | Keyword::CURRENT_DATE => {
self.parse_time_functions(ObjectName(vec![w.to_ident()]))
}
Keyword::CASE => self.parse_case_expr(),
Keyword::CAST => self.parse_cast_expr(),
Keyword::TRY_CAST => self.parse_try_cast_expr(),
@ -552,6 +555,20 @@ impl<'a> Parser<'a> {
}))
}
pub fn parse_time_functions(&mut self, name: ObjectName) -> Result<Expr, ParserError> {
let args = if self.consume_token(&Token::LParen) {
self.parse_optional_args()?
} else {
vec![]
};
Ok(Expr::Function(Function {
name,
args,
over: None,
distinct: false,
}))
}
pub fn parse_window_frame_units(&mut self) -> Result<WindowFrameUnits, ParserError> {
match self.next_token() {
Token::Word(w) => match w.keyword {
@ -2631,8 +2648,19 @@ impl<'a> Parser<'a> {
None
};
// Not Sure if Top should be cheked here as well. Trino doesn't support TOP.
let is_l_parent = if distinct {
self.consume_token(&Token::LParen)
} else {
false
};
let projection = self.parse_comma_separated(Parser::parse_select_item)?;
if is_l_parent {
self.consume_token(&Token::RParen);
}
// Note that for keywords to be properly handled here, they need to be
// added to `RESERVED_FOR_COLUMN_ALIAS` / `RESERVED_FOR_TABLE_ALIAS`,
// otherwise they may be parsed as an alias as part of the `projection`