Skip to content
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

Make Snowflake keywords unreserved: account, organization, pivot #2172

Merged
merged 7 commits into from Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sqlfluff/dialects/dialect_ansi.py
Expand Up @@ -621,6 +621,7 @@ class ObjectReferenceSegment(BaseSegment):
Ref("BinaryOperatorGrammar"),
Ref("ColonSegment"),
Ref("DelimiterSegment"),
Ref("JoinLikeClauseGrammar"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BorePlusPlus btw this is what I needed to add to stop the parser getting confused about whether PIVOT is an alias or a function.
Basically for an ObjectReferenceSegment, which is inherited by TableReferenceSegment, it will stop matching when the subsequent token is part of JoinLikeClauseGrammar, which contains the FromPivotExpressionSegment in Snowflake.

BracketedSegment,
),
allow_gaps=False,
Expand Down
8 changes: 4 additions & 4 deletions src/sqlfluff/dialects/dialect_snowflake_keywords.py
@@ -1,7 +1,6 @@
"""A list of all Snowflake SQL key words."""

snowflake_reserved_keywords = """ACCOUNT
ALL
snowflake_reserved_keywords = """ALL
ALTER
AND
ANY
Expand Down Expand Up @@ -59,9 +58,7 @@
ON
OR
ORDER
ORGANIZATION
PARTITION
PIVOT
QUALIFY
REGEXP
REVOKE
Expand Down Expand Up @@ -98,6 +95,7 @@
snowflake_unreserved_keywords = """ABORT
ABORT_STATEMENT
ACCESS
ACCOUNT
ACCOUNTS
ADD
ADMIN
Expand Down Expand Up @@ -269,6 +267,7 @@
OPTION
OPTIONS
ORC
ORGANIZATION
OUTER
OVER
OVERLAPS
Expand All @@ -281,6 +280,7 @@
PATTERN
PIPE
PIPES
PIVOT
POLICIES
POLICY
PRECEDING
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/dialects/bigquery/select_example.sql
Expand Up @@ -30,4 +30,4 @@ FROM
age_buckets_bit_array
JOIN
bucket_abundance
USING (bucket_id)
USING (bucket_id)
@@ -0,0 +1,9 @@
SELECT account
FROM foo;

CREATE TABLE IF NOT EXISTS table_name(
organization VARCHAR
);

with pivot as (select 1)
select * from pivot;
@@ -0,0 +1,68 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: 0a53b2cd033461a0d01c39c4b100a3d8dbb033a360a61d1fcd28d8b178c47f82
file:
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
column_reference:
identifier: account
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
identifier: foo
- statement_terminator: ;
- statement:
create_table_statement:
- keyword: CREATE
- keyword: TABLE
- keyword: IF
- keyword: NOT
- keyword: EXISTS
- table_reference:
identifier: table_name
- bracketed:
start_bracket: (
column_definition:
identifier: organization
data_type:
data_type_identifier: VARCHAR
end_bracket: )
- statement_terminator: ;
- statement:
with_compound_statement:
keyword: with
common_table_expression:
identifier: pivot
keyword: as
bracketed:
start_bracket: (
select_statement:
select_clause:
keyword: select
select_clause_element:
literal: '1'
end_bracket: )
select_statement:
select_clause:
keyword: select
select_clause_element:
wildcard_expression:
wildcard_identifier:
star: '*'
from_clause:
keyword: from
from_expression:
from_expression_element:
table_expression:
table_reference:
identifier: pivot
- statement_terminator: ;