Skip to content

Commit

Permalink
Merge branch 'main' into issue-5687
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmcruickshank committed Mar 21, 2024
2 parents c681d00 + b2a4eab commit b715fe1
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 13 deletions.
8 changes: 0 additions & 8 deletions docs/source/partials/starter_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ project_dir = ./
# SQLFluff maintainers do use them in their projects.
allow_implicit_indents = True

# The default configuration for aliasing rules is "consistent"
# which will auto-detect the setting from the rest of the file. This
# is less desirable in a new project and you may find this (slightly
# more strict) setting more useful.
[sqlfluff:rules:aliasing.table]
aliasing = explicit
[sqlfluff:rules:aliasing.column]
aliasing = explicit
[sqlfluff:rules:aliasing.length]
min_alias_length = 3

Expand Down
2 changes: 1 addition & 1 deletion src/sqlfluff/dialects/dialect_bigquery_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
INTO
IS
JOIN
KEY
LATERAL
LEFT
LIKE
Expand Down Expand Up @@ -177,6 +176,7 @@
INOUT
INSERT
INTEGRATION
KEY
ITERATE
LANGUAGE
LARGE
Expand Down
6 changes: 5 additions & 1 deletion src/sqlfluff/dialects/dialect_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,14 +1523,16 @@ class ChangesClauseSegment(BaseSegment):
"INFORMATION",
Ref("ParameterAssignerSegment"),
OneOf("DEFAULT", "APPEND_ONLY"),
parse_mode=ParseMode.GREEDY,
),
OneOf(
Sequence(
"AT",
Bracketed(
OneOf("TIMESTAMP", "OFFSET", "STATEMENT"),
OneOf("TIMESTAMP", "OFFSET", "STATEMENT", "STREAM"),
Ref("ParameterAssignerSegment"),
Ref("ExpressionSegment"),
parse_mode=ParseMode.GREEDY,
),
),
Sequence(
Expand All @@ -1539,6 +1541,7 @@ class ChangesClauseSegment(BaseSegment):
"STATEMENT",
Ref("ParameterAssignerSegment"),
Ref("ExpressionSegment"),
parse_mode=ParseMode.GREEDY,
),
),
),
Expand All @@ -1548,6 +1551,7 @@ class ChangesClauseSegment(BaseSegment):
OneOf("TIMESTAMP", "OFFSET", "STATEMENT"),
Ref("ParameterAssignerSegment"),
Ref("ExpressionSegment"),
parse_mode=ParseMode.GREEDY,
),
optional=True,
),
Expand Down
2 changes: 1 addition & 1 deletion src/sqlfluff/dialects/dialect_snowflake_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
CURRENT_USER
DELETE
DISTINCT
DO
DROP
ELSE
EXISTS
Expand Down Expand Up @@ -231,6 +230,7 @@
DISABLE_AUTO_CONVERT
DISABLE_SNOWFLAKE_DATA
DISPLAY_NAME
DO
DOMAIN
DOUBLE
DYNAMIC
Expand Down
25 changes: 25 additions & 0 deletions src/sqlfluff/dialects/dialect_trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
Anything,
BaseSegment,
Bracketed,
CodeSegment,
Delimited,
LiteralSegment,
Matchable,
Nothing,
OneOf,
Ref,
Sequence,
StringLexer,
StringParser,
SymbolSegment,
TypedParser,
)
from sqlfluff.dialects import dialect_ansi as ansi
Expand Down Expand Up @@ -43,6 +47,18 @@
"reserved_keywords", trino_reserved_keywords
)

trino_dialect.insert_lexer_matchers(
# Regexp Replace w/ Lambda: https://trino.io/docs/422/functions/regexp.html
[
StringLexer("right_arrow", "->", CodeSegment),
],
before="like_operator",
)

trino_dialect.add(
RightArrowOperator=StringParser("->", SymbolSegment, type="binary_operator"),
)

