Skip to content

Commit

Permalink
Merge branch 'main' into extra_config_path
Browse files Browse the repository at this point in the history
  • Loading branch information
jpy-git committed Nov 27, 2021
2 parents b586aa0 + d145358 commit 997622b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/sqlfluff/dialects/dialect_bigquery.py
Expand Up @@ -30,7 +30,9 @@
OptionallyBracketed,
Indent,
Dedent,
Matchable,
)
from sqlfluff.core.parser.segments.base import BracketedSegment

from sqlfluff.core.dialects import load_raw_dialect

Expand Down Expand Up @@ -123,6 +125,18 @@
type="literal",
trim_chars=("@",),
),
# Add a Full equivalent which also allow keywords
NakedIdentifierSegmentFull=RegexParser(
r"[A-Z0-9_]*[A-Z][A-Z0-9_]*",
CodeSegment,
name="naked_identifier_all",
type="identifier",
),
SingleIdentifierGrammarFull=OneOf(
Ref("NakedIdentifierSegment"),
Ref("QuotedIdentifierSegment"),
Ref("NakedIdentifierSegmentFull"),
),
)


Expand Down Expand Up @@ -633,9 +647,47 @@ class LiteralCoercionSegment(BaseSegment):

@bigquery_dialect.segment(replace=True)
class ColumnReferenceSegment(ObjectReferenceSegment): # type: ignore
"""A reference to column, field or alias."""
"""A reference to column, field or alias.
We override this for BigQuery to allow keywords in structures
(using Full segments) and to properly return references for objects.
Ref: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical
"A reserved keyword must be a quoted identifier if it is a standalone
keyword or the first component of a path expression. It may be unquoted
as the second or later component of a path expression."
"""

type = "column_reference"
match_grammar: Matchable = Sequence(
Ref("SingleIdentifierGrammar"),
Sequence(
OneOf(Ref("DotSegment"), Sequence(Ref("DotSegment"), Ref("DotSegment"))),
Delimited(
Ref("SingleIdentifierGrammarFull"),
delimiter=OneOf(
Ref("DotSegment"), Sequence(Ref("DotSegment"), Ref("DotSegment"))
),
terminator=OneOf(
"ON",
"AS",
"USING",
Ref("CommaSegment"),
Ref("CastOperatorSegment"),
Ref("StartSquareBracketSegment"),
Ref("StartBracketSegment"),
Ref("BinaryOperatorGrammar"),
Ref("ColonSegment"),
Ref("DelimiterSegment"),
BracketedSegment,
),
allow_gaps=False,
),
allow_gaps=False,
optional=True,
),
allow_gaps=False,
)

def extract_possible_references(self, level):
"""Extract possible references of a given level."""
Expand Down
@@ -0,0 +1,7 @@
-- current is a reserved word but keywords are allowed as part of a nested object name
SELECT
table1.current.column,
table1.object.current.column,
table1.object.nested.current.column,
FROM
table1
@@ -0,0 +1,48 @@
# 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: e9b7b38575826b8cc463734bcc7647038a51e5b8342f3c2dd6624b233bae30d8
file:
statement:
select_statement:
select_clause:
- keyword: SELECT
- select_clause_element:
column_reference:
- identifier: table1
- dot: .
- identifier: current
- dot: .
- identifier: column
- comma: ','
- select_clause_element:
column_reference:
- identifier: table1
- dot: .
- identifier: object
- dot: .
- identifier: current
- dot: .
- identifier: column
- comma: ','
- select_clause_element:
column_reference:
- identifier: table1
- dot: .
- identifier: object
- dot: .
- identifier: nested
- dot: .
- identifier: current
- dot: .
- identifier: column
- comma: ','
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
identifier: table1

0 comments on commit 997622b

Please sign in to comment.