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

Commit 4cdf389

Browse files
committed
Add a test
1 parent 27ff7ca commit 4cdf389

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/test_diff_tables.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,65 @@ def test_uuid_columns_with_nulls(self):
409409
self.assertEqual(diff, [("-", (str(self.null_uuid), None))])
410410

411411

412+
class TestConcatMultipleColumnWithNulls(TestWithConnection):
413+
def setUp(self):
414+
super().setUp()
415+
416+
queries = [
417+
f"DROP TABLE IF EXISTS {self.table_src}",
418+
f"DROP TABLE IF EXISTS {self.table_dst}",
419+
f"CREATE TABLE {self.table_src}(id varchar(100), c1 varchar(100), c2 varchar(100))",
420+
f"CREATE TABLE {self.table_dst}(id varchar(100), c1 varchar(100), c2 varchar(100))",
421+
]
422+
423+
self.diffs = []
424+
for i in range(0, 8):
425+
pk = uuid.uuid1(i)
426+
table_src_c1_val = str(i)
427+
table_dst_c1_val = str(i) + "-different"
428+
429+
queries.append(f"INSERT INTO {self.table_src} VALUES ('{pk}', '{table_src_c1_val}', NULL)")
430+
queries.append(f"INSERT INTO {self.table_dst} VALUES ('{pk}', '{table_dst_c1_val}', NULL)")
431+
432+
self.diffs.append(("-", (str(pk), table_src_c1_val, None)))
433+
self.diffs.append(("+", (str(pk), table_dst_c1_val, None)))
434+
435+
queries.append("COMMIT")
436+
437+
for query in queries:
438+
self.connection.query(query, None)
439+
440+
self.a = TableSegment(self.connection, (self.table_src,), "id", extra_columns=("c1", "c2"))
441+
self.b = TableSegment(self.connection, (self.table_dst,), "id", extra_columns=("c1", "c2"))
442+
443+
def test_tables_are_different(self):
444+
"""
445+
Here we test a case when in one segment one or more columns has only null values. For example,
446+
Table A:
447+
| id | c1 | c2 |
448+
|------|----|------|
449+
| pk_1 | 1 | NULL |
450+
| pk_2 | 2 | NULL |
451+
...
452+
| pk_n | n | NULL |
453+
454+
Table B:
455+
| id | c1 | c2 |
456+
|------|--------|------|
457+
| pk_1 | 1-diff | NULL |
458+
| pk_2 | 2-diff | NULL |
459+
...
460+
| pk_n | n-diff | NULL |
461+
462+
To calculate a checksum, we need to concatenate string values by rows. If both tables have columns with NULL
463+
value, it may lead that concat(pk_i, i, NULL) == concat(pk_i, i-diff, NULL). This test handle such cases.
464+
"""
465+
466+
differ = TableDiffer(bisection_factor=2, bisection_threshold=4)
467+
diff = list(differ.diff_tables(self.a, self.b))
468+
self.assertEqual(diff, self.diffs)
469+
470+
412471
class TestTableTableEmpty(TestWithConnection):
413472
def setUp(self):
414473
super().setUp()

0 commit comments

Comments
 (0)