Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 2cc7f93

Browse files
authored
Merge pull request #851 from datafold/pk-mistmach-error-reporting
Improve error reporting for PK type mismatch
2 parents f8dd74c + a3410f0 commit 2cc7f93

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

data_diff/diff_tables.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import attrs
1313

14+
from data_diff.errors import DataDiffMismatchingKeyTypesError
1415
from data_diff.info_tree import InfoTree, SegmentInfo
1516
from data_diff.utils import dbt_diff_string_template, run_as_daemon, safezip, getLogger, truncate_error, Vector
1617
from data_diff.thread_utils import ThreadedYielder
@@ -292,9 +293,13 @@ def _bisect_and_diff_tables(self, table1: TableSegment, table2: TableSegment, in
292293
if not isinstance(kt, IKey):
293294
raise NotImplementedError(f"Cannot use a column of type {kt} as a key")
294295

295-
for kt1, kt2 in safezip(key_types1, key_types2):
296+
for i, (kt1, kt2) in enumerate(safezip(key_types1, key_types2)):
296297
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+
)
298303

299304
# Query min/max values
300305
key_ranges = self._threaded_call_as_completed("query_key_range", [table1, table2])

data_diff/errors.py

+4
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ class DataDiffCloudDiffTimedOut(Exception):
6868

6969
class DataDiffSimpleSelectNotFound(Exception):
7070
"Raised when using --select on dbt < 1.5 and a model node is not found in the manifest."
71+
72+
73+
class DataDiffMismatchingKeyTypesError(Exception):
74+
"Raised when the key types of two tables do not match, like VARCHAR and INT."

0 commit comments

Comments
 (0)