Skip to content

Commit bca4958

Browse files
committed
Remove data type validation, it's too tricky to get right with all of
the possible type aliases at this stage.
1 parent 4044925 commit bca4958

File tree

1 file changed

+8
-48
lines changed

1 file changed

+8
-48
lines changed

transform/macros/validate_all_schemas.sql

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
upper(table_schema) as table_schema,
7070
upper(table_name) as table_name,
7171
upper(column_name) as column_name,
72-
upper(data_type) as data_type,
7372
ordinal_position
7473
from {{ database }}.information_schema.columns
7574
where upper(table_schema) in ({{ quoted_schema_names | join(', ') }})
@@ -82,15 +81,13 @@
8281
{%- set schemas_list = database_columns_result.columns[1].values() -%}
8382
{%- set table_names_list = database_columns_result.columns[2].values() -%}
8483
{%- set column_names_list = database_columns_result.columns[3].values() -%}
85-
{%- set data_types_list = database_columns_result.columns[4].values() -%}
8684

8785
{%- for i in range(table_names_list | length) -%}
8886
{%- do all_columns_data.append({
8987
'database': databases_list[i],
9088
'schema': schemas_list[i],
9189
'table_name': table_names_list[i],
92-
'column_name': column_names_list[i],
93-
'data_type': data_types_list[i]
90+
'column_name': column_names_list[i]
9491
}) -%}
9592
{%- endfor -%}
9693
{%- endif -%}
@@ -101,10 +98,9 @@
10198
{%- for row in all_columns_data -%}
10299
{%- set table_key = row.table_name -%}
103100
{%- if table_key not in table_columns -%}
104-
{%- do table_columns.update({table_key: {'columns': [], 'data_types': {}}}) -%}
101+
{%- do table_columns.update({table_key: {'columns': []}}) -%}
105102
{%- endif -%}
106103
{%- do table_columns[table_key]['columns'].append(row.column_name) -%}
107-
{%- do table_columns[table_key]['data_types'].update({row.column_name: row.data_type}) -%}
108104
{%- endfor -%}
109105

110106
{{ return(table_columns) }}
@@ -122,10 +118,8 @@
122118
{%- set table_key = node.name.upper() -%}
123119
{%- if table_key in table_columns_info -%}
124120
{%- set actual_columns = table_columns_info[table_key]['columns'] -%}
125-
{%- set actual_data_types = table_columns_info[table_key]['data_types'] -%}
126121
{%- else -%}
127122
{%- set actual_columns = [] -%}
128-
{%- set actual_data_types = {} -%}
129123
{%- endif -%}
130124

131125
-- If no columns were found, the table doesn't exist in the database
@@ -136,23 +130,16 @@
136130
'table_database': node.database,
137131
'resource_type': resource_type,
138132
'validation_issues': ['TABLE_NOT_FOUND'],
139-
'actual_column_count': 0,
140-
'documented_column_count': 0,
141133
'documented_but_missing_columns': [],
142-
'undocumented_columns': [],
143-
'data_type_mismatches': []
134+
'undocumented_columns': []
144135
} -%}
145136
{{ return(result) }}
146137
{%- endif -%}
147138

148-
-- Get documented columns and data types
139+
-- Get documented columns
149140
{%- set documented_columns = [] -%}
150-
{%- set documented_data_types = {} -%}
151141
{%- for column_name, column_info in node.columns.items() -%}
152142
{%- do documented_columns.append(column_name.upper()) -%}
153-
{%- if column_info.data_type -%}
154-
{%- do documented_data_types.update({column_name.upper(): column_info.data_type.upper()}) -%}
155-
{%- endif -%}
156143
{%- endfor -%}
157144

158145
-- Find missing and undocumented columns
@@ -170,20 +157,6 @@
170157
{%- endif -%}
171158
{%- endfor -%}
172159