trino_dialect.replace(
DateTimeLiteralGrammar=OneOf(
Sequence(
Expand Down Expand Up @@ -170,6 +186,14 @@
Ref("EmptyStructLiteralSegment"),
Ref("ListaggOverflowClauseSegment"),
),
BinaryOperatorGrammar=OneOf(
Ref("ArithmeticBinaryOperatorGrammar"),
Ref("StringBinaryOperatorGrammar"),
Ref("BooleanBinaryOperatorGrammar"),
Ref("ComparisonOperatorGrammar"),
# Add arrow operators for functions (e.g. regexp_replace)
Ref("RightArrowOperator"),
),
)


Expand All @@ -187,6 +211,7 @@ class DatatypeSegment(BaseSegment):
"TINYINT",
"SMALLINT",
"INTEGER",
"INT",
"BIGINT",
# Floating-point
"REAL",
Expand Down
1 change: 1 addition & 0 deletions src/sqlfluff/dialects/dialect_trino_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
INCLUDING
INITIAL
INPUT
INT
INTEGER
INTERVAL
INVOKER
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dialects/bigquery/select.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT 'metadata' AS key from foo;
24 changes: 24 additions & 0 deletions test/fixtures/dialects/bigquery/select.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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: dee0a6c0271b2be54f6c70ff6062083e5b2d7842c80a81597715b6abb523d67c
file:
statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
quoted_literal: "'metadata'"
alias_expression:
keyword: AS
naked_identifier: key
from_clause:
keyword: from
from_expression:
from_expression_element:
table_expression:
table_reference:
naked_identifier: foo
statement_terminator: ;
5 changes: 5 additions & 0 deletions test/fixtures/dialects/snowflake/changes_clause.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ select *
from t1
changes(information => default)
before(statement => '8e5d0ca9-005e-44e6-b858-a8f5b37c5726');

select *
from st.test
changes (information => append_only)
at (stream => 'ppr.str_test');
36 changes: 35 additions & 1 deletion test/fixtures/dialects/snowflake/changes_clause.yml
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: 71297b1cb80e4085221b6c2dba0cd9142e4a1eaa595ecd7645fa6fb1497b717a
_hash: 18db925256de17a42d506048e40eb2ccde74ec1d0f8e209b46061019025f0a51
file:
- statement:
select_statement:
Expand Down Expand Up @@ -156,3 +156,37 @@ file:
quoted_literal: "'8e5d0ca9-005e-44e6-b858-a8f5b37c5726'"
end_bracket: )
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: select
select_clause_element:
wildcard_expression:
wildcard_identifier:
star: '*'
from_clause:
keyword: from
from_expression:
from_expression_element:
table_expression:
table_reference:
- naked_identifier: st
- dot: .
- naked_identifier: test
changes_clause:
- keyword: changes
- bracketed:
- start_bracket: (
- keyword: information
- parameter_assigner: =>
- keyword: append_only
- end_bracket: )
- keyword: at
- bracketed:
start_bracket: (
keyword: stream
parameter_assigner: =>
expression:
quoted_literal: "'ppr.str_test'"
end_bracket: )
- statement_terminator: ;
4 changes: 4 additions & 0 deletions test/fixtures/dialects/snowflake/select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ SELECT
FROM my_table cross join my_table2;

select notify from foo;

select
coalesce(do.a, do.b) as value
from delivery_override as do
37 changes: 36 additions & 1 deletion test/fixtures/dialects/snowflake/select.yml
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: 5c6e8e7c5c1a182423156293e962df7be03b68274e64cd021323910b9b14eabe
_hash: 19749d766e5fbecede87e275131bee6e9f53d82122de5863166e211745a45eb3
file:
- statement:
select_statement:
Expand Down Expand Up @@ -134,3 +134,38 @@ file:
table_reference:
naked_identifier: foo
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: select
select_clause_element:
function:
function_name:
function_name_identifier: coalesce
bracketed:
- start_bracket: (
- expression:
column_reference:
- naked_identifier: do
- dot: .
- naked_identifier: a
- comma: ','
- expression:
column_reference:
- naked_identifier: do
- dot: .
- naked_identifier: b
- end_bracket: )
alias_expression:
keyword: as
naked_identifier: value
from_clause:
keyword: from
from_expression:
from_expression_element:
table_expression:
table_reference:
naked_identifier: delivery_override
alias_expression:
keyword: as
naked_identifier: do
11 changes: 11 additions & 0 deletions test/fixtures/dialects/trino/integer_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

SELECT CAST(1 AS TINYINT);

SELECT CAST(2 AS SMALLINT);

-- Synonyms of INTEGER
-- https://trino.io/docs/422/language/types.html#integer-or-int
SELECT CAST(3 AS INTEGER);
SELECT CAST(4 AS INT);

SELECT CAST(5 AS BIGINT);
92 changes: 92 additions & 0 deletions test/fixtures/dialects/trino/integer_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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: 561864b853aec595cba18c89eef48d2a945baf87e4ad5d95213f775cc9e81428
file:
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
function:
function_name:
function_name_identifier: CAST
bracketed:
start_bracket: (
expression:
numeric_literal: '1'
keyword: AS
data_type:
keyword: TINYINT
end_bracket: )
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
function:
function_name:
function_name_identifier: CAST
bracketed:
start_bracket: (
expression:
numeric_literal: '2'
keyword: AS
data_type:
keyword: SMALLINT
end_bracket: )
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
function:
function_name:
function_name_identifier: CAST
bracketed:
start_bracket: (
expression:
numeric_literal: '3'
keyword: AS
data_type:
keyword: INTEGER
end_bracket: )
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
function:
function_name:
function_name_identifier: CAST
bracketed:
start_bracket: (
expression:
numeric_literal: '4'
keyword: AS
data_type:
keyword: INT
end_bracket: )
- statement_terminator: ;
- statement:
select_statement:
select_clause:
keyword: SELECT
select_clause_element:
function:
function_name:
function_name_identifier: CAST
bracketed:
start_bracket: (
expression:
numeric_literal: '5'
keyword: AS
data_type:
keyword: BIGINT
end_bracket: )
- statement_terminator: ;

0 comments on commit b715fe1

Please sign in to comment.