Skip to content

Commit b5af463

Browse files
committed
fix(test-validation): handle commas in column names
1 parent d4076a1 commit b5af463

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

testgen/template/dbsetup_test_types/test_types_Incr_Avg_Shift.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test_types:
5656
test_type: Incr_Avg_Shift
5757
sql_flavor: mssql
5858
measure: |-
59-
COALESCE(ABS( ({BASELINE_AVG} - (SUM(CAST("{COLUMN_NAME}" AS FLOAT)) - {BASELINE_SUM}) / NULLIF(CAST(COUNT({COLUMN_NAME}) AS FLOAT) - {BASELINE_VALUE_CT}, 0)) / {BASELINE_SD} ), 0)
59+
COALESCE(ABS( ({BASELINE_AVG} - (SUM(CAST({COLUMN_NAME} AS FLOAT)) - {BASELINE_SUM}) / NULLIF(CAST(COUNT({COLUMN_NAME}) AS FLOAT) - {BASELINE_VALUE_CT}, 0)) / {BASELINE_SD} ), 0)
6060
test_operator: '>='
6161
test_condition: |-
6262
{THRESHOLD_VALUE}

testgen/template/validate_tests/ex_get_test_column_list_tg.sql

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
SELECT cat_test_id,
1818
schema_name AS schema_name,
1919
table_name AS table_name,
20-
TRIM(TRIM(UNNEST(STRING_TO_ARRAY(column_name, ','))), '{QUOTE}') as column_name
20+
TRIM(TRIM(UNNEST(ARRAY_REMOVE(
21+
REGEXP_SPLIT_TO_ARRAY(column_name, ',(?=(?:[^"]*"[^"]*")*[^"]*$)'),
22+
'' )), ' '), '{QUOTE}') as column_name
2123
FROM test_definitions d
2224
INNER JOIN test_types t
2325
ON d.test_type = t.test_type
@@ -30,7 +32,9 @@
3032
SELECT cat_test_id,
3133
schema_name AS schema_name,
3234
table_name AS table_name,
33-
TRIM(TRIM(UNNEST(STRING_TO_ARRAY(groupby_names, ','))), '{QUOTE}') as column_name
35+
TRIM(TRIM(UNNEST(ARRAY_REMOVE(
36+
REGEXP_SPLIT_TO_ARRAY(groupby_names, ',(?=(?:[^"]*"[^"]*")*[^"]*$)'),
37+
'' )), ' '), '{QUOTE}') AS column_name
3438
FROM test_definitions d
3539
INNER JOIN test_types t
3640
ON d.test_type = t.test_type
@@ -42,7 +46,9 @@
4246
SELECT cat_test_id,
4347
schema_name AS schema_name,
4448
table_name AS table_name,
45-
TRIM(TRIM(UNNEST(STRING_TO_ARRAY(window_date_column, ','))), '{QUOTE}') as column_name
49+
TRIM(TRIM(UNNEST(ARRAY_REMOVE(
50+
REGEXP_SPLIT_TO_ARRAY(window_date_column, ',(?=(?:[^"]*"[^"]*")*[^"]*$)'),
51+
'' )), ' '), '{QUOTE}') as column_name
4652
FROM test_definitions d
4753
INNER JOIN test_types t
4854
ON d.test_type = t.test_type
@@ -54,7 +60,9 @@
5460
SELECT cat_test_id,
5561
match_schema_name AS schema_name,
5662
match_table_name AS table_name,
57-
TRIM(TRIM(UNNEST(STRING_TO_ARRAY(match_column_names, ','))), '{QUOTE}') as column_name
63+
TRIM(TRIM(UNNEST(ARRAY_REMOVE(
64+
REGEXP_SPLIT_TO_ARRAY(match_column_names, ',(?=(?:[^"]*"[^"]*")*[^"]*$)'),
65+
'' )), ' '), '{QUOTE}') as column_name
5866
FROM test_definitions d
5967
INNER JOIN test_types t
6068
ON d.test_type = t.test_type
@@ -67,7 +75,9 @@
6775
SELECT cat_test_id,
6876
match_schema_name AS schema_name,
6977
match_table_name AS table_name,
70-
TRIM(TRIM(UNNEST(STRING_TO_ARRAY(match_groupby_names, ','))), '{QUOTE}') as column_name
78+
TRIM(TRIM(UNNEST(ARRAY_REMOVE(
79+
REGEXP_SPLIT_TO_ARRAY(match_groupby_names, ',(?=(?:[^"]*"[^"]*")*[^"]*$)'),
80+
'' )), ' '), '{QUOTE}') as column_name
7181
FROM test_definitions d
7282
INNER JOIN test_types t
7383
ON d.test_type = t.test_type

0 commit comments

Comments
 (0)