Skip to content

Commit f1b70aa

Browse files
fix: add Trino and Spark adapter support for create_table_as and full_name_split (#948)
* fix: add Trino and Spark adapter support for create_table_as and full_name_split - Add trino__full_name_split: Trino arrays are 1-based, not 0-based like the default - Add trino__edr_get_create_table_as_sql: bypass dbt-trino's create_table_as which accesses model.config (fails outside model materialization context) - Add spark__edr_get_create_table_as_sql: use temporary view for temp tables Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> * fix: use SQL standard TRIM syntax for Trino full_name_split Trino requires TRIM(BOTH '"' FROM value) instead of TRIM(value, '"') Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Itamar Hartstein <haritamar@gmail.com>
1 parent 06a56ee commit f1b70aa

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

macros/edr/system/system_utils/full_names.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@
145145
{% endmacro %}
146146

147147

148+
{% macro trino__full_name_split(part_name) %}
149+
{# Trino arrays are 1-based, so we use 1/2/3 instead of 0/1/2 #}
150+
{%- if part_name == 'database_name' -%}
151+
{%- set part_index = 1 -%}
152+
{%- elif part_name == 'schema_name' -%}
153+
{%- set part_index = 2 -%}
154+
{%- elif part_name == 'table_name' -%}
155+
{%- set part_index = 3 -%}
156+
{%- else -%}
157+
{{ return('') }}
158+
{%- endif -%}
159+
trim(BOTH '"' FROM split(full_table_name,'.')[{{ part_index }}]) as {{ part_name }}
160+
{% endmacro %}
161+
162+
148163
{% macro dremio__full_name_split(part_name) %}
149164
{%- if part_name == 'database_name' -%}
150165
trim('"' from split_part(full_table_name,'.',1)) as {{ part_name }}

macros/utils/table_operations/create_table_as.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,21 @@
9090
create or replace {% if temporary %} temporary {% endif %} table {{ relation }}
9191
as {{ sql_query }}
9292
{% endmacro %}
93+
94+
{% macro trino__edr_get_create_table_as_sql(temporary, relation, sql_query) %}
95+
{# dbt-trino's create_table_as accesses model.config which fails when called
96+
outside a model context (e.g. from edr_create_table_as). Use simplified SQL. #}
97+
create table {{ relation }}
98+
as {{ sql_query }}
99+
{% endmacro %}
100+
101+
{% macro spark__edr_get_create_table_as_sql(temporary, relation, sql_query) %}
102+
{# Spark: use a temporary view for temp tables, regular table otherwise #}
103+
{% if temporary %}
104+
create or replace temporary view {{ relation }}
105+
as {{ sql_query }}
106+
{% else %}
107+
create table {{ relation }}
108+
as {{ sql_query }}
109+
{% endif %}
110+
{% endmacro %}

0 commit comments

Comments
 (0)