|
9 | 9 | from rich.console import Console |
10 | 10 | from sqlmesh.core.console import TerminalConsole |
11 | 11 | from sqlmesh.core.context import Context |
12 | | -from sqlmesh.core.config import AutoCategorizationMode, CategorizerConfig |
| 12 | +from sqlmesh.core.config import AutoCategorizationMode, CategorizerConfig, DuckDBConnectionConfig |
13 | 13 | from sqlmesh.core.model import SqlModel, load_sql_based_model |
14 | 14 | from sqlmesh.core.table_diff import TableDiff |
15 | 15 | import numpy as np |
@@ -511,3 +511,54 @@ def test_data_diff_array_dict(sushi_context_fixed_date): |
511 | 511 | stripped_output = strip_ansi_codes(output) |
512 | 512 | stripped_expected = expected_output.strip() |
513 | 513 | assert stripped_output == stripped_expected |
| 514 | + |
| 515 | + |
| 516 | +def test_data_diff_nullable_booleans(): |
| 517 | + engine_adapter = DuckDBConnectionConfig().create_engine_adapter() |
| 518 | + |
| 519 | + columns_to_types = {"key": exp.DataType.build("int"), "value": exp.DataType.build("boolean")} |
| 520 | + |
| 521 | + engine_adapter.create_table("table_diff_source", columns_to_types) |
| 522 | + engine_adapter.create_table("table_diff_target", columns_to_types) |
| 523 | + |
| 524 | + engine_adapter.execute( |
| 525 | + "insert into table_diff_source (key, value) values (1, true), (2, false), (3, null)" |
| 526 | + ) |
| 527 | + engine_adapter.execute( |
| 528 | + "insert into table_diff_target (key, value) values (1, false), (2, null), (3, true)" |
| 529 | + ) |
| 530 | + |
| 531 | + table_diff = TableDiff( |
| 532 | + adapter=engine_adapter, |
| 533 | + source="table_diff_source", |
| 534 | + target="table_diff_target", |
| 535 | + source_alias="dev", |
| 536 | + target_alias="prod", |
| 537 | + on=["key"], |
| 538 | + ) |
| 539 | + |
| 540 | + diff = table_diff.row_diff() |
| 541 | + |
| 542 | + output = capture_console_output("show_row_diff", row_diff=diff) |
| 543 | + |
| 544 | + expected_output = """ |
| 545 | +Row Counts: |
| 546 | +└── PARTIAL MATCH: 3 rows (100.0%) |
| 547 | +
|
| 548 | +COMMON ROWS column comparison stats: |
| 549 | + pct_match |
| 550 | +value 0.0 |
| 551 | +
|
| 552 | +
|
| 553 | +COMMON ROWS sample data differences: |
| 554 | +Column: value |
| 555 | +┏━━━━━┳━━━━━━━┳━━━━━━━┓ |
| 556 | +┃ key ┃ DEV ┃ PROD ┃ |
| 557 | +┡━━━━━╇━━━━━━━╇━━━━━━━┩ |
| 558 | +│ 1 │ True │ False │ |
| 559 | +│ 2 │ False │ <NA> │ |
| 560 | +│ 3 │ <NA> │ True │ |
| 561 | +└─────┴───────┴───────┘ |
| 562 | +""" |
| 563 | + |
| 564 | + assert strip_ansi_codes(output) == expected_output.strip() |
0 commit comments