Skip to content

Commit 3dd7193

Browse files
address comments; remove redundant condition
1 parent 330c5eb commit 3dd7193

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

sqlmesh/core/engine_adapter/base.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,11 +1758,8 @@ def remove_managed_columns(
17581758
if truncate
17591759
else existing_rows_query.where(
17601760
exp.and_(
1761-
valid_from_col <= cleanup_ts,
1762-
exp.and_(
1763-
valid_to_col.is_(exp.Null().not_()),
1764-
valid_to_col < cleanup_ts,
1765-
),
1761+
valid_to_col.is_(exp.Null().not_()),
1762+
valid_to_col < cleanup_ts,
17661763
),
17671764
),
17681765
)

sqlmesh/core/snapshot/definition.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,14 @@ def get_removal_interval(
800800
# SCD Type 2 validation that end date is the latest interval if it was provided
801801
if not is_preview and self.is_scd_type_2 and self.intervals:
802802
requested_start, requested_end = removal_interval
803-
latest_end = max(interval[1] for interval in self.intervals)
804-
if requested_end != latest_end:
803+
latest_end = self.intervals[-1][1]
804+
if requested_end < latest_end:
805805
from sqlmesh.core.console import get_console
806806

807807
get_console().log_warning(
808808
f"SCD Type 2 model '{self.model.name}' does not support end date in restatements.\n"
809-
f"Requested end date [{to_ts(requested_end)}] doesn't match latest interval end date [{to_ts(latest_end)}].\n"
809+
f"Requested end date [{to_ts(requested_end)}] is less than the latest interval end date.\n"
810+
f"The requested end date will be ignored. Using the latest interval end instead: [{to_ts(latest_end)}]"
810811
)
811812

812813
removal_interval = self.inclusive_exclusive(requested_start, latest_end, strict)

tests/core/engine_adapter/test_base.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,7 @@ def test_scd_type_2_by_time(make_mocked_engine_adapter: t.Callable):
12551255
"test_valid_to",
12561256
TRUE AS "_exists"
12571257
FROM "target"
1258-
WHERE "test_valid_from" <= CAST('2020-01-01 00:00:00' AS TIMESTAMP)
1259-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP))
1258+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP)
12601259
), "latest" AS (
12611260
SELECT
12621261
"id",
@@ -1455,8 +1454,7 @@ def test_scd_type_2_by_time_no_invalidate_hard_deletes(make_mocked_engine_adapte
14551454
"test_valid_to",
14561455
TRUE AS "_exists"
14571456
FROM "target"
1458-
WHERE "test_valid_from" <= CAST('2020-01-01 00:00:00' AS TIMESTAMP)
1459-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP))
1457+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP)
14601458
), "latest" AS (
14611459
SELECT
14621460
"id",
@@ -1651,8 +1649,7 @@ def test_merge_scd_type_2_pandas(make_mocked_engine_adapter: t.Callable):
16511649
"test_valid_to",
16521650
TRUE AS "_exists"
16531651
FROM "target"
1654-
WHERE "test_valid_from" <= CAST('2020-01-01 00:00:00+00:00' AS TIMESTAMPTZ)
1655-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00+00:00' AS TIMESTAMPTZ))
1652+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00+00:00' AS TIMESTAMPTZ)
16561653
), "latest" AS (
16571654
SELECT
16581655
"id1",
@@ -1831,8 +1828,7 @@ def test_scd_type_2_by_column(make_mocked_engine_adapter: t.Callable):
18311828
"test_valid_to",
18321829
TRUE AS "_exists"
18331830
FROM "target"
1834-
WHERE "test_VALID_from" <= CAST('2020-01-01 00:00:00' AS TIMESTAMP)
1835-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP))
1831+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP)
18361832
), "latest" AS (
18371833
SELECT
18381834
"id",
@@ -2025,8 +2021,7 @@ def test_scd_type_2_by_column_composite_key(make_mocked_engine_adapter: t.Callab
20252021
"test_valid_to",
20262022
TRUE AS "_exists"
20272023
FROM "target"
2028-
WHERE "test_VALID_from" <= CAST('2020-01-01 00:00:00' AS TIMESTAMP)
2029-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP))
2024+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP)
20302025
), "latest" AS (
20312026
SELECT
20322027
"id_a",
@@ -2386,8 +2381,7 @@ def test_scd_type_2_by_column_star_check(make_mocked_engine_adapter: t.Callable)
23862381
"test_valid_to",
23872382
TRUE AS "_exists"
23882383
FROM "target"
2389-
WHERE "test_valid_from" <= CAST('2020-01-01 00:00:00' AS TIMESTAMP)
2390-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP))
2384+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP)
23912385
), "latest" AS (
23922386
SELECT
23932387
"id",
@@ -2562,8 +2556,7 @@ def test_scd_type_2_by_column_no_invalidate_hard_deletes(make_mocked_engine_adap
25622556
"test_valid_to",
25632557
TRUE AS "_exists"
25642558
FROM "target"
2565-
WHERE "test_valid_from" <= CAST('2020-01-01 00:00:00' AS TIMESTAMP)
2566-
AND (NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP))
2559+
WHERE NOT "test_valid_to" IS NULL AND "test_valid_to" < CAST('2020-01-01 00:00:00' AS TIMESTAMP)
25672560
), "latest" AS (
25682561
SELECT
25692562
"id",

0 commit comments

Comments
 (0)