Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add list support to primary_key" #400

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Avoid potential data loss by using `CREATE OR REPLACE DICTIONARY` to atomically
* Added support for the creation of more than one materialized view inserting records into the same target table. ([#360](https://github.com/ClickHouse/dbt-clickhouse/pull/364))

### Improvement

* Enhance the `primary_key` macro to accept a list of columns, allowing for primary keys with multiple columns. ([#337](https://github.com/ClickHouse/dbt-clickhouse/pull/337))
* Added support for [range_hashed](https://clickhouse.com/docs/en/sql-reference/dictionaries#range_hashed) and [complex_key_range_hashed](https://clickhouse.com/docs/en/sql-reference/dictionaries#complex_key_range_hashed) layouts to the dictionary materialization. ([#361](https://github.com/ClickHouse/dbt-clickhouse/pull/361))
* Truncated stack trace for database errors for cleaner output when HIDE_STACK_TRACE variable is set to any value. ([#382](https://github.com/ClickHouse/dbt-clickhouse/pull/382))
* It is now possible to pass query settings not only on table creation but also on query. ([#362](https://github.com/ClickHouse/dbt-clickhouse/pull/362))
Expand Down
14 changes: 3 additions & 11 deletions dbt/include/clickhouse/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,10 @@
{%- endmacro -%}

{% macro primary_key_clause(label) %}
{%- set cols = config.get('primary_key', validator=validation.any[list, basestring]) -%}
{%- set primary_key = config.get('primary_key', validator=validation.any[basestring]) -%}

{%- if cols is not none %}
{%- if cols is string -%}
{%- set cols = [cols] -%}
{%- endif -%}
{{ label }} (
{%- for item in cols -%}
{{ item }}
{%- if not loop.last -%},{%- endif -%}
{%- endfor -%}
)
{%- if primary_key is not none %}
{{ label }} {{ primary_key }}
{%- endif %}
{%- endmacro -%}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/adapter/basic/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TestIncremental(BaseIncremental):


incremental_not_schema_change_sql = """
{{ config(materialized="incremental", primary_key="user_id_current_time", unique_key="user_id_current_time",on_schema_change="append_new_columns") }}
{{ config(materialized="incremental", unique_key="user_id_current_time",on_schema_change="append_new_columns") }}
select
toString(1) || '-' || toString(now64()) as user_id_current_time,
{% if is_incremental() %}
Expand Down
1 change: 0 additions & 1 deletion tests/integration/adapter/clickhouse/test_clickhouse_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
materialized='incremental',
order_by='pickup_datetime',
incremental_strategy='delete+insert',
primary_key='trip_id',
unique_key='trip_id',
taxi_s3={"structure":['trip_id UInt32', 'pickup_datetime DateTime', 'passenger_count UInt8']}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
materialized='table',
engine='MergeTree()',
order_by=['ts'],
primary_key=['impid'],
unique_key=['impid']
)
}}
Expand All @@ -34,7 +33,6 @@
materialized='incremental',
engine='MergeTree()',
order_by=['ts'],
primary_key=['impid'],
unique_key=['impid'],
settings={'allow_nullable_key':'1'}
)
Expand Down Expand Up @@ -64,7 +62,6 @@ def test_simple_incremental(self, project):
{{ config(
materialized='incremental',
order_by=['key1'],
primary_key='key1',
unique_key='key1',
incremental_strategy='delete+insert',
settings={'allow_nullable_key':1}
Expand Down Expand Up @@ -100,7 +97,6 @@ def test_lw_delete(self, project):
{{ config(
materialized='incremental',
order_by=['key1'],
primary_key='key1',
unique_key='key1',
incremental_strategy='legacy',
settings={'allow_nullable_key':1}
Expand Down Expand Up @@ -144,7 +140,6 @@ def test_legacy(self, project):
{{ config(
materialized='incremental',
order_by=['key1', 'key2'],
primary_key=['key1', 'key2'],
unique_key='key1, key2',
incremental_strategy='delete+insert'
)
Expand Down Expand Up @@ -179,7 +174,7 @@ class TestInsertsOnlyIncrementalMaterialization(BaseIncremental):
@pytest.fixture(scope="class")
def models(self):
config_materialized_incremental = """
{{ config(order_by='(some_date, id, name)', inserts_only=True, materialized='incremental', primary_key='id', unique_key='id') }}
{{ config(order_by='(some_date, id, name)', inserts_only=True, materialized='incremental', unique_key='id') }}
"""
incremental_sql = config_materialized_incremental + model_incremental
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
materialized='distributed_table',
engine='MergeTree()',
order_by=['ts'],
primary_key=['impid'],
unique_key=['impid']
)
}}
Expand All @@ -30,7 +29,6 @@
config(
materialized='distributed_incremental',
engine='MergeTree()',
primary_key=['impid'],
order_by=['ts'],
unique_key=['impid']
)
Expand Down Expand Up @@ -71,7 +69,6 @@ def test_simple_incremental(self, project):
{{ config(
materialized='distributed_incremental',
order_by=['key1'],
primary_key='key1',
unique_key='key1',
incremental_strategy='delete+insert'
)
Expand Down Expand Up @@ -114,7 +111,6 @@ def test_lw_delete(self, project):
{{ config(
materialized='distributed_incremental',
order_by=['key1', 'key2'],
primary_key=['key1', 'key2'],
unique_key='key1, key2',
incremental_strategy='delete+insert'
)
Expand Down Expand Up @@ -162,7 +158,7 @@ class TestInsertsOnlyDistributedIncrementalMaterialization(BaseIncremental):
@pytest.fixture(scope="class")
def models(self):
config_materialized_incremental = """
{{ config(order_by='(some_date, id, name)', inserts_only=True, materialized='distributed_incremental', primary_key='id', unique_key='id') }}
{{ config(order_by='(some_date, id, name)', inserts_only=True, materialized='distributed_incremental', unique_key='id') }}
"""
incremental_sql = config_materialized_incremental + model_incremental
return {
Expand All @@ -186,7 +182,7 @@ def test_incremental(self, project):


incremental_not_schema_change_sql = """
{{ config(materialized="distributed_incremental", primary_key="user_id_current_time", unique_key="user_id_current_time", on_schema_change="sync_all_columns") }}
{{ config(materialized="distributed_incremental", unique_key="user_id_current_time",on_schema_change="sync_all_columns") }}
select
toString(1) || '-' || toString(now64()) as user_id_current_time,
{% if is_incremental() %}
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/adapter/incremental/test_schema_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
{{
config(
materialized='%s',
primary_key='col_1',
unique_key='col_1',
on_schema_change='%s'
)
Expand Down Expand Up @@ -102,7 +101,6 @@ def test_append(self, project, model):
{{
config(
materialized='%s',
primary_key='col_1',
unique_key='col_1',
on_schema_change='%s'
)
Expand Down Expand Up @@ -191,7 +189,6 @@ def test_sync(self, project, model):
{{
config(
materialized='%s',
primary_key='col_1',
unique_key='col_1',
on_schema_change='fail'
)
Expand Down
Loading