|
| 1 | +{# |
| 2 | + Override of the dbt-trino adapter's properties() macro to inject dune.public |
| 3 | + into extra_properties at CREATE TABLE time. |
| 4 | +
|
| 5 | + Configure per model via config(): |
| 6 | + , dune_public = true -- make table publicly visible on Dune |
| 7 | + , dune_public = false -- (default) keep table private |
| 8 | +
|
| 9 | + Or set for an entire folder in dbt_project.yml: |
| 10 | + models: |
| 11 | + my_project: |
| 12 | + public_models: |
| 13 | + +dune_public: true |
| 14 | +
|
| 15 | + Only runs in prod. On incremental (non-full-refresh) runs, set_table_visibility |
| 16 | + handles it via ALTER TABLE instead. |
| 17 | +#} |
| 18 | +{% macro properties(temporary=False) %} |
| 19 | + {%- set _properties = config.get('properties') -%} |
| 20 | + {%- set table_format = config.get('table_format') -%} |
| 21 | + {%- set file_format = config.get('file_format') -%} |
| 22 | +
|
| 23 | + {%- if file_format -%} |
| 24 | + {%- if _properties -%} |
| 25 | + {%- if _properties.format -%} |
| 26 | + {% set msg %} |
| 27 | + You can specify either 'file_format' or 'properties.format' configurations, but not both. |
| 28 | + {% endset %} |
| 29 | + {% do exceptions.raise_compiler_error(msg) %} |
| 30 | + {%- else -%} |
| 31 | + {%- do _properties.update({'format': "'" ~ file_format ~ "'"}) -%} |
| 32 | + {%- endif -%} |
| 33 | + {%- else -%} |
| 34 | + {%- set _properties = {'format': "'" ~ file_format ~ "'"} -%} |
| 35 | + {%- endif -%} |
| 36 | + {%- endif -%} |
| 37 | +
|
| 38 | + {%- if table_format -%} |
| 39 | + {%- if _properties -%} |
| 40 | + {%- if _properties.type -%} |
| 41 | + {% set msg %} |
| 42 | + You can specify either 'table_format' or 'properties.type' configurations, but not both. |
| 43 | + {% endset %} |
| 44 | + {% do exceptions.raise_compiler_error(msg) %} |
| 45 | + {%- else -%} |
| 46 | + {%- do _properties.update({'type': "'" ~ table_format ~ "'"}) -%} |
| 47 | + {%- endif -%} |
| 48 | + {%- else -%} |
| 49 | + {%- set _properties = {'type': "'" ~ table_format ~ "'"} -%} |
| 50 | + {%- endif -%} |
| 51 | + {%- endif -%} |
| 52 | +
|
| 53 | + {%- if temporary -%} |
| 54 | + {%- if _properties -%} |
| 55 | + {%- if _properties.location -%} |
| 56 | + {%- do _properties.update({'location': _properties.location[:-1] ~ "__dbt_tmp'"}) -%} |
| 57 | + {%- endif -%} |
| 58 | + {%- endif -%} |
| 59 | + {%- endif -%} |
| 60 | +
|
| 61 | + {#-- Inject dune.public into extra_properties at CREATE time (prod only) --#} |
| 62 | + {%- set dune_public = config.get('dune_public') -%} |
| 63 | + {%- if dune_public is not none and target.name == 'prod' -%} |
| 64 | + {%- set visibility_value = 'true' if dune_public else 'false' -%} |
| 65 | + {%- set extra_props_sql = "map_from_entries(ARRAY[ROW('dune.public', '" ~ visibility_value ~ "')])" -%} |
| 66 | + {%- if _properties is none -%} |
| 67 | + {%- set _properties = {'extra_properties': extra_props_sql} -%} |
| 68 | + {%- else -%} |
| 69 | + {%- do _properties.update({'extra_properties': extra_props_sql}) -%} |
| 70 | + {%- endif -%} |
| 71 | + {%- endif -%} |
| 72 | +
|
| 73 | + {%- if _properties is not none -%} |
| 74 | + WITH ( |
| 75 | + {%- for key, value in _properties.items() -%} |
| 76 | + {{ key }} = {{ value }} |
| 77 | + {%- if not loop.last -%}{{ ',\n ' }}{%- endif -%} |
| 78 | + {%- endfor -%} |
| 79 | + ) |
| 80 | + {%- endif -%} |
| 81 | +{%- endmacro -%} |
0 commit comments