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

Commit e322806

Browse files
authored
Merge pull request #171 from datafold/separated
Now separating the columns with a '|' before concatting them
2 parents 63139a3 + be6a36d commit e322806

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

data_diff/sql.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from runtype import dataclass
88

9+
from .utils import join_iter
10+
911
from .databases.database_types import AbstractDatabase, DbPath, DbKey, DbTime, ArithUUID
1012

1113

@@ -15,6 +17,8 @@ class Sql:
1517

1618
SqlOrStr = Union[Sql, str]
1719

20+
CONCAT_SEP = "|"
21+
1822

1923
@dataclass
2024
class Compiler:
@@ -122,7 +126,8 @@ class Checksum(Sql):
122126
def compile(self, c: Compiler):
123127
if len(self.exprs) > 1:
124128
compiled_exprs = [f"coalesce({c.compile(expr)}, '<null>')" for expr in self.exprs]
125-
expr = c.database.concat(compiled_exprs)
129+
separated = list(join_iter(f"'|'", compiled_exprs))
130+
expr = c.database.concat(separated)
126131
else:
127132
# No need to coalesce - safe to assume that key cannot be null
128133
(expr,) = self.exprs

data_diff/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ def number_to_human(n):
5151
)
5252

5353
return "{:.0f}{}".format(n / 10 ** (3 * millidx), millnames[millidx])
54+
55+
56+
def join_iter(joiner: Any, iterable: iter) -> iter:
57+
it = iter(iterable)
58+
yield next(it)
59+
for i in it:
60+
yield joiner
61+
yield i

tests/test_diff_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def test_get_values(self):
254254
table = self.table.with_schema()
255255

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

260260
def test_diff_small_tables(self):

0 commit comments

Comments
 (0)