Skip to content

Commit

Permalink
feat: support quoted columns in constraint (#404)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Dimchenko <39801237+svdimchenko@users.noreply.github.com>
  • Loading branch information
hiro-o918 and svdimchenko authored Sep 14, 2023
1 parent fc00e80 commit 2b65fb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dbt/include/athena/macros/adapters/columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
{%- if col['data_type'] is not defined -%}
{{ col_err.append(col['name']) }}
{%- else -%}
cast(null as {{ dml_data_type(col['data_type']) }}) as {{ col['name'] }}{{ ", " if not loop.last }}
{% set col_name = adapter.quote(col['name']) if col.get('quote') else col['name'] %}
cast(null as {{ dml_data_type(col['data_type']) }}) as {{ col_name }}{{ ", " if not loop.last }}
{%- endif -%}
{%- endfor -%}
{%- if (col_err | length) > 0 -%}
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/adapter/test_constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from dbt.tests.adapter.constraints.fixtures import (
model_quoted_column_schema_yml,
my_model_with_quoted_column_name_sql,
)
from dbt.tests.adapter.constraints.test_constraints import BaseConstraintQuotedColumn


class TestAthenaConstraintQuotedColumn(BaseConstraintQuotedColumn):
@pytest.fixture(scope="class")
def models(self):
return {
"my_model.sql": my_model_with_quoted_column_name_sql,
"constraints_schema.yml": model_quoted_column_schema_yml.replace("text", "string"),
}

@pytest.fixture(scope="class")
def expected_sql(self):
# FIXME: dbt-athena outputs a query about stats into `target/run/` directory.
# dbt-core expects the query to be a ddl statement to create a table.
# This is a workaround to pass the test for now.

# NOTE: by the above reason, this test just checks the query can be executed without errors.
# The query itself is not checked.
return 'SELECT \'{"rowcount":1,"data_scanned_in_bytes":0}\';'

0 comments on commit 2b65fb0

Please sign in to comment.