Skip to content

Commit

Permalink
Get 'properties' config inside 'properties' function. Add tests for t…
Browse files Browse the repository at this point in the history
…able properties
  • Loading branch information
damian3031 committed Oct 23, 2024
1 parent 5e50f93 commit 1214e37
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
15 changes: 7 additions & 8 deletions dbt/include/trino/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
{% macro trino__create_csv_table(model, agate_table) %}
{%- set column_override = model['config'].get('column_types', {}) -%}
{%- set quote_seed_column = model['config'].get('quote_columns', None) -%}
{%- set _properties = config.get('properties') -%}

{% set sql %}
create table {{ this.render() }} (
Expand All @@ -68,7 +67,7 @@
{%- set column_name = (col_name | string) -%}
{{ adapter.quote_seed_column(column_name, quote_seed_column) }} {{ type }} {%- if not loop.last -%}, {%- endif -%}
{%- endfor -%}
) {{ properties(_properties) }}
) {{ properties() }}
{% endset %}

{% call statement('_') -%}
Expand All @@ -78,10 +77,11 @@
{{ return(sql) }}
{% endmacro %}

{% macro properties(properties) %}
{%- if properties is not none -%}
{% macro properties() %}
{%- set _properties = config.get('properties') -%}
{%- if _properties is not none -%}
WITH (
{%- for key, value in properties.items() -%}
{%- for key, value in _properties.items() -%}
{{ key }} = {{ value }}
{%- if not loop.last -%}{{ ',\n ' }}{%- endif -%}
{%- endfor -%}
Expand All @@ -100,7 +100,6 @@
{%- endmacro -%}
{% macro trino__create_table_as(temporary, relation, sql, replace=False) -%}
{%- set _properties = config.get('properties') -%}
{%- if replace -%}
{%- set or_replace = ' or replace' -%}
Expand All @@ -117,7 +116,7 @@
{{ get_assert_columns_equivalent(sql) }}
{%- set sql = get_select_subquery(sql) %}
{{ comment(model.get('description')) }}
{{ properties(_properties) }}
{{ properties() }}
;
insert into {{ relation }}
Expand All @@ -130,7 +129,7 @@
create{{ or_replace }} table {{ relation }}
{{ comment(model.get('description')) }}
{{ properties(_properties) }}
{{ properties() }}
as (
{{ sql }}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{%- macro trino__get_create_materialized_view_as_sql(target_relation, sql) -%}
{%- set _properties = config.get('properties') -%}
create materialized view {{ target_relation }}
{{ properties(_properties) }}
{{ properties() }}
as
{{ sql }}
;
Expand Down
49 changes: 49 additions & 0 deletions tests/functional/adapter/test_table_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
from dbt.tests.util import run_dbt, run_dbt_and_capture

from tests.functional.adapter.materialization.fixtures import model_sql, seed_csv


class BaseTableProperties:
# Everything that goes in the "seeds" directory
@pytest.fixture(scope="class")
def seeds(self):
return {
"seed.csv": seed_csv,
}

# Everything that goes in the "models" directory
@pytest.fixture(scope="class")
def models(self):
return {
"model.sql": model_sql,
}


@pytest.mark.iceberg
class TestTableProperties(BaseTableProperties):
# Configuration in dbt_project.yml
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"name": "properties_test",
"models": {
"+materialized": "table",
"+properties": {
"format": "'PARQUET'",
"format_version": "2",
},
},
}

def test_table_properties(self, project):
# Seed seed
results = run_dbt(["seed"], expect_pass=True)
assert len(results) == 1

# Create model with properties
results, logs = run_dbt_and_capture(["--debug", "run"], expect_pass=True)
assert len(results) == 1
assert "WITH (" in logs
assert "format = 'PARQUET'" in logs
assert "format_version = 2" in logs

0 comments on commit 1214e37

Please sign in to comment.