Skip to content

Commit

Permalink
Merge pull request #362 from alexsubota/apply-query-settings-for-empt…
Browse files Browse the repository at this point in the history
…y-model

Apply query settings for empty table model
  • Loading branch information
BentsiLeviav authored Oct 30, 2024
2 parents f5c00bb + 52cbf4f commit 0198fc8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions dbt/include/clickhouse/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
{{ sql }}
)
{%- endif %}
{{ adapter.get_model_query_settings(model) }}
{%- endif %}

{%- endmacro %}
Expand Down
65 changes: 65 additions & 0 deletions tests/integration/adapter/query_settings/test_query_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest
from dbt.tests.util import run_dbt

nullable_column_model = """
{{
config(
materialized='table',
query_settings={
'join_use_nulls': 1
}
)
}}
select t2.id as test_id
from (select 1 as id) t1
left join (select 2 as id) t2
on t1.id=t2.id
"""


class TestNullableColumnJoin:
@pytest.fixture(scope="class")
def models(self):
return {
"nullable_column_model.sql": nullable_column_model,
}

def test_nullable_column_join(self, project):
run_dbt(["run", "--select", "nullable_column_model"])
result = project.run_sql(
"select isNullable(test_id) as is_nullable_column from nullable_column_model",
fetch="one",
)
assert result[0] == 1


not_nullable_column_model = """
{{
config(
materialized='table',
query_settings={
'join_use_nulls': 0
}
)
}}
select t2.id as test_id
from (select 1 as id) t1
left join (select 2 as id) t2
on t1.id=t2.id
"""


class TestNotNullableColumnJoin:
@pytest.fixture(scope="class")
def models(self):
return {
"not_nullable_column_model.sql": not_nullable_column_model,
}

def test_nullable_column_join(self, project):
run_dbt(["run", "--select", "not_nullable_column_model"])
result = project.run_sql(
"select isNullable(test_id) as is_nullable_column from not_nullable_column_model",
fetch="one",
)
assert result[0] == 0

0 comments on commit 0198fc8

Please sign in to comment.