Skip to content

Commit 03ce685

Browse files
Added support for Variable Substitution for Snowflake Target_lag (#6567)
1 parent 863c53f commit 03ce685

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/sqlfluff/dialects/dialect_snowflake.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
type="copy_on_error_option",
361361
),
362362
DynamicTableLagIntervalSegment=RegexParser(
363-
r"'((DOWNSTREAM)|([1-9]\d*\s+(?:SECOND|MINUTE|HOUR|DAY)S?))'",
363+
r"DYNAMIC|'.*'",
364364
LiteralSegment,
365365
type="dynamic_table_lag_interval_segment",
366366
),

test/fixtures/dialects/snowflake/create_table.sql

+7-1
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,18 @@ WAREHOUSE = mywh
180180
AS
181181
SELECT * FROM my_table;
182182

183-
CREATE OR REPLACE DYNAMIC TABLE DT_WITH_MULTIPLE_DAYS_LAG
183+
CREATE OR REPLACE DYNAMIC TABLE my_table
184184
TARGET_LAG = '5 days'
185185
WAREHOUSE = mywh
186186
AS
187187
SELECT * FROM my_table;
188188

189+
CREATE OR REPLACE DYNAMIC TABLE my_table
190+
TARGET_LAG = '${my_time_variable}'
191+
WAREHOUSE = mywh
192+
AS
193+
SELECT * FROM my_table;
194+
189195
CREATE OR REPLACE TABLE IF NOT EXISTS EXAMPLE_TABLE_WITH_RLS (
190196
EXAMPLE VARCHAR
191197
) WITH ROW ACCESS POLICY my_db.my_schema.rls_policy ON (EXAMPLE);

test/fixtures/dialects/snowflake/create_table.yml

+36-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# computed by SQLFluff when running the tests. Please run
44
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
55
# altering SQL files.
6-
_hash: c533f7884aa98a0aa3e740d7dd0250b86ba138c752fcf90e018fb8e036e5b306
6+
_hash: dd2e987190b52eebc6a01f5f6760d192348c04857db1463679286f311412e4bf
77
file:
88
- statement:
99
create_table_statement:
@@ -1459,7 +1459,7 @@ file:
14591459
- keyword: DYNAMIC
14601460
- keyword: TABLE
14611461
- table_reference:
1462-
naked_identifier: DT_WITH_MULTIPLE_DAYS_LAG
1462+
naked_identifier: my_table
14631463
- keyword: TARGET_LAG
14641464
- comparison_operator:
14651465
raw_comparison_operator: '='
@@ -1485,6 +1485,40 @@ file:
14851485
table_reference:
14861486
naked_identifier: my_table
14871487
- statement_terminator: ;
1488+
- statement:
1489+
create_table_statement:
1490+
- keyword: CREATE
1491+
- keyword: OR
1492+
- keyword: REPLACE
1493+
- keyword: DYNAMIC
1494+
- keyword: TABLE
1495+
- table_reference:
1496+
naked_identifier: my_table
1497+
- keyword: TARGET_LAG
1498+
- comparison_operator:
1499+
raw_comparison_operator: '='
1500+
- dynamic_table_lag_interval_segment: "'${my_time_variable}'"
1501+
- keyword: WAREHOUSE
1502+
- comparison_operator:
1503+
raw_comparison_operator: '='
1504+
- object_reference:
1505+
naked_identifier: mywh
1506+
- keyword: AS
1507+
- select_statement:
1508+
select_clause:
1509+
keyword: SELECT
1510+
select_clause_element:
1511+
wildcard_expression:
1512+
wildcard_identifier:
1513+
star: '*'
1514+
from_clause:
1515+
keyword: FROM
1516+
from_expression:
1517+
from_expression_element:
1518+
table_expression:
1519+
table_reference:
1520+
naked_identifier: my_table
1521+
- statement_terminator: ;
14881522
- statement:
14891523
create_table_statement:
14901524
- keyword: CREATE

0 commit comments

Comments
 (0)