Compare commits

...

5 Commits
v2.0.0 ... main

Author SHA1 Message Date
Shah Newaz Khan
fb20f8e47a
Merge pull request #9 from FlipsideCrypto/STREAM-1089/namespace-scope-construct_api_route
namespace scope construct_api_route
2025-04-11 07:57:53 -07:00
shah
84dc724d7d namespace scope construct_api_route 2025-04-10 19:32:40 -07:00
Shah Newaz Khan
6a45354247
Merge pull request #8 from FlipsideCrypto/STREAM-1089/namespace-scope-ephemeral-deploy-macros
namespace scope ephemeral deploy macro dependencies | add render macro
2025-04-10 15:51:45 -07:00
shah
732e561c71 namesapace scope apply_grants_by_schema() 2025-04-09 16:32:02 -07:00
shah
42c83595f8 namespace scope ephemeral deploy macro dependencies 2025-04-09 13:58:58 -07:00
2 changed files with 73 additions and 6 deletions

View File

@ -36,7 +36,7 @@
func_type = none
) %}
CREATE OR REPLACE {{ func_type }} FUNCTION {{ name_ }}(
{{- compile_signature(signature) }}
{{- livequery_base.compile_signature(signature) }}
)
COPY GRANTS
RETURNS {{ return_type }}
@ -45,7 +45,7 @@
{% endif %}
{%- if api_integration -%}
api_integration = {{ api_integration }}
AS {{ construct_api_route(sql_) ~ ";" }}
AS {{ livequery_base.construct_api_route(sql_) ~ ";" }}
{% else -%}
AS
$$
@ -67,7 +67,7 @@
{% set func_type = config ["func_type"] %}
{% if not drop_ -%}
{{ create_sql_function(
{{ livequery_base.create_sql_function(
name_ = name_,
signature = signature,
return_type = return_type,
@ -113,7 +113,7 @@
CREATE SCHEMA IF NOT EXISTS {{ schema }};
{%- set configs = fromyaml(config_func(blockchain, network)) if network else fromyaml(config_func(schema, blockchain)) -%}
{%- for udf in configs -%}
{{- create_or_drop_function_from_config(udf, drop_=drop_) -}}
{{- livequery_base.create_or_drop_function_from_config(udf, drop_=drop_) -}}
{%- endfor -%}
{%- endmacro -%}
@ -147,7 +147,7 @@
{% if execute and (var("UPDATE_UDFS_AND_SPS") or var("DROP_UDFS_AND_SPS")) and model.unique_id in selected_resources %}
{% set sql %}
{% for config in configs %}
{{- crud_udfs_by_chain(config, blockchain, network, var("DROP_UDFS_AND_SPS")) -}}
{{- livequery_base.crud_udfs_by_chain(config, blockchain, network, var("DROP_UDFS_AND_SPS")) -}}
{%- endfor -%}
{%- endset -%}
{%- if var("DROP_UDFS_AND_SPS") -%}
@ -155,7 +155,7 @@
{%- else -%}
{%- do log("Deploy partner udfs: " ~ this.database ~ "." ~ schema, true) -%}
{%- endif -%}
{%- do run_query(sql ~ apply_grants_by_schema(schema)) -%}
{%- do run_query(sql ~ livequery_base.apply_grants_by_schema(schema)) -%}
{%- endif -%}
SELECT '{{ model.schema }}' as schema_
{%- endmacro -%}

View File

@ -0,0 +1,67 @@
{% macro get_rendered_model(package_name, model_name, schema, blockchain, network) %}
{#
This macro retrieves and renders a specified model from the graph.
Args:
package_name (str): The name of the package containing the model.
model_name (str): The name of the model to be rendered.
schema (str): The schema to be used.
blockchain (str): The blockchain to be used.
network (str): The network to be used.
Returns:
str: The rendered SQL of the specified model.
#}
{% if execute %}
{{ log("=== Starting get_rendered_model ===", info=True) }}
{# Use a list to store the node to avoid scope issues #}
{%- set nodes = [] -%}
{{ log("Looking for node: " ~ package_name ~ "." ~ model_name, info=True) }}
{%- for node in graph.nodes.values() -%}
{%- if node.package_name == package_name and node.name == model_name -%}
{{ log("Found target node: " ~ node.unique_id, info=True) }}
{%- do nodes.append(node) -%}
{%- endif -%}
{%- endfor -%}
{%- if nodes | length == 0 -%}
{{ log("No target node found!", info=True) }}
{{ return('') }}
{%- endif -%}
{%- set target_node = nodes[0] -%}
{{ log("Processing node: " ~ target_node.unique_id, info=True) }}
{{ log("Dependencies:\n\t\t" ~ (target_node.depends_on.nodes | pprint).replace("\n", "\n\t\t"), info=True) }}
{# First render all dependency CTEs #}
{%- set ctes = [] -%}
{%- for dep_id in target_node.depends_on.nodes -%}
{{ log("Processing dependency: " ~ dep_id, info=True) }}
{%- set dep_node = graph.nodes[dep_id] -%}
{%- set rendered_sql = render(dep_node.raw_code) | trim -%}
{%- if rendered_sql -%}
{%- set cte_sql -%}
__dbt__cte__{{ dep_node.name }} AS (
{{ rendered_sql }}
)
{%- endset -%}
{%- do ctes.append(cte_sql) -%}
{%- endif -%}
{%- endfor -%}
{{ log("Number of CTEs generated: " ~ ctes | length, info=True) }}
{# Combine CTEs with main query #}
{%- set final_sql -%}
WITH {{ ctes | join(',\n\n') }}
{{ render(target_node.raw_code) }}
{%- endset -%}
{{ log("=== End get_rendered_model ===\n\n" , info=True) }}
{{ return(final_sql) }}
{% endif %}
{% endmacro %}