Skip to content

Commit 0184a34

Browse files
Fix cross-database compatibility in volume_threshold macro
- Replace 'cast(... as numeric)' with edr_type_numeric() for adapter-aware type - Replace 'limit 1' with row_number() pattern (SQL Server/Fabric compatible) - Replace '||' string concat with edr_concat() (SQL Server/Fabric compatible) Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent 6e75bc8 commit 0184a34

1 file changed

Lines changed: 37 additions & 15 deletions

File tree

macros/edr/tests/test_volume_threshold.sql

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,31 @@
182182

183183
current_bucket as (
184184
select bucket_start, bucket_end, row_count
185-
from metrics
186-
order by bucket_end desc
187-
limit 1
185+
from
186+
(
187+
select
188+
bucket_start,
189+
bucket_end,
190+
row_count,
191+
row_number() over (order by bucket_end desc) as rn
192+
from metrics
193+
) as ranked_current
194+
where rn = 1
188195
),
189196

190197
previous_bucket as (
191198
select bucket_start, bucket_end, row_count
192-
from metrics
193-
where bucket_end <= (select bucket_start from current_bucket)
194-
order by bucket_end desc
195-
limit 1
199+
from
200+
(
201+
select
202+
bucket_start,
203+
bucket_end,
204+
row_count,
205+
row_number() over (order by bucket_end desc) as rn
206+
from metrics
207+
where bucket_end <= (select bucket_start from current_bucket)
208+
) as ranked_previous
209+
where rn = 1
196210
),
197211

198212
comparison as (
@@ -210,7 +224,7 @@
210224
cast(
211225
(curr.row_count - prev.row_count)
212226
* 100.0
213-
/ prev.row_count as numeric
227+
/ prev.row_count as {{ elementary.edr_type_numeric() }}
214228
),
215229
2
216230
)
@@ -262,13 +276,21 @@
262276
case
263277
severity_level when 2 then 'error' when 1 then 'warn' else 'pass'
264278
end as severity_name,
265-
'Row count changed by '
266-
|| cast(percent_change as {{ elementary.edr_type_string() }})
267-
|| '% (from '
268-
|| cast(previous_row_count as {{ elementary.edr_type_string() }})
269-
|| ' to '
270-
|| cast(current_row_count as {{ elementary.edr_type_string() }})
271-
|| ')' as result_description
279+
{{
280+
elementary.edr_concat(
281+
[
282+
"'Row count changed by '",
283+
"cast(percent_change as " ~ elementary.edr_type_string() ~ ")",
284+
"'% (from '",
285+
"cast(previous_row_count as "
286+
~ elementary.edr_type_string()
287+
~ ")",
288+
"' to '",
289+
"cast(current_row_count as " ~ elementary.edr_type_string() ~ ")",
290+
"')'",
291+
]
292+
)
293+
}} as result_description
272294
from result
273295

274296
{% endmacro %}

0 commit comments

Comments
 (0)