From 19fca6d0f1b1255cdc89c6d2bf62429145fabb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20=C5=A0imkus?= Date: Fri, 3 May 2024 11:05:08 +0300 Subject: [PATCH] Detect hyphen in hard coded reference --- .../models/marts/fct_model_6.sql | 6 +++- .../dag/test_fct_hard_coded_references.csv | 2 +- macros/find_all_hard_coded_references.sql | 34 +++++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/integration_tests/models/marts/fct_model_6.sql b/integration_tests/models/marts/fct_model_6.sql index 65a0f368..e57e48af 100644 --- a/integration_tests/models/marts/fct_model_6.sql +++ b/integration_tests/models/marts/fct_model_6.sql @@ -65,7 +65,11 @@ select 1 as id union all select 4 as id - from 'raw_relation_4' + from 'raw_relation_4' + union all + select + 4 as id + from `project-name.dataset_name.table_name` union all select 4 as id diff --git a/integration_tests/seeds/dag/test_fct_hard_coded_references.csv b/integration_tests/seeds/dag/test_fct_hard_coded_references.csv index 9393447a..345266e1 100644 --- a/integration_tests/seeds/dag/test_fct_hard_coded_references.csv +++ b/integration_tests/seeds/dag/test_fct_hard_coded_references.csv @@ -1,2 +1,2 @@ model,hard_coded_references -fct_model_6,"""my_db"".""my_schema"".""my_table"", ""my_schema"".""raw_relation_5"", ""raw_relation_2"", 'my_db'.'my_schema'.'my_table', 'my_schema'.'raw_relation_5', 'raw_relation_4', [my_db].[my_schema].[my_table], [my_schema].[raw_relation_5], [raw_relation_3], `my_db`.`my_schema`.`my_table`, `my_schema`.`raw_relation_5`, `raw_relation_1`, my_db.my_schema.my_table, my_schema.raw_relation_5, {{ var(""my_table_reference"") }}, {{ var(""my_table_reference"", ""table_d"") }}, {{ var('my_table_reference') }}, {{ var('my_table_reference', 'table_d') }}" \ No newline at end of file +fct_model_6,"""my_db"".""my_schema"".""my_table"", ""my_schema"".""raw_relation_5"", ""raw_relation_2"", 'my_db'.'my_schema'.'my_table', 'my_schema'.'raw_relation_5', 'raw_relation_4', [my_db].[my_schema].[my_table], [my_schema].[raw_relation_5], [raw_relation_3], `my_db`.`my_schema`.`my_table`, `my_schema`.`raw_relation_5`, `project-name.dataset_name.table_name`, `raw_relation_1`, my_db.my_schema.my_table, my_schema.raw_relation_5, {{ var(""my_table_reference"") }}, {{ var(""my_table_reference"", ""table_d"") }}, {{ var('my_table_reference') }}, {{ var('my_table_reference', 'table_d') }}" \ No newline at end of file diff --git a/macros/find_all_hard_coded_references.sql b/macros/find_all_hard_coded_references.sql index e22080eb..18b5f512 100644 --- a/macros/find_all_hard_coded_references.sql +++ b/macros/find_all_hard_coded_references.sql @@ -134,7 +134,7 @@ # third matching group # at least 1 word character - (\w+) + (\w+-?\w+) # fouth matching group # 1 or 0 of (closing bracket, backtick, or quotation mark) @@ -150,7 +150,7 @@ # seventh matching group # at least 1 word character - (\w+) + (\w+-?\w+) # eighth matching group # 1 or 0 of (closing bracket, backtick, or quotation mark) folowed by a whitespace character or end of string @@ -164,23 +164,23 @@ (?