From 7a84e51c1a4eaee1c4cf2969f86323c5639de008 Mon Sep 17 00:00:00 2001 From: alexsubota Date: Wed, 25 Sep 2024 11:57:33 +0300 Subject: [PATCH 1/3] Apply query settings for empty model --- dbt/include/clickhouse/macros/materializations/table.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt/include/clickhouse/macros/materializations/table.sql b/dbt/include/clickhouse/macros/materializations/table.sql index 1ef0e8b5..a7601552 100644 --- a/dbt/include/clickhouse/macros/materializations/table.sql +++ b/dbt/include/clickhouse/macros/materializations/table.sql @@ -203,6 +203,7 @@ {{ sql }} ) {%- endif %} + {{ adapter.get_model_query_settings(model) }} {%- endif %} {%- endmacro %} From d992b9f39a4c75a056fa8236a3d10c02bc9550a1 Mon Sep 17 00:00:00 2001 From: alexsubota Date: Thu, 26 Sep 2024 13:26:11 +0300 Subject: [PATCH 2/3] Create test_query_settings.py --- .../query_settings/test_query_settings.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/integration/adapter/query_settings/test_query_settings.py diff --git a/tests/integration/adapter/query_settings/test_query_settings.py b/tests/integration/adapter/query_settings/test_query_settings.py new file mode 100644 index 00000000..43fb6c39 --- /dev/null +++ b/tests/integration/adapter/query_settings/test_query_settings.py @@ -0,0 +1,60 @@ +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 From 52cbf4ff37a6990647dfc568078674d92a32ec5d Mon Sep 17 00:00:00 2001 From: alexsubota Date: Fri, 27 Sep 2024 09:22:04 +0300 Subject: [PATCH 3/3] fix black test_query_settings.py --- .../adapter/query_settings/test_query_settings.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/integration/adapter/query_settings/test_query_settings.py b/tests/integration/adapter/query_settings/test_query_settings.py index 43fb6c39..83ef370c 100644 --- a/tests/integration/adapter/query_settings/test_query_settings.py +++ b/tests/integration/adapter/query_settings/test_query_settings.py @@ -26,11 +26,13 @@ def models(self): 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") + 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( @@ -56,5 +58,8 @@ def models(self): 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") + result = project.run_sql( + "select isNullable(test_id) as is_nullable_column from not_nullable_column_model", + fetch="one", + ) assert result[0] == 0