From 766593d13d68806fe2afecfd928f3fb5d67bc982 Mon Sep 17 00:00:00 2001 From: shah Date: Fri, 16 Feb 2024 13:34:11 -0800 Subject: [PATCH] added if_data_call_function_v2 --- macros/streamline/utils.sql | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/macros/streamline/utils.sql b/macros/streamline/utils.sql index f67b6dd..94a6267 100644 --- a/macros/streamline/utils.sql +++ b/macros/streamline/utils.sql @@ -82,3 +82,40 @@ ) }} {%- endif %} {% endmacro %} + +{% macro if_data_call_function_v2( + func, + target, + params + ) %} + {% if var( + "STREAMLINE_INVOKE_STREAMS" + ) %} + {% if execute %} + {{ log( + "Running macro `if_data_call_function`: Calling udf " ~ func ~ " with params: \n" ~ params | tojson(indent=2) ~ "\n on " ~ target, + True + ) }} + {% endif %} + SELECT + {{ this.schema }}.{{ func }}( parse_json($${{ params | tojson }}$$) ) + WHERE + EXISTS( + SELECT + 1 + FROM + {{ target }} + LIMIT + 1 + ) + {% else %} + {% if execute %} + {{ log( + "Running macro `if_data_call_function`: NOOP", + False + ) }} + {% endif %} + SELECT + NULL + {% endif %} +{% endmacro %} \ No newline at end of file