mirror of
https://github.com/FlipsideCrypto/livequery-models.git
synced 2026-02-06 10:56:46 +00:00
add macro and model to generate UDF ddls
This commit is contained in:
parent
2c561fd8ff
commit
0de08fc0ff
@ -156,4 +156,41 @@
|
||||
{%- set combined_ddl = gold_views_ddl + gold_tables_ddl -%}
|
||||
{%- do combined_ddl.insert(0, "CREATE DATABASE IF NOT EXISTS __NEW__;") -%}
|
||||
{{- "BEGIN\n" ~ (combined_ddl | join("\n")) ~ "\nEND" -}}
|
||||
{%- endmacro -%}
|
||||
|
||||
{% macro generate_datashare_udf_ddl() %}
|
||||
{#
|
||||
generate UDF DDL for datashare
|
||||
|
||||
Return: UDF DDL for datashare
|
||||
#}
|
||||
{%- set schema = "UTILS" -%}
|
||||
{%- set udfs = fromyaml(fsc_utils.udf_configs(schema)) -%}
|
||||
{%- set combined_ddl = [] -%}
|
||||
{%- for udf in udfs -%}
|
||||
{% set name_ = udf ["name"] %}
|
||||
{% set signature = udf ["signature"] %}
|
||||
{% set return_type = udf ["return_type"] %}
|
||||
{% set sql_ = udf ["sql"] %}
|
||||
{% set options = udf ["options"] %}
|
||||
{% set api_integration = udf ["api_integration"] %}
|
||||
{% set func_type = udf ["func_type"] %}
|
||||
{% set exclude_from_datashare = udf.get("exclude_from_datashare",False) %}
|
||||
{% if not exclude_from_datashare %}
|
||||
{%- set udf_ddl = fsc_utils.create_sql_function(
|
||||
name_ = name_,
|
||||
signature = signature,
|
||||
return_type = return_type,
|
||||
sql_ = sql_,
|
||||
options = options,
|
||||
api_integration = api_integration,
|
||||
func_type = func_type
|
||||
).replace("\\","\\\\").replace("'","\\'") -%}
|
||||
{%- do combined_ddl.append(udf_ddl) -%}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{%- do combined_ddl.insert(0, "CREATE DATABASE IF NOT EXISTS __NEW__;") -%}
|
||||
{%- do combined_ddl.insert(1, "USE DATABASE __NEW__;") -%}
|
||||
{%- do combined_ddl.insert(2, "CREATE SCHEMA IF NOT EXISTS "~schema~";") -%}
|
||||
{{- "'BEGIN','" ~ (combined_ddl | join("','")) ~ "','END'" -}}
|
||||
{%- endmacro -%}
|
||||
20
models/datashare/_datashare___create_udfs.sql
Normal file
20
models/datashare/_datashare___create_udfs.sql
Normal file
@ -0,0 +1,20 @@
|
||||
{{
|
||||
config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'ddl_hash',
|
||||
merge_update_columns = [],
|
||||
)
|
||||
}}
|
||||
{% if execute %}
|
||||
SELECT
|
||||
CONCAT_WS('\n',{{- fsc_utils.generate_datashare_udf_ddl().strip() -}}) AS ddl,
|
||||
md5(ddl) AS ddl_hash,
|
||||
sysdate() as ddl_created_at
|
||||
{% else %}
|
||||
SELECT
|
||||
null as ddl,
|
||||
null as ddl_hash,
|
||||
null as ddl_created_at
|
||||
from dual limit 0
|
||||
{% endif %}
|
||||
Loading…
Reference in New Issue
Block a user