173-
-- Check data type mismatches (if data types are documented)
174-
{%- set data_type_mismatches = [] -%}
175-
{%- if documented_data_types | length > 0 -%}
176-
{%- for col_name in actual_columns -%}
177-
{%- if col_name in documented_data_types -%}
178-
{%- set actual_type = actual_data_types[col_name] -%}
179-
{%- set expected_type = documented_data_types[col_name] -%}
180-
{%- if actual_type != expected_type -%}
181-
{%- do data_type_mismatches.append(col_name ~ ' (expected: ' ~ expected_type ~ ', actual: ' ~ actual_type ~ ')') -%}
182-
{%- endif -%}
183-
{%- endif -%}
184-
{%- endfor -%}
185-
{%- endif -%}
186-
187160
-- Determine validation issues as a list
188161
{%- set validation_issues = [] -%}
189162

@@ -195,21 +168,14 @@
195168
{%- do validation_issues.append('UNDOCUMENTED_COLUMNS') -%}
196169
{%- endif -%}
197170

198-
{%- if data_type_mismatches | length > 0 -%}
199-
{%- do validation_issues.append('DATA_TYPE_MISMATCH') -%}
200-
{%- endif -%}
201-
202171
{%- set result = {
203172
'table_name': node.name,
204173
'table_schema': node.schema,
205174
'table_database': node.database,
206175
'resource_type': resource_type,
207176
'validation_issues': validation_issues,
208-
'actual_column_count': actual_columns | length,
209-
'documented_column_count': documented_columns | length,
210177
'documented_but_missing_columns': documented_but_missing_columns,
211-
'undocumented_columns': undocumented_columns,
212-
'data_type_mismatches': data_type_mismatches
178+
'undocumented_columns': undocumented_columns
213179
} -%}
214180

215181
{{ return(result) }}
@@ -242,7 +208,7 @@
242208
{%- endif -%}
243209

244210
-- Define error issues based on the flag once at the top
245-
{%- set error_issues = ['DOCUMENTED_BUT_MISSING_COLUMNS', 'DATA_TYPE_MISMATCH', 'TABLE_NOT_FOUND'] -%}
211+
{%- set error_issues = ['DOCUMENTED_BUT_MISSING_COLUMNS', 'TABLE_NOT_FOUND'] -%}
246212
{%- if undocumented_columns_as_errors -%}
247213
{%- do error_issues.append('UNDOCUMENTED_COLUMNS') -%}
248214
{%- endif -%}
@@ -287,7 +253,7 @@
287253
-- Log the result based on errors_only flag
288254
{%- if result.validation_issues | length == 0 -%}
289255
{%- if not errors_only -%}
290-
{{ log('' ~ resource_type | title ~ ' ' ~ result.table_name ~ ': Schema matches documentation (' ~ result.actual_column_count ~ ' columns)', info=True) }}
256+
{{ log('' ~ resource_type | title ~ ' ' ~ result.table_name ~ ': Schema matches documentation', info=True) }}
291257
{%- endif -%}
292258
{%- elif 'TABLE_NOT_FOUND' in result.validation_issues -%}
293259
{%- if resource_type == 'model' -%}
@@ -297,7 +263,7 @@
297263
{%- endif -%}
298264
{%- elif result.validation_issues == ['UNDOCUMENTED_COLUMNS'] and not undocumented_columns_as_errors -%}
299265
{%- if not errors_only -%}
300-
{{ log('' ~ resource_type | title ~ ' ' ~ result.table_name ~ ': Schema matches documentation (' ~ result.actual_column_count ~ ' columns)', info=True) }}
266+
{{ log('' ~ resource_type | title ~ ' ' ~ result.table_name ~ ': Schema matches documentation', info=True) }}
301267
{{ log(' ⚠️ Undocumented columns (not treated as errors): ' ~ result.undocumented_columns | join(', '), info=True) }}
302268
{%- endif -%}
303269
{%- else -%}
@@ -312,12 +278,6 @@
312278
{{ log(' ⚠️ Undocumented columns (not treated as errors): ' ~ result.undocumented_columns | join(', '), info=True) }}
313279
{%- endif -%}
314280
{%- endif -%}
315-
{%- if 'DATA_TYPE_MISMATCH' in result.validation_issues -%}
316-
{{ log(' • Data type mismatches:', info=True) }}
317-
{%- for mismatch in result.data_type_mismatches -%}
318-
{{ log(' - ' ~ mismatch, info=True) }}
319-
{%- endfor -%}
320-
{%- endif -%}
321281
{%- endif -%}
322282
{%- endfor -%}
323283

0 commit comments

Comments
 (0)