From 59535c5e39b55adb0b81f5326c1049cddf08cc2e Mon Sep 17 00:00:00 2001 From: Geoff Genz Date: Fri, 2 Sep 2022 13:05:23 -0600 Subject: [PATCH 1/2] Backport settings fix, bump versions --- dbt/adapters/clickhouse/__version__.py | 2 +- dbt/include/clickhouse/macros/adapters.sql | 5 +++-- dev_requirements.txt | 2 +- setup.py | 2 +- tests/conftest.py | 2 +- tests/integration/adapter/test_basic.py | 3 ++- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dbt/adapters/clickhouse/__version__.py b/dbt/adapters/clickhouse/__version__.py index aae2670c..3e606d2b 100644 --- a/dbt/adapters/clickhouse/__version__.py +++ b/dbt/adapters/clickhouse/__version__.py @@ -1 +1 @@ -version = '1.1.7' +version = '1.1.8' diff --git a/dbt/include/clickhouse/macros/adapters.sql b/dbt/include/clickhouse/macros/adapters.sql index 0ba12813..9e6f1448 100644 --- a/dbt/include/clickhouse/macros/adapters.sql +++ b/dbt/include/clickhouse/macros/adapters.sql @@ -69,7 +69,6 @@ {% set create_table = create_table_or_empty(temporary, relation, sql) %} {% if adapter.is_before_version('22.7.1') -%} {{ create_table }} - {{ adapter.get_model_settings(model) }} {%- else %} {% call statement('create_table_empty') %} {{ create_table }} @@ -88,6 +87,7 @@ engine = Memory {{ order_cols(label="order by") }} {{ partition_cols(label="partition by") }} + {{ adapter.get_model_settings(model) }} {%- else %} create table {{ relation.include(database=False) }} {{ on_cluster_clause(label="on cluster") }} @@ -95,13 +95,14 @@ {{ order_cols(label="order by") }} {{ primary_key_clause(label="primary key") }} {{ partition_cols(label="partition by") }} + {{ adapter.get_model_settings(model) }} {% if not adapter.is_before_version('22.7.1') -%} empty {%- endif %} {%- endif %} as ( {{ sql }} - ); + ) {%- endmacro %} {% macro clickhouse__create_view_as(relation, sql) -%} diff --git a/dev_requirements.txt b/dev_requirements.txt index 63c576c5..106f2c86 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -1,5 +1,5 @@ dbt-core==1.1.0 -clickhouse-connect>=0.1.5 +clickhouse-connect>=0.2.5 clickhouse-driver>=0.2.3 pytest==7.0.0 pytest-dotenv==0.5.2 diff --git a/setup.py b/setup.py index d1de0360..edb44ef2 100644 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ def _dbt_clickhouse_version(): }, install_requires=[ f'dbt-core~={dbt_version}', - 'clickhouse-connect>=0.1.5', + 'clickhouse-connect>=0.2.5', 'clickhouse-driver>=0.2.3', ], python_requires=">=3.7", diff --git a/tests/conftest.py b/tests/conftest.py index 1d280205..fe16d3be 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,7 +17,7 @@ # repos. Example in dbt.tests.adapter.basic.test_base. @pytest.fixture(scope="session") def test_config(): - run_docker = os.environ.get('RUN_DOCKER_ENV_VAR_NAME', False) + run_docker = os.environ.get('RUN_DOCKER_ENV_VAR_NAME', '').lower() in ('1', 'true', 'yes') if run_docker: # Run docker compose with clickhouse-server image. compose_file = f'{Path(__file__).parent}/docker-compose.yml' diff --git a/tests/integration/adapter/test_basic.py b/tests/integration/adapter/test_basic.py index f983c996..93b3bb80 100644 --- a/tests/integration/adapter/test_basic.py +++ b/tests/integration/adapter/test_basic.py @@ -68,7 +68,8 @@ class TestMergeTreeTabelMaterializations(BaseSimpleMaterializations): @pytest.fixture(scope="class") def models(self): config_materialized_table = """ - {{ config(order_by='(some_date, id, name)', engine='MergeTree()', materialized='table') }} + {{ config(order_by='(some_date, id, name)', engine='MergeTree()', materialized='table', + settings={'allow_nullable_key': 1}) }} """ base_table_sql = config_materialized_table + model_base return { From 664f6bc9daa3adae1ccba223dfd69d2ab75d16b5 Mon Sep 17 00:00:00 2001 From: Geoff Genz Date: Fri, 2 Sep 2022 13:37:21 -0600 Subject: [PATCH 2/2] Remove invalid model settings from insert --- dbt/include/clickhouse/macros/adapters.sql | 1 - tests/docker-compose.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/dbt/include/clickhouse/macros/adapters.sql b/dbt/include/clickhouse/macros/adapters.sql index 9e6f1448..7c6335de 100644 --- a/dbt/include/clickhouse/macros/adapters.sql +++ b/dbt/include/clickhouse/macros/adapters.sql @@ -225,7 +225,6 @@ insert into {{ target_relation }} ({{ dest_cols_csv }}) {{ sql }} - {{ adapter.get_model_settings(model) }} {%- endmacro %} diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 59fa84ca..49bee504 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: ch_server: - image: clickhouse/clickhouse-server + image: clickhouse/clickhouse-server:latest ports: - "10723:8123" - "10743:8443"