forked from repo-mirrors/sqlfluff
Bigquery: Support column level key definitions (#6465)
This commit is contained in:
@@ -556,6 +556,7 @@ ansi_dialect.add(
|
||||
PrimaryKeyGrammar=Sequence("PRIMARY", "KEY"),
|
||||
ForeignKeyGrammar=Sequence("FOREIGN", "KEY"),
|
||||
UniqueKeyGrammar=Sequence("UNIQUE"),
|
||||
NotEnforcedGrammar=Nothing(),
|
||||
# Odd syntax, but prevents eager parameters being confused for data types
|
||||
FunctionParameterGrammar=OneOf(
|
||||
Sequence(
|
||||
@@ -665,20 +666,20 @@ ansi_dialect.add(
|
||||
Ref("FunctionSegment"),
|
||||
Ref("BareFunctionSegment"),
|
||||
),
|
||||
ReferenceMatchGrammar=Sequence(
|
||||
"MATCH",
|
||||
OneOf(
|
||||
"FULL",
|
||||
"PARTIAL",
|
||||
"SIMPLE",
|
||||
),
|
||||
),
|
||||
ReferenceDefinitionGrammar=Sequence(
|
||||
"REFERENCES",
|
||||
Ref("TableReferenceSegment"),
|
||||
# Foreign columns making up FOREIGN KEY constraint
|
||||
Ref("BracketedColumnReferenceListGrammar", optional=True),
|
||||
Sequence(
|
||||
"MATCH",
|
||||
OneOf(
|
||||
"FULL",
|
||||
"PARTIAL",
|
||||
"SIMPLE",
|
||||
),
|
||||
optional=True,
|
||||
),
|
||||
Ref("ReferenceMatchGrammar", optional=True),
|
||||
AnySetOf(
|
||||
# ON DELETE clause, e.g. ON DELETE NO ACTION
|
||||
Sequence(
|
||||
@@ -3130,10 +3131,15 @@ class ColumnConstraintSegment(BaseSegment):
|
||||
"DEFAULT",
|
||||
Ref("ColumnConstraintDefaultGrammar"),
|
||||
),
|
||||
Ref("PrimaryKeyGrammar"),
|
||||
Sequence(
|
||||
Ref("PrimaryKeyGrammar"), Ref("NotEnforcedGrammar", optional=True)
|
||||
),
|
||||
Ref("UniqueKeyGrammar"), # UNIQUE
|
||||
Ref("AutoIncrementGrammar"),
|
||||
Ref("ReferenceDefinitionGrammar"), # REFERENCES reftable [ ( refcolumn) ]x
|
||||
Sequence(
|
||||
Ref("ReferenceDefinitionGrammar"),
|
||||
Ref("NotEnforcedGrammar", optional=True),
|
||||
), # REFERENCES reftable [ ( refcolumn) ]x
|
||||
Ref("CommentClauseSegment"),
|
||||
Sequence(
|
||||
"COLLATE", Ref("CollationReferenceSegment")
|
||||
|
||||
@@ -324,6 +324,8 @@ bigquery_dialect.replace(
|
||||
Ref("SemiStructuredAccessorSegment"),
|
||||
),
|
||||
BracketedSetExpressionGrammar=Bracketed(Ref("SetExpressionSegment")),
|
||||
NotEnforcedGrammar=Sequence("NOT", "ENFORCED"),
|
||||
ReferenceMatchGrammar=Nothing(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -19,3 +19,8 @@ CREATE TABLE t_table1
|
||||
_other STRING
|
||||
)
|
||||
;
|
||||
|
||||
CREATE TABLE `some_dataset.some_table` (
|
||||
id STRING NOT NULL PRIMARY KEY NOT ENFORCED,
|
||||
other_field STRING REFERENCES other_table(other_field) NOT ENFORCED
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# 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: 2e318327637f8ff0d1e4cbbe1c338b2d39724e040ffffd39dde1aa208cd310ea
|
||||
_hash: e4af7f29c06a83c2190d5fd2588bfe8558c9438902ff2587fdc5194747f96e62
|
||||
file:
|
||||
- statement:
|
||||
create_table_statement:
|
||||
@@ -118,3 +118,41 @@ file:
|
||||
data_type_identifier: STRING
|
||||
- end_bracket: )
|
||||
- statement_terminator: ;
|
||||
- statement:
|
||||
create_table_statement:
|
||||
- keyword: CREATE
|
||||
- keyword: TABLE
|
||||
- table_reference:
|
||||
quoted_identifier: '`some_dataset.some_table`'
|
||||
- bracketed:
|
||||
- start_bracket: (
|
||||
- column_definition:
|
||||
- naked_identifier: id
|
||||
- data_type:
|
||||
data_type_identifier: STRING
|
||||
- column_constraint_segment:
|
||||
- keyword: NOT
|
||||
- keyword: 'NULL'
|
||||
- column_constraint_segment:
|
||||
- keyword: PRIMARY
|
||||
- keyword: KEY
|
||||
- keyword: NOT
|
||||
- keyword: ENFORCED
|
||||
- comma: ','
|
||||
- column_definition:
|
||||
naked_identifier: other_field
|
||||
data_type:
|
||||
data_type_identifier: STRING
|
||||
column_constraint_segment:
|
||||
- keyword: REFERENCES
|
||||
- table_reference:
|
||||
naked_identifier: other_table
|
||||
- bracketed:
|
||||
start_bracket: (
|
||||
column_reference:
|
||||
naked_identifier: other_field
|
||||
end_bracket: )
|
||||
- keyword: NOT
|
||||
- keyword: ENFORCED
|
||||
- end_bracket: )
|
||||
- statement_terminator: ;
|
||||
|
||||
Reference in New Issue
Block a user