Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
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
7 changes: 6 additions & 1 deletion data_diff/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from runtype import dataclass

from .utils import join_iter

from .databases.database_types import AbstractDatabase, DbPath, DbKey, DbTime, ArithUUID


Expand All @@ -15,6 +17,8 @@ class Sql:

SqlOrStr = Union[Sql, str]

CONCAT_SEP = "|"


@dataclass
class Compiler:
Expand Down Expand Up @@ -122,7 +126,8 @@ class Checksum(Sql):
def compile(self, c: Compiler):
if len(self.exprs) > 1:
compiled_exprs = [f"coalesce({c.compile(expr)}, '<null>')" for expr in self.exprs]
expr = c.database.concat(compiled_exprs)
separated = list(join_iter(f"'|'", compiled_exprs))
expr = c.database.concat(separated)
else:
# No need to coalesce - safe to assume that key cannot be null
(expr,) = self.exprs
Expand Down
8 changes: 8 additions & 0 deletions data_diff/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ def number_to_human(n):
)

return "{:.0f}{}".format(n / 10 ** (3 * millidx), millnames[millidx])


def join_iter(joiner: Any, iterable: iter) -> iter:
it = iter(iterable)
yield next(it)
for i in it:
yield joiner
yield i
2 changes: 1 addition & 1 deletion tests/test_diff_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_get_values(self):
table = self.table.with_schema()

self.assertEqual(1, table.count())
concatted = str(id_) + time
concatted = str(id_) + "|" + time
self.assertEqual(str_to_checksum(concatted), table.count_and_checksum()[1])

def test_diff_small_tables(self):
Expand Down