|
11 | 11 |
|
12 | 12 | import attrs
|
13 | 13 |
|
| 14 | +from data_diff.errors import DataDiffMismatchingKeyTypesError |
14 | 15 | from data_diff.info_tree import InfoTree, SegmentInfo
|
15 | 16 | from data_diff.utils import dbt_diff_string_template, run_as_daemon, safezip, getLogger, truncate_error, Vector
|
16 | 17 | from data_diff.thread_utils import ThreadedYielder
|
@@ -285,16 +286,20 @@ def _bisect_and_diff_tables(self, table1: TableSegment, table2: TableSegment, in
|
285 | 286 | if len(table1.key_columns) != len(table2.key_columns):
|
286 | 287 | raise ValueError("Tables should have an equivalent number of key columns!")
|
287 | 288 |
|
288 |
| - key_types1 = [table1._schema[i] for i in table1.key_columns] |
289 |
| - key_types2 = [table2._schema[i] for i in table2.key_columns] |
| 289 | + key_types1 = [(i, table1._schema[i]) for i in table1.key_columns] |
| 290 | + key_types2 = [(i, table2._schema[i]) for i in table2.key_columns] |
290 | 291 |
|
291 | 292 | for kt in key_types1 + key_types2:
|
292 | 293 | if not isinstance(kt, IKey):
|
293 | 294 | raise NotImplementedError(f"Cannot use a column of type {kt} as a key")
|
294 | 295 |
|
295 |
| - for kt1, kt2 in safezip(key_types1, key_types2): |
| 296 | + for i, (kt1, kt2) in enumerate(safezip(key_types1, key_types2)): |
296 | 297 | if kt1.python_type is not kt2.python_type:
|
297 |
| - raise TypeError(f"Incompatible key types: {kt1} and {kt2}") |
| 298 | + k1 = table1.key_columns[i] |
| 299 | + k2 = table2.key_columns[i] |
| 300 | + raise DataDiffMismatchingKeyTypesError( |
| 301 | + f"Key columns {k1} and {k2} can't be compared due to different types." |
| 302 | + ) |
298 | 303 |
|
299 | 304 | # Query min/max values
|
300 | 305 | key_ranges = self._threaded_call_as_completed("query_key_range", [table1, table2])
|
|
0 commit comments