-
Notifications
You must be signed in to change notification settings - Fork 603
BigQuery: Fix column identifier reserved keywords list #1678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bff25db
to
a4d445b
Compare
src/dialect/mod.rs
Outdated
/// for the dialect. | ||
/// For example given: `SELECT <col> AS <alias> FROM T`. The returned | ||
/// keywords are not allowed in `<col>` and `<alias>` | ||
fn get_reserved_keywords_for_column_identifier(&self) -> &'static [Keyword] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically, a dialect may have a different list of reserved keywords for column identifiers and column aliases, and in some cases, the parser will need to look ahead to make that decision accurately.
Perhaps we should adopt a unified approach to this check along the lines of Dialect::is_select_item_alias
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this would be nice -- perhaps we can do so in a follow on PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this sounds good! I'll take a look at it tomorrow and I'll ping to take another look at the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this now to be similar to is_select_item_alias
, taking in a parser, PTAL!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @iffyio and @yoavcloud -- this looks good to me.
@@ -213,6 +213,15 @@ fn parse_raw_literal() { | |||
); | |||
} | |||
|
|||
#[test] | |||
fn parse_big_query_non_reserved_column_alias() { | |||
let sql = r#"SELECT OFFSET, EXPLAIN, ANALYZE, SORT, TOP, VIEW FROM T"#; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
src/dialect/mod.rs
Outdated
/// for the dialect. | ||
/// For example given: `SELECT <col> AS <alias> FROM T`. The returned | ||
/// keywords are not allowed in `<col>` and `<alias>` | ||
fn get_reserved_keywords_for_column_identifier(&self) -> &'static [Keyword] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this would be nice -- perhaps we can do so in a follow on PR
Parser currently uses the same `RESERVED_FOR_COLUMN_ALIAS` keywords list to avoid lookahead when parsing column identifiers. This assumed that all listed keywords were reservered across all dialects which isn't the case. So that the following valid BigQuery statement previously failed due to `OFFSET` being flagged as a keyword. ```sql SELECT 1, OFFSET FROM T ``` This updates the parser to support dialect specific `RESERVED_FOR_COLUMN_ALIAS` list
a4d445b
to
2b00afd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👨🍳 👌
Parser currently uses the same
RESERVED_FOR_COLUMN_ALIAS
keywords list to avoid lookahead when parsing column identifiers. This assumed that all listed keywords were reservered across all dialects which isn't the case.So that the following valid BigQuery statement previously failed due to
OFFSET
being flagged as a keyword.This updates the parser to support dialect specific
RESERVED_FOR_COLUMN_ALIAS
list