Skip to content

Commit

Permalink
add supports_with_order function to dialect
Browse files Browse the repository at this point in the history
remove parse_options_in_parentheses functionality
  • Loading branch information
mertak-synnada committed Sep 3, 2024
1 parent e878149 commit 17ba408
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
4 changes: 4 additions & 0 deletions src/dialect/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ impl Dialect for GenericDialect {
true
}

fn supports_with_order_expr(&self) -> bool {
true
}

fn allow_extract_custom(&self) -> bool {
true
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if the dialects supports `WITH ORDER` expressions.
fn supports_with_order_expr(&self) -> bool {
false
}

/// Returns true if the dialect supports CONNECT BY.
fn supports_connect_by(&self) -> bool {
false
Expand Down
34 changes: 13 additions & 21 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5591,19 +5591,15 @@ impl<'a> Parser<'a> {
// PostgreSQL supports `WITH ( options )`, before `AS`
let mut with_options: Vec<SqlOption> = vec![];
let mut order_exprs: Vec<Vec<OrderByExpr>> = vec![];
if self.parse_keyword(Keyword::WITH) {
if self.parse_keyword(Keyword::ORDER) {
self.expect_token(&Token::LParen)?;
loop {
order_exprs.push(vec![self.parse_order_by_expr()?]);
if !self.consume_token(&Token::Comma) {
self.expect_token(&Token::RParen)?;
break;
}
}
} else {
with_options = self.parse_options_in_parentheses()?;
}
if self.dialect.supports_with_order_expr()
&& self.parse_keywords(&[Keyword::WITH, Keyword::ORDER])
{
self.expect_token(&Token::LParen)?;
let order_by = self.parse_comma_separated(Parser::parse_order_by_expr)?;
order_exprs.push(order_by);
self.expect_token(&Token::RParen)?;
} else {
with_options = self.parse_options(Keyword::WITH)?;
}

let table_properties = self.parse_options(Keyword::TBLPROPERTIES)?;
Expand Down Expand Up @@ -6386,19 +6382,15 @@ impl<'a> Parser<'a> {

pub fn parse_options(&mut self, keyword: Keyword) -> Result<Vec<SqlOption>, ParserError> {
if self.parse_keyword(keyword) {
self.parse_options_in_parentheses()
self.expect_token(&Token::LParen)?;
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
self.expect_token(&Token::RParen)?;
Ok(options)
} else {
Ok(vec![])
}
}

fn parse_options_in_parentheses(&mut self) -> Result<Vec<SqlOption>, ParserError> {
self.expect_token(&Token::LParen)?;
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
self.expect_token(&Token::RParen)?;
Ok(options)
}

pub fn parse_options_with_keywords(
&mut self,
keywords: &[Keyword],
Expand Down

0 comments on commit 17ba408

Please sign in to comment.