Skip to content

Commit

Permalink
BigQuery - prevent L006 flagging hyphenated table references (#2842)
Browse files Browse the repository at this point in the history
* BigQuery - avoid L006 being raise on hyphenated table references

* Update test/fixtures/rules/std_rule_cases/L006.yml

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
  • Loading branch information
tunetheweb and barrywhart committed Mar 11, 2022
1 parent bdd8dde commit b44851f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/sqlfluff/dialects/dialect_bigquery.py
Expand Up @@ -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):
Expand Down
Expand Up @@ -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:
Expand All @@ -20,27 +20,27 @@ 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
- from_expression_element:
table_expression:
hyphenated_object_reference:
- identifier: dataset
- binary_operator: '-'
- dash: '-'
- identifier: c
- dot: .
- identifier: table
- binary_operator: '-'
- dash: '-'
- identifier: d
- keyword: USING
- bracketed:
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/rules/std_rule_cases/L006.yml
Expand Up @@ -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:
# hyphenated table reference should not fail
pass_str: SELECT col_foo FROM foo-bar.foo.bar
configs:
core:
dialect: bigquery

0 comments on commit b44851f

Please sign in to comment.