Skip to content

Commit f944c34

Browse files
add files to connect already existing labels to dbt
1 parent 7bae66b commit f944c34

File tree

198 files changed

+18928
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+18928
-25
lines changed

dbt_project.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ flags:
1717
# These configurations specify where dbt should look for different types of files.
1818
# The `model-paths` config, for example, states that models in this project can be
1919
# found in the "models/" directory. You probably won't need to change these!
20-
model-paths: ["models"]
20+
model-paths: ["models", "sources"]
2121
analysis-paths: ["analyses"]
2222
test-paths: ["tests"]
2323
seed-paths: ["seeds"]
@@ -29,7 +29,7 @@ clean-targets: # directories to be removed by `dbt clean`
2929
- "dbt_packages"
3030

3131
models:
32-
dbt_template:
32+
balancer:
3333
# Config indicated by + and applies to all files under models/templates/
3434
+materialized: view # fallback default, materialized should be overriden in model specific configs
3535
+view_security: invoker # required security setting for views
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{%- macro trino_properties(properties) -%}
2+
map_from_entries(ARRAY[
3+
{%- for key, value in properties.items() %}
4+
ROW('{{ key }}', '{{ value }}')
5+
{%- if not loop.last -%},{%- endif -%}
6+
{%- endfor %}
7+
])
8+
{%- endmacro -%}
9+
10+
{% macro expose_spells(blockchains, spell_type, spell_name, contributors) %}
11+
{%- set validated_contributors = tojson(fromjson(contributors | as_text)) -%}
12+
{%- if ("%s" % validated_contributors) == "null" -%}
13+
{%- do exceptions.raise_compiler_error("Invalid contributors '%s'. The list of contributors must be valid JSON." % contributors) -%}
14+
{%- endif -%}
15+
{%- if target.name == 'prod' -%}
16+
{%- set properties = {
17+
'dune.public': 'true',
18+
'dune.data_explorer.blockchains': blockchains | as_text,
19+
'dune.data_explorer.category': 'abstraction',
20+
'dune.data_explorer.abstraction.type': spell_type,
21+
'dune.data_explorer.abstraction.name': spell_name,
22+
'dune.data_explorer.contributors': validated_contributors,
23+
'dune.vacuum': '{"enabled":true}'
24+
} -%}
25+
{%- if model.config.materialized == "view" -%}
26+
CALL {{ model.database }}._internal.alter_view_properties('{{ model.schema }}', '{{ model.alias }}',
27+
{{ trino_properties(properties) }}
28+
)
29+
{%- else -%}
30+
ALTER TABLE {{ this }}
31+
SET PROPERTIES extra_properties = {{ trino_properties(properties) }}
32+
{%- endif -%}
33+
{%- endif -%}
34+
{%- endmacro -%}
35+
36+
{% macro hide_spells() %}
37+
{%- if target.name == 'prod' -%}
38+
{%- set properties = {
39+
'dune.public': 'false',
40+
'dune.data_explorer.category': 'abstraction',
41+
'dune.vacuum': '{"enabled":true}'
42+
} -%}
43+
{%- if model.config.materialized == "view" -%}
44+
CALL {{ model.database }}._internal.alter_view_properties('{{ model.schema }}', '{{ model.alias }}',
45+
{{ trino_properties(properties) }}
46+
)
47+
{%- else -%}
48+
ALTER TABLE {{ this }}
49+
SET PROPERTIES extra_properties = {{ trino_properties(properties) }}
50+
{%- endif -%}
51+
{%- endif -%}
52+
{%- endmacro -%}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% macro incremental_predicate(column) -%}
2+
{{column}} >= date_trunc('{{var("DBT_ENV_INCREMENTAL_TIME_UNIT")}}', now() - interval '{{var('DBT_ENV_INCREMENTAL_TIME')}}' {{var('DBT_ENV_INCREMENTAL_TIME_UNIT')}})
3+
{%- endmacro -%}

macros/dune_dbt_overrides/get_custom_schema.sql

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@
88

99
{% macro generate_schema_name(custom_schema_name, node) -%}
1010

11-
{%- set dev_suffix = env_var('DEV_SCHEMA_SUFFIX', '') -%}
11+
{# Base schema is set in profiles.yml per Dune docs (team or team__tmp_*) #}
12+
{%- set base_schema = target.schema -%}
1213

13-
{%- if target.name == 'prod' -%}
14-
{# prod environment, writes to target schema #}
15-
{{ target.schema }}
16-
{%- elif target.name != 'prod' and dev_suffix != '' -%}
17-
{# dev environments, writes to target schema with dev suffix #}
18-
{{ target.schema }}__tmp_{{ dev_suffix | trim }}
14+
{# If a model supplies a custom schema, append it to avoid collisions #}
15+
{%- if custom_schema_name is not none -%}
16+
{{ base_schema }}__{{ custom_schema_name | trim }}
1917
{%- else -%}
20-
{# default to dev environment, no dev suffix #}
21-
{{ target.schema }}__tmp_
18+
{{ base_schema }}
2219
{%- endif -%}
2320

2421
{%- endmacro %}

0 commit comments

Comments
 (0)