|  | 
| 69 | 69 |         upper(table_schema) as table_schema, | 
| 70 | 70 |         upper(table_name) as table_name, | 
| 71 | 71 |         upper(column_name) as column_name, | 
| 72 |  | -        upper(data_type) as data_type, | 
| 73 | 72 |         ordinal_position | 
| 74 | 73 |       from {{ database }}.information_schema.columns | 
| 75 | 74 |       where upper(table_schema) in ({{ quoted_schema_names | join(', ') }}) | 
|  | 
| 82 | 81 |       {%- set schemas_list = database_columns_result.columns[1].values() -%} | 
| 83 | 82 |       {%- set table_names_list = database_columns_result.columns[2].values() -%} | 
| 84 | 83 |       {%- set column_names_list = database_columns_result.columns[3].values() -%} | 
| 85 |  | -      {%- set data_types_list = database_columns_result.columns[4].values() -%} | 
| 86 | 84 | 
 | 
| 87 | 85 |       {%- for i in range(table_names_list | length) -%} | 
| 88 | 86 |         {%- do all_columns_data.append({ | 
| 89 | 87 |           'database': databases_list[i], | 
| 90 | 88 |           'schema': schemas_list[i], | 
| 91 | 89 |           '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] | 
| 94 | 91 |         }) -%} | 
| 95 | 92 |       {%- endfor -%} | 
| 96 | 93 |     {%- endif -%} | 
|  | 
| 101 | 98 |   {%- for row in all_columns_data -%} | 
| 102 | 99 |     {%- set table_key = row.table_name -%} | 
| 103 | 100 |     {%- 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': []}}) -%} | 
| 105 | 102 |     {%- endif -%} | 
| 106 | 103 |     {%- 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}) -%} | 
| 108 | 104 |   {%- endfor -%} | 
| 109 | 105 | 
 | 
| 110 | 106 |   {{ return(table_columns) }} | 
|  | 
| 122 | 118 |   {%- set table_key = node.name.upper() -%} | 
| 123 | 119 |   {%- if table_key in table_columns_info -%} | 
| 124 | 120 |     {%- set actual_columns = table_columns_info[table_key]['columns'] -%} | 
| 125 |  | -    {%- set actual_data_types = table_columns_info[table_key]['data_types'] -%} | 
| 126 | 121 |   {%- else -%} | 
| 127 | 122 |     {%- set actual_columns = [] -%} | 
| 128 |  | -    {%- set actual_data_types = {} -%} | 
| 129 | 123 |   {%- endif -%} | 
| 130 | 124 | 
 | 
| 131 | 125 |   -- If no columns were found, the table doesn't exist in the database | 
|  | 
| 136 | 130 |       'table_database': node.database, | 
| 137 | 131 |       'resource_type': resource_type, | 
| 138 | 132 |       'validation_issues': ['TABLE_NOT_FOUND'], | 
| 139 |  | -      'actual_column_count': 0, | 
| 140 |  | -      'documented_column_count': 0, | 
| 141 | 133 |       'documented_but_missing_columns': [], | 
| 142 |  | -      'undocumented_columns': [], | 
| 143 |  | -      'data_type_mismatches': [] | 
|  | 134 | +      'undocumented_columns': [] | 
| 144 | 135 |     } -%} | 
| 145 | 136 |     {{ return(result) }} | 
| 146 | 137 |   {%- endif -%} | 
| 147 | 138 | 
 | 
| 148 |  | -  -- Get documented columns and data types | 
|  | 139 | +  -- Get documented columns | 
| 149 | 140 |   {%- set documented_columns = [] -%} | 
| 150 |  | -  {%- set documented_data_types = {} -%} | 
| 151 | 141 |   {%- for column_name, column_info in node.columns.items() -%} | 
| 152 | 142 |     {%- 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 -%} | 
| 156 | 143 |   {%- endfor -%} | 
| 157 | 144 | 
 | 
| 158 | 145 |   -- Find missing and undocumented columns | 
|  | 
| 170 | 157 |     {%- endif -%} | 
| 171 | 158 |   {%- endfor -%} | 
| 172 | 159 | 
 | 
| 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 |  | - | 
| 187 | 160 |   -- Determine validation issues as a list | 
| 188 | 161 |   {%- set validation_issues = [] -%} | 
| 189 | 162 | 
 | 
|  | 
| 195 | 168 |     {%- do validation_issues.append('UNDOCUMENTED_COLUMNS') -%} | 
| 196 | 169 |   {%- endif -%} | 
| 197 | 170 | 
 | 
| 198 |  | -  {%- if data_type_mismatches | length > 0 -%} | 
| 199 |  | -    {%- do validation_issues.append('DATA_TYPE_MISMATCH') -%} | 
| 200 |  | -  {%- endif -%} | 
| 201 |  | - | 
| 202 | 171 |   {%- set result = { | 
| 203 | 172 |     'table_name': node.name, | 
| 204 | 173 |     'table_schema': node.schema, | 
| 205 | 174 |     'table_database': node.database, | 
| 206 | 175 |     'resource_type': resource_type, | 
| 207 | 176 |     'validation_issues': validation_issues, | 
| 208 |  | -    'actual_column_count': actual_columns | length, | 
| 209 |  | -    'documented_column_count': documented_columns | length, | 
| 210 | 177 |     '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 | 
| 213 | 179 |   } -%} | 
| 214 | 180 | 
 | 
| 215 | 181 |   {{ return(result) }} | 
|  | 
| 242 | 208 |   {%- endif -%} | 
| 243 | 209 | 
 | 
| 244 | 210 |   -- 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'] -%} | 
| 246 | 212 |   {%- if undocumented_columns_as_errors -%} | 
| 247 | 213 |     {%- do error_issues.append('UNDOCUMENTED_COLUMNS') -%} | 
| 248 | 214 |   {%- endif -%} | 
|  | 
| 287 | 253 |     -- Log the result based on errors_only flag | 
| 288 | 254 |     {%- if result.validation_issues | length == 0 -%} | 
| 289 | 255 |       {%- 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) }} | 
| 291 | 257 |       {%- endif -%} | 
| 292 | 258 |     {%- elif 'TABLE_NOT_FOUND' in result.validation_issues -%} | 
| 293 | 259 |       {%- if resource_type == 'model' -%} | 
|  | 
| 297 | 263 |       {%- endif -%} | 
| 298 | 264 |     {%- elif result.validation_issues == ['UNDOCUMENTED_COLUMNS'] and not undocumented_columns_as_errors -%} | 
| 299 | 265 |       {%- 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) }} | 
| 301 | 267 |         {{ log('   ⚠️  Undocumented columns (not treated as errors): ' ~ result.undocumented_columns | join(', '), info=True) }} | 
| 302 | 268 |       {%- endif -%} | 
| 303 | 269 |     {%- else -%} | 
|  | 
| 312 | 278 |           {{ log('   ⚠️  Undocumented columns (not treated as errors): ' ~ result.undocumented_columns | join(', '), info=True) }} | 
| 313 | 279 |         {%- endif -%} | 
| 314 | 280 |       {%- 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 -%} | 
| 321 | 281 |     {%- endif -%} | 
| 322 | 282 |   {%- endfor -%} | 
| 323 | 283 | 
 | 
|  | 
0 commit comments