mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Support DISTINCT AS { STRUCT | VALUE } for BigQuery (#1880)
Some checks failed
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / compile (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
Some checks failed
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / compile (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
This commit is contained in:
parent
c2e83d49f6
commit
703ba2cf48
3 changed files with 69 additions and 18 deletions
|
|
@ -11505,18 +11505,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
let select_token = self.expect_keyword(Keyword::SELECT)?;
|
||||
let value_table_mode =
|
||||
if dialect_of!(self is BigQueryDialect) && self.parse_keyword(Keyword::AS) {
|
||||
if self.parse_keyword(Keyword::VALUE) {
|
||||
Some(ValueTableMode::AsValue)
|
||||
} else if self.parse_keyword(Keyword::STRUCT) {
|
||||
Some(ValueTableMode::AsStruct)
|
||||
} else {
|
||||
self.expected("VALUE or STRUCT", self.peek_token())?
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let value_table_mode = self.parse_value_table_mode()?;
|
||||
|
||||
let mut top_before_distinct = false;
|
||||
let mut top = None;
|
||||
|
|
@ -11692,6 +11681,32 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn parse_value_table_mode(&mut self) -> Result<Option<ValueTableMode>, ParserError> {
|
||||
if !dialect_of!(self is BigQueryDialect) {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let mode = if self.parse_keywords(&[Keyword::DISTINCT, Keyword::AS, Keyword::VALUE]) {
|
||||
Some(ValueTableMode::DistinctAsValue)
|
||||
} else if self.parse_keywords(&[Keyword::DISTINCT, Keyword::AS, Keyword::STRUCT]) {
|
||||
Some(ValueTableMode::DistinctAsStruct)
|
||||
} else if self.parse_keywords(&[Keyword::AS, Keyword::VALUE])
|
||||
|| self.parse_keywords(&[Keyword::ALL, Keyword::AS, Keyword::VALUE])
|
||||
{
|
||||
Some(ValueTableMode::AsValue)
|
||||
} else if self.parse_keywords(&[Keyword::AS, Keyword::STRUCT])
|
||||
|| self.parse_keywords(&[Keyword::ALL, Keyword::AS, Keyword::STRUCT])
|
||||
{
|
||||
Some(ValueTableMode::AsStruct)
|
||||
} else if self.parse_keyword(Keyword::AS) {
|
||||
self.expected("VALUE or STRUCT", self.peek_token())?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(mode)
|
||||
}
|
||||
|
||||
/// Invoke `f` after first setting the parser's `ParserState` to `state`.
|
||||
///
|
||||
/// Upon return, restores the parser's state to what it started at.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue