mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-04 13:10:31 +00:00
ClickHouse CREATE TABLE Fixes: add ORDER BY and fix clause ordering (#824)
* Fix ClickHouse (add ORDER BY) * Improve test case
This commit is contained in:
parent
1cf913e717
commit
d69b875367
4 changed files with 59 additions and 11 deletions
|
@ -3340,12 +3340,6 @@ impl<'a> Parser<'a> {
|
|||
// PostgreSQL supports `WITH ( options )`, before `AS`
|
||||
let with_options = self.parse_options(Keyword::WITH)?;
|
||||
let table_properties = self.parse_options(Keyword::TBLPROPERTIES)?;
|
||||
// Parse optional `AS ( query )`
|
||||
let query = if self.parse_keyword(Keyword::AS) {
|
||||
Some(Box::new(self.parse_query()?))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let engine = if self.parse_keyword(Keyword::ENGINE) {
|
||||
self.expect_token(&Token::Eq)?;
|
||||
|
@ -3358,6 +3352,29 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
};
|
||||
|
||||
let order_by = if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) {
|
||||
if self.consume_token(&Token::LParen) {
|
||||
let columns = if self.peek_token() != Token::RParen {
|
||||
self.parse_comma_separated(Parser::parse_identifier)?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Some(columns)
|
||||
} else {
|
||||
Some(vec![self.parse_identifier()?])
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Parse optional `AS ( query )`
|
||||
let query = if self.parse_keyword(Keyword::AS) {
|
||||
Some(Box::new(self.parse_query()?))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let default_charset = if self.parse_keywords(&[Keyword::DEFAULT, Keyword::CHARSET]) {
|
||||
self.expect_token(&Token::Eq)?;
|
||||
let next_token = self.next_token();
|
||||
|
@ -3414,6 +3431,7 @@ impl<'a> Parser<'a> {
|
|||
.like(like)
|
||||
.clone_clause(clone)
|
||||
.engine(engine)
|
||||
.order_by(order_by)
|
||||
.default_charset(default_charset)
|
||||
.collation(collation)
|
||||
.on_commit(on_commit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue