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

Improve error reporting for PK type mismatch #851

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions data_diff/diff_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import attrs

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

for kt1, kt2 in safezip(key_types1, key_types2):
for i, (kt1, kt2) in enumerate(safezip(key_types1, key_types2)):
if kt1.python_type is not kt2.python_type:
raise TypeError(f"Incompatible key types: {kt1} and {kt2}")
k1 = table1.key_columns[i]
k2 = table2.key_columns[i]
raise DataDiffMismatchingKeyTypesError(
f"Key columns {k1} and {k2} can't be compared due to different types."
)

# Query min/max values
key_ranges = self._threaded_call_as_completed("query_key_range", [table1, table2])
Expand Down
4 changes: 4 additions & 0 deletions data_diff/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ class DataDiffCloudDiffTimedOut(Exception):

class DataDiffSimpleSelectNotFound(Exception):
"Raised when using --select on dbt < 1.5 and a model node is not found in the manifest."


class DataDiffMismatchingKeyTypesError(Exception):
"Raised when the key types of two tables do not match, like VARCHAR and INT."