Skip to content

Commit

Permalink
Merge pull request #11 from RossOkuno/feature/support-double-quotation
Browse files Browse the repository at this point in the history
support double quotation in ref function
  • Loading branch information
hiracky16 authored Dec 7, 2024
2 parents 3913750 + 9972977 commit c77e819
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sqlfluff_templater_dataform/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# regex pattern for config block and js block
CONFIG_BLOCK_PATTERN = r'config\s*\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}'
JS_BLOCK_PATTERN = r'js\s*\{(?:[^{}]|\{[^{}]*\})*\}'
REF_PATTERN = r'\$\{\s*ref\(\s*\'([^\']+)\'(?:\s*,\s*\'([^\']+)\')?\s*\)\s*\}'
REF_PATTERN = r'\$\{\s*ref\(\s*[\'"]([^\'"]+)[\'"](?:\s*,\s*[\'"]([^\'"]+)[\'"])?\s*\)\s*\}'

class UsedJSBlockError(SQLFluffSkipFile):
""" This package does not support dataform js block """
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/dataform/definitions/test.sqlx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ WITH users AS (
select user_id,
name,
age
from ${ref('users')}
from ${ref("users")}
)
, user_orders AS (
select user_id, order_id, DATE(created_at) AS order_date from ${ref('user_orders')}
Expand Down
12 changes: 12 additions & 0 deletions test/templater_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ def test_replace_ref_with_bq_table_single_ref(templater):
result = templater.replace_ref_with_bq_table(input_sql)
assert result == expected_sql

def test_replace_ref_with_bq_table_single_ref_double_quotes(templater):
input_sql = 'SELECT * FROM ${ref("test")}'
expected_sql = "SELECT * FROM `my_project.my_dataset.test`"
result = templater.replace_ref_with_bq_table(input_sql)
assert result == expected_sql

def test_replace_ref_with_bq_table_with_dataset(templater):
input_sql = "SELECT * FROM ${ref('other_dataset', 'test')}"
expected_sql = "SELECT * FROM `my_project.other_dataset.test`"
result = templater.replace_ref_with_bq_table(input_sql)
assert result == expected_sql

def test_replace_ref_with_bq_table_with_dataset_double_quotes(templater):
input_sql = 'SELECT * FROM ${ref("other_dataset", "test")}'
expected_sql = "SELECT * FROM `my_project.other_dataset.test`"
result = templater.replace_ref_with_bq_table(input_sql)
assert result == expected_sql

def test_replace_ref_with_bq_table_multiple_refs(templater):
input_sql = "SELECT * FROM ${ref('test')}, ${ref('another')}"
expected_sql = "SELECT * FROM `my_project.my_dataset.test`, `my_project.my_dataset.another`"
Expand Down

0 comments on commit c77e819

Please sign in to comment.