Skip to content

Commit

Permalink
Update condition for BigQueryDialect or GenericDialect
Browse files Browse the repository at this point in the history
I updated condition.
This changes conditionalize parsing for only BigQueryDialect or GenericDialect.
  • Loading branch information
sivchari committed May 24, 2022
1 parent 25b878f commit 4c5021f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
41 changes: 23 additions & 18 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3609,27 +3609,32 @@ impl<'a> Parser<'a> {
// appearing alone in parentheses (e.g. `FROM (mytable)`)
self.expected("joined table", self.peek_token())
}
} else if self.parse_keyword(Keyword::UNNEST) {
self.expect_token(&Token::LParen)?;
let expr = self.parse_expr()?;
self.expect_token(&Token::RParen)?;
} else if dialect_of!(self is BigQueryDialect | GenericDialect) {
if self.parse_keyword(Keyword::UNNEST) {
self.expect_token(&Token::LParen)?;
let expr = self.parse_expr()?;
self.expect_token(&Token::RParen)?;

let alias = match self.parse_optional_table_alias(keywords::RESERVED_FOR_TABLE_ALIAS) {
Ok(Some(alias)) => Some(alias),
Ok(None) => None,
Err(e) => return Err(e),
};
let alias =
match self.parse_optional_table_alias(keywords::RESERVED_FOR_TABLE_ALIAS) {
Ok(Some(alias)) => Some(alias),
Ok(None) => None,
Err(e) => return Err(e),
};

let with_offset = match self.expect_keywords(&[Keyword::WITH, Keyword::OFFSET]) {
Ok(()) => true,
Err(_) => false,
};
let with_offset = match self.expect_keywords(&[Keyword::WITH, Keyword::OFFSET]) {
Ok(()) => true,
Err(_) => false,
};

Ok(TableFactor::UNNEST {
alias,
array_expr: Box::new(expr),
with_offset,
})
Ok(TableFactor::UNNEST {
alias,
array_expr: Box::new(expr),
with_offset,
})
} else {
self.expected("UNNEST", self.peek_token())
}
} else {
let name = self.parse_object_name()?;
// Postgres, MSSQL: table-valued functions:
Expand Down
5 changes: 4 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2779,8 +2779,11 @@ fn parse_table_function() {

#[test]
fn parse_unnest() {
let dialects = TestedDialects {
dialects: vec![Box::new(BigQueryDialect {}), Box::new(GenericDialect {})],
};
let sql = "SELECT * FROM UNNEST(expr) AS numbers WITH OFFSET";
let select = verified_only_select(sql);
let select = dialects.verified_only_select(sql);
assert_eq!(
select.from,
vec![TableWithJoins {
Expand Down

0 comments on commit 4c5021f

Please sign in to comment.