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

BigQuery - prevent L006 flagging hyphenated table references #2842

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sqlfluff/dialects/dialect_bigquery.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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:
# hypenated table reference should not fail
barrywhart marked this conversation as resolved.
Show resolved Hide resolved
pass_str: SELECT col_foo FROM foo-bar.foo.bar
configs:
core:
dialect: bigquery