Skip to content

Commit 23db0bf

Browse files
haritamarclaude
andcommitted
Fix ClickHouse freshness SLA: rename string-cast alias to avoid shadowing
ClickHouse resolves column references against output aliases regardless of SELECT clause order. The cast(sla_deadline_utc as string) with the same alias name caused the is_failure comparison to use the string version instead of the timestamp, producing DateTime vs String type mismatch. Renamed to sla_deadline_utc_str internally and re-aliased in the final SELECT. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 33d17f7 commit 23db0bf

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

macros/edr/tests/test_data_freshness_sla.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,20 @@
281281
cast(
282282
max_timestamp as {{ elementary.edr_type_string() }}
283283
) as max_timestamp,
284-
{# Compute is_failure before casting sla_deadline_utc to string,
285-
so the comparison uses the original timestamp type. #}
286284
{{
287285
elementary.edr_condition_as_boolean(
288286
"freshness_status != 'DATA_FRESH' and "
289287
~ elementary.edr_current_timestamp_in_utc()
290288
~ " > sla_deadline_utc"
291289
)
292290
}} as is_failure,
291+
{# Use a different alias to avoid shadowing the input column.
292+
ClickHouse resolves column refs against output aliases, so
293+
keeping the same name would make is_failure compare against
294+
the string-cast version, causing a type mismatch. #}
293295
cast(
294296
sla_deadline_utc as {{ elementary.edr_type_string() }}
295-
) as sla_deadline_utc,
297+
) as sla_deadline_utc_str,
296298
{# BigQuery does not support '' to escape single quotes inside string literals.
297299
Use \' for BigQuery and '' for all other adapters. #}
298300
{%- if target.type == "bigquery" -%}
@@ -363,7 +365,7 @@
363365
target_date,
364366
sla_time,
365367
timezone,
366-
sla_deadline_utc,
368+
sla_deadline_utc_str as sla_deadline_utc,
367369
freshness_status,
368370
max_timestamp,
369371
result_description

0 commit comments

Comments
 (0)