From 67d310106ed4c3629b8ec02985aa41c18c568ecf Mon Sep 17 00:00:00 2001 From: Barry Date: Fri, 11 Mar 2022 16:57:23 +0000 Subject: [PATCH 1/2] BigQuery - avoid L006 being raise on hyphenated table references --- src/sqlfluff/dialects/dialect_bigquery.py | 4 +++- .../select_hyphenated_table_name_in_from.yml | 12 ++++++------ test/fixtures/rules/std_rule_cases/L006.yml | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/sqlfluff/dialects/dialect_bigquery.py b/src/sqlfluff/dialects/dialect_bigquery.py index 6c322405419..7e198cf8340 100644 --- a/src/sqlfluff/dialects/dialect_bigquery.py +++ b/src/sqlfluff/dialects/dialect_bigquery.py @@ -817,7 +817,9 @@ class HyphenatedObjectReferenceSegment(ObjectReferenceSegment): # type: ignore match_grammar.delimiter = OneOf( Ref("DotSegment"), Sequence(Ref("DotSegment"), Ref("DotSegment")), - Sequence(Ref("MinusSegment")), + Sequence( + StringParser("-", SymbolSegment, name="dash", type="dash"), + ), ) def iter_raw_references(self): diff --git a/test/fixtures/dialects/bigquery/select_hyphenated_table_name_in_from.yml b/test/fixtures/dialects/bigquery/select_hyphenated_table_name_in_from.yml index b33a74bbf3b..86fa5be5415 100644 --- a/test/fixtures/dialects/bigquery/select_hyphenated_table_name_in_from.yml +++ b/test/fixtures/dialects/bigquery/select_hyphenated_table_name_in_from.yml @@ -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: 103b85caea8316516741519b191e16afa6a3241cd0c0e716e98862e2bf66accf +_hash: 988e9594c851997adb0722cc892d1e3670f696e151a8817c7934652d6bcab118 file: statement: select_statement: @@ -20,15 +20,15 @@ file: table_expression: hyphenated_object_reference: - identifier: project - - binary_operator: '-' + - dash: '-' - identifier: a - dot: . - identifier: dataset - - binary_operator: '-' + - dash: '-' - identifier: b - dot: . - identifier: table - - binary_operator: '-' + - dash: '-' - identifier: c join_clause: - keyword: JOIN @@ -36,11 +36,11 @@ file: table_expression: hyphenated_object_reference: - identifier: dataset - - binary_operator: '-' + - dash: '-' - identifier: c - dot: . - identifier: table - - binary_operator: '-' + - dash: '-' - identifier: d - keyword: USING - bracketed: diff --git a/test/fixtures/rules/std_rule_cases/L006.yml b/test/fixtures/rules/std_rule_cases/L006.yml index b7e549d65f0..7824dbb2f9b 100644 --- a/test/fixtures/rules/std_rule_cases/L006.yml +++ b/test/fixtures/rules/std_rule_cases/L006.yml @@ -57,3 +57,11 @@ fail_simple: dont_fail_on_too_much_whitespace: # Too much whitespace should be caught by L039 pass_str: "SELECT 1 + 2" + + +pass_bigquery_hyphen: + # hypenated table reference should not fail + pass_str: SELECT col_foo FROM foo-bar.foo.bar + configs: + core: + dialect: bigquery From 27f9671f976aed8b3cf98b4cc9c960da2b2fc344 Mon Sep 17 00:00:00 2001 From: Barry Hart Date: Fri, 11 Mar 2022 16:54:11 -0500 Subject: [PATCH 2/2] Update test/fixtures/rules/std_rule_cases/L006.yml --- test/fixtures/rules/std_rule_cases/L006.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/rules/std_rule_cases/L006.yml b/test/fixtures/rules/std_rule_cases/L006.yml index 7824dbb2f9b..9467636753d 100644 --- a/test/fixtures/rules/std_rule_cases/L006.yml +++ b/test/fixtures/rules/std_rule_cases/L006.yml @@ -60,7 +60,7 @@ dont_fail_on_too_much_whitespace: pass_bigquery_hyphen: - # hypenated table reference should not fail + # hyphenated table reference should not fail pass_str: SELECT col_foo FROM foo-bar.foo.bar configs: core: