Skip to content

Commit

Permalink
Merge branch 'bhart-issue_1437_robust_jinja_raw_templated_slice_mappi…
Browse files Browse the repository at this point in the history
…ng' of https://github.com/barrywhart/sqlfluff into bhart-issue_1437_robust_jinja_raw_templated_slice_mapping
  • Loading branch information
Barry Hart committed Oct 15, 2021
2 parents 72917dd + c353999 commit d1cd2bc
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 9 deletions.
110 changes: 105 additions & 5 deletions src/sqlfluff/dialects/dialect_tsql.py
Expand Up @@ -359,15 +359,115 @@ class ObjectReferenceSegment(BaseSegment):
"""

type = "object_reference"
# match grammar (don't allow whitespace)
match_grammar: Matchable = Delimited(
# match grammar (allow whitespace)
match_grammar: Matchable = Sequence(
Ref("SingleIdentifierGrammar"),
delimiter=OneOf(
Ref("DotSegment"), Sequence(Ref("DotSegment"), Ref("DotSegment"))
AnyNumberOf(
Sequence(
Ref("DotSegment"),
Ref("SingleIdentifierGrammar", optional=True),
),
min_times=0,
max_times=3,
),
allow_gaps=False,
)

ObjectReferencePart = ansi_dialect.get_segment(
"ObjectReferenceSegment"
).ObjectReferencePart

_iter_reference_parts = ansi_dialect.get_segment(
"ObjectReferenceSegment"
)._iter_reference_parts

iter_raw_references = ansi_dialect.get_segment(
"ObjectReferenceSegment"
).iter_raw_references

is_qualified = ansi_dialect.get_segment("ObjectReferenceSegment").is_qualified

qualification = ansi_dialect.get_segment("ObjectReferenceSegment").qualification

ObjectReferenceLevel = ansi_dialect.get_segment(
"ObjectReferenceSegment"
).ObjectReferenceLevel

extract_possible_references = ansi_dialect.get_segment(
"ObjectReferenceSegment"
).extract_possible_references

_level_to_int = ansi_dialect.get_segment("ObjectReferenceSegment")._level_to_int


@tsql_dialect.segment(replace=True)
class TableReferenceSegment(ObjectReferenceSegment):
"""A reference to an table, CTE, subquery or alias.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "table_reference"


@tsql_dialect.segment(replace=True)
class SchemaReferenceSegment(ObjectReferenceSegment):
"""A reference to a schema.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "schema_reference"


@tsql_dialect.segment(replace=True)
class DatabaseReferenceSegment(ObjectReferenceSegment):
"""A reference to a database.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "database_reference"


@tsql_dialect.segment(replace=True)
class IndexReferenceSegment(ObjectReferenceSegment):
"""A reference to an index.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "index_reference"


@tsql_dialect.segment(replace=True)
class ExtensionReferenceSegment(ObjectReferenceSegment):
"""A reference to an extension.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "extension_reference"


@tsql_dialect.segment(replace=True)
class ColumnReferenceSegment(ObjectReferenceSegment):
"""A reference to column, field or alias.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "column_reference"


@tsql_dialect.segment(replace=True)
class SequenceReferenceSegment(ObjectReferenceSegment):
"""A reference to a sequence.
Overriding to capture TSQL's override of ObjectReferenceSegment
"""

type = "sequence_reference"


@tsql_dialect.segment()
class PivotColumnReferenceSegment(ObjectReferenceSegment):
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/dialects/tsql/select.sql
Expand Up @@ -10,4 +10,7 @@ SELECT
WHEN 1 != 1 THEN 'False'
WHEN 1 !> 1 THEN 'NULL Handling, Probably'
ELSE 'Silly Tests'
END
END,
all_pop. [Arrival Date]
FROM dbo . all_pop

21 changes: 18 additions & 3 deletions test/fixtures/dialects/tsql/select.yml
Expand Up @@ -3,14 +3,14 @@
# 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: 7a3d7a550f46510b3607368ba5d59bd5cbbbc183c7e48dcf23d6761ee6e39161
_hash: a9ba36322c00ee61edc62ebab4df214cb3111c2f60c07d8b417eba0c9ea9d65b
file:
batch:
statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
- keyword: SELECT
- select_clause_element:
expression:
case_expression:
- keyword: CASE
Expand Down Expand Up @@ -90,3 +90,18 @@ file:
- expression:
literal: "'Silly Tests'"
- keyword: END
- comma: ','
- select_clause_element:
column_reference:
- identifier: all_pop
- dot: .
- identifier: '[Arrival Date]'
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
- identifier: dbo
- dot: .
- identifier: all_pop

0 comments on commit d1cd2bc

Please sign in to comment.