Skip to content

Commit a92786d

Browse files
committed
fix(doris): preserve NULL rows on non-aligned DATE_TRUNC NEQ and NOT IN rewrites
Signed-off-by: Bruce Arctor <5032356+brucearctor@users.noreply.github.com>
1 parent f7c91e5 commit a92786d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎sqlmesh/core/engine_adapter/doris.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,9 @@ def _rewrite_direct_time_transforms_in_where(self, where: exp.Expr) -> exp.Expr:
25932593
copy=False,
25942594
)
25952595
else:
2596-
replacement = exp.true()
2596+
replacement = exp.not_(
2597+
exp.Is(this=col_expr.copy(), expression=exp.Null())
2598+
)
25972599
elif effective_op is exp.GTE:
25982600
bound_lit = low_lit if is_aligned else high_lit
25992601
replacement = exp.GTE(this=col_expr.copy(), expression=bound_lit.copy())
@@ -2639,7 +2641,9 @@ def _rewrite_direct_time_transforms_in_where(self, where: exp.Expr) -> exp.Expr:
26392641
]
26402642
if parent_not is not None:
26412643
if not aligned_ranges:
2642-
replacement_in: exp.Expr = exp.true()
2644+
replacement_in: exp.Expr = exp.not_(
2645+
exp.Is(this=col_expr.copy(), expression=exp.Null())
2646+
)
26432647
else:
26442648
not_in_parts: t.List[exp.Expr] = [
26452649
exp.Paren(

‎tests/core/engine_adapter/test_doris.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4731,7 +4731,7 @@ def test_doris_not_pushdown_week_quarter_and_candidate_extraction(
47314731
"DELETE FROM `db`.`t` WHERE `ds` >= '2024-01-15' AND `ds` < '2024-01-22' AND `ts` >= '2024-04-01' AND `ts` < '2024-07-01' AND NOT `ds` IS NULL",
47324732
"DELETE FROM `db`.`t` WHERE `ds` >= '2024-01-15' AND `ds` < '2024-01-22'",
47334733
"DELETE FROM `db`.`t` WHERE `ds` >= '2024-01-22' AND `ds` < '2024-01-29'",
4734-
"DELETE FROM `db`.`t` WHERE `a` = 1",
4734+
"DELETE FROM `db`.`t` WHERE NOT `ds` IS NULL AND `a` = 1",
47354735
]
47364736

47374737
# 2. Candidate loops in `_extract_or_key_rows_from_where` and `_extract_subquery_from_where`

0 commit comments

Comments
 (0)