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

Feat/clickhouse support #475

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Tox will take care of installing the dependencies for each environment, so you d
tox -e integration_snowflake # For the Snowflake tests
tox -e integration_databricks # For the Databricks tests
tox -e integration_bigquery # For the BigQuery tests
tox -e integration_clickhouse # For the Clickhouse tests
```

The Spark tests require installing the [ODBC driver](https://www.databricks.com/spark/odbc-drivers-download). On a Mac,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The package currently supports
- Google BigQuery :white_check_mark:
- Postgres :white_check_mark:
- SQL Server :white_check_mark:
- Clickhouse :white_check_mark:

Models included:

Expand Down
3 changes: 3 additions & 0 deletions integration_test_project/example-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export DBT_ENV_SECRET_DATABRICKS_TOKEN=
export DBT_ENV_SECRET_GCP_PROJECT=
export DBT_ENV_SPARK_DRIVER_PATH= # /Library/simba/spark/lib/libsparkodbc_sbu.dylib on a Mac
export DBT_ENV_SPARK_ENDPOINT= # The endpoint ID from the Databricks HTTP path
export DBT_ENV_SECRET_CLICKHOUSE_HOST=
export DBT_ENV_SECRET_CLICKHOUSE_USER=
export DBT_ENV_SECRET_CLICKHOUSE_PASSWORD=

# dbt environment variables, change these
export DBT_VERSION="1_5_0"
Expand Down
2 changes: 1 addition & 1 deletion integration_test_project/models/sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2

sources:
- name: dummy_source
database: "{% if target.type not in ('spark', 'databricks') %}{{ var('dbt_artifacts_database', target.database) }}{% endif %}"
database: "{% if target.type not in ('spark', 'databricks', 'clickhouse') %}{{ var('dbt_artifacts_database', target.database) }}{% endif %}"
schema: "{{ target.schema }}"
freshness:
error_after: {count: 24, period: hour}
Expand Down
8 changes: 8 additions & 0 deletions integration_test_project/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ dbt_artifacts:
Encrypt: False
user: dbt
password: "123"
clickhouse:
type: clickhouse
host: "{{ env_var('DBT_ENV_SECRET_CLICKHOUSE_HOST') }}"
port: 8123
user: "{{ env_var('DBT_ENV_SECRET_CLICKHOUSE_USER') }}"
password: "{{ env_var('DBT_ENV_SECRET_CLICKHOUSE_PASSWORD') }}"
schema: dbt_artifacts_test_commit_{{ env_var('DBT_VERSION', '') }}_{{ env_var('GITHUB_SHA_OVERRIDE', '') if env_var('GITHUB_SHA_OVERRIDE', '') else env_var('GITHUB_SHA') }}
threads: 8
69 changes: 69 additions & 0 deletions macros/database_specific_helpers/type_helpers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{{ return(api.Column.translate_type("boolean")) }}
{% endmacro %}

{% macro clickhouse__type_boolean() %}
Nullable(Boolean)
{% endmacro %}

{#- JSON -#}

{% macro type_json() %}
Expand All @@ -26,6 +30,10 @@
json
{% endmacro %}

{% macro clickhouse__type_json() %}
Nullable(String)
{% endmacro %}

{#- ARRAY -#}

{% macro type_array() %}
Expand All @@ -43,3 +51,64 @@
{% macro bigquery__type_array() %}
array<string>
{% endmacro %}

{% macro clickhouse__type_array() %}
Array(String)
{% endmacro %}

{#- STRING -#}

{% macro type_string() %}
{{ return(adapter.dispatch('type_string', 'dbt_artifacts')()) }}
{% endmacro %}

{% macro default__type_string() %}
{{ return(api.Column.translate_type("string")) }}
{% endmacro %}

{% macro clickhouse__type_string() %}
Nullable(String)
{% endmacro %}

{#- TIMESTAMP -#}

{% macro type_timestamp() %}
{{ return(adapter.dispatch('type_timestamp', 'dbt_artifacts')()) }}
{% endmacro %}

{% macro default__type_timestamp() %}
{{ return(api.Column.translate_type("timestamp")) }}
{% endmacro %}

{% macro clickhouse__type_timestamp() %}
Nullable(DateTime)
{% endmacro %}

{#- INT -#}

{% macro type_int() %}
{{ return(adapter.dispatch('type_int', 'dbt_artifacts')()) }}
{% endmacro %}

{% macro default__type_int() %}
{{ return(api.Column.translate_type("integer")) }}
{% endmacro %}

{% macro clickhouse__type_int() %}
Nullable(Int32)
{% endmacro %}

{#- FLOAT -#}

{% macro type_float() %}
{{ return(adapter.dispatch('type_float', 'dbt_artifacts')()) }}
{% endmacro %}

{% macro default__type_float() %}
{{ return(api.Column.translate_type("float")) }}
{% endmacro %}

{% macro clickhouse__type_float() %}
Nullable(Float32)
{% endmacro %}

4 changes: 4 additions & 0 deletions macros/upload_individual_datasets/upload_exposures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_exposures_dml_sql(exposures) -%}
{{ return(dbt_artifacts.postgres__get_exposures_dml_sql(exposures)) }}
{%- endmacro %}

3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_invocations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,6 @@

{% endmacro -%}

{% macro clickhouse__get_invocations_dml_sql() -%}
{{ return(dbt_artifacts.postgres__get_invocations_dml_sql()) }}
{% endmacro -%}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,6 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_model_executions_dml_sql(models) -%}
{{ return(dbt_artifacts.postgres__get_model_executions_dml_sql(models)) }}
{% endmacro -%}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_models_dml_sql(models) -%}
{{ return(dbt_artifacts.postgres__get_models_dml_sql(models)) }}
{%- endmacro %}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_seed_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_seed_executions_dml_sql(seeds) -%}
{{ return(dbt_artifacts.postgres__get_seed_executions_dml_sql(seeds)) }}
{%- endmacro %}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_seeds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_seeds_dml_sql(seeds) -%}
{{ return(dbt_artifacts.postgres__get_seeds_dml_sql(seeds)) }}
{%- endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_snapshot_executions_dml_sql(snapshots) -%}
{{ return(dbt_artifacts.postgres__get_snapshot_executions_dml_sql(snapshots)) }}
{%- endmacro %}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,6 @@
{% endif %}
{% endmacro -%}

{% macro clickhouse__get_snapshots_dml_sql(snapshots) -%}
{{ return(dbt_artifacts.postgres__get_snapshots_dml_sql(snapshots)) }}
{%- endmacro %}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
{% endif %}
{%- endmacro %}

{% macro clickhouse__get_sources_dml_sql(sources) -%}
{{ return(dbt_artifacts.postgres__get_sources_dml_sql(sources)) }}
{%- endmacro %}

{% macro sqlserver__get_sources_dml_sql(sources) -%}

Expand Down
4 changes: 3 additions & 1 deletion macros/upload_individual_datasets/upload_test_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@
{% endif %}
{% endmacro -%}


{% macro clickhouse__get_test_executions_dml_sql(tests) -%}
{{ return(dbt_artifacts.postgres__get_test_executions_dml_sql(tests)) }}
{%- endmacro %}
3 changes: 3 additions & 0 deletions macros/upload_individual_datasets/upload_tests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
{% endif %}
{%- endmacro %}

{% macro clickhouse__get_tests_dml_sql(tests) -%}
{{ return(dbt_artifacts.postgres__get_tests_dml_sql(tests)) }}
{%- endmacro %}

{% macro sqlserver__get_tests_dml_sql(tests) -%}

Expand Down
12 changes: 12 additions & 0 deletions macros/upload_results/insert_into_metadata_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@

{%- endmacro %}

{% macro clickhouse__insert_into_metadata_table(relation, fields, content) -%}

{% set insert_into_table_query %}
insert into {{ relation }} {{ fields }}
values
{{ content }}
{% endset %}

{% do run_query(insert_into_table_query) %}

{%- endmacro %}

{% macro default__insert_into_metadata_table(relation, fields, content) -%}
{%- endmacro %}

12 changes: 10 additions & 2 deletions models/sources/exposures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ select
, cast(null as {{ type_string() }}) as description
, cast(null as {{ type_string() }}) as url
, cast(null as {{ type_string() }}) as package_name
, cast(null as {{ type_array() }}) as depends_on_nodes
, cast(null as {{ type_array() }}) as tags
{% if target.type == "clickhouse" %}
, cast(null as {{ type_string() }}) as depends_on_nodes
{% else %}
, cast(null as {{ type_array() }}) as depends_on_nodes
{% endif %}
{% if target.type == "clickhouse" %}
, cast(null as {{ type_string() }}) as tags
{% else %}
, cast(null as {{ type_array() }}) as tags
{% endif %}
, cast(null as {{ type_json() }}) as all_results
from dummy_cte
where 1 = 0
12 changes: 10 additions & 2 deletions models/sources/models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ select
{% else %} schema
{% endif %},
cast(null as {{ type_string() }}) as name,
cast(null as {{ type_array() }}) as depends_on_nodes,
{% if target.type == "clickhouse" %}
cast(null as {{ type_string() }}) as depends_on_nodes,
{% else %}
cast(null as {{ type_array() }}) as depends_on_nodes,
{% endif %}
cast(null as {{ type_string() }}) as package_name,
cast(null as {{ type_string() }}) as path,
cast(null as {{ type_string() }}) as checksum,
cast(null as {{ type_string() }}) as materialization,
cast(null as {{ type_array() }}) as tags,
{% if target.type == "clickhouse" %}
cast(null as {{ type_string() }}) as tags,
{% else %}
cast(null as {{ type_array() }}) as tags,
{% endif %}
cast(null as {{ type_json() }}) as meta,
cast(null as {{ type_string() }}) as alias,
cast(null as {{ type_json() }}) as all_results
Expand Down
6 changes: 5 additions & 1 deletion models/sources/snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ select
{% else %} schema
{% endif %},
cast(null as {{ type_string() }}) as name,
cast(null as {{ type_array() }}) as depends_on_nodes,
{% if target.type == "clickhouse" %}
cast(null as {{ type_string() }}) as depends_on_nodes,
{% else %}
cast(null as {{ type_array() }}) as depends_on_nodes,
{% endif %}
cast(null as {{ type_string() }}) as package_name,
cast(null as {{ type_string() }}) as path,
cast(null as {{ type_string() }}) as checksum,
Expand Down
13 changes: 11 additions & 2 deletions models/sources/tests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ select
, cast(null as {{ type_string() }}) as node_id
, cast(null as {{ type_timestamp() }}) as run_started_at
, cast(null as {{ type_string() }}) as name
, cast(null as {{ type_array() }}) as depends_on_nodes
{% if target.type == "clickhouse" %}
, cast(null as {{ type_string() }}) as depends_on_nodes
{% else %}
, cast(null as {{ type_array() }}) as depends_on_nodes
{% endif %}
, cast(null as {{ type_string() }}) as package_name
, cast(null as {{ type_string() }}) as test_path
, cast(null as {{ type_array() }}) as tags
{% if target.type == "clickhouse" %}
, cast(null as {{ type_string() }}) as tags
{% else %}
, cast(null as {{ type_array() }}) as tags
{% endif %}
, cast(null as {{ type_json() }}) as all_results
from dummy_cte
where 1 = 0

4 changes: 3 additions & 1 deletion models/staging/stg_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ with
node_id,
run_started_at,
was_full_refresh,
{{ split_part("thread_id", "'-'", 2) }} as thread_id,
{% if target.type == "clickhouse" %} {{ split_part("coalesce(thread_id, '')", "'-'", 2) }} as thread_id,
{% else %} {{ split_part("thread_id", "'-'", 2) }} as thread_id,
{% endif %}
status,
compile_started_at,
query_completed_at,
Expand Down
4 changes: 3 additions & 1 deletion models/staging/stg_dbt__seed_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ with
node_id,
run_started_at,
was_full_refresh,
{{ split_part("thread_id", "'-'", 2) }} as thread_id,
{% if target.type == "clickhouse" %} {{ split_part("coalesce(thread_id, '')", "'-'", 2) }} as thread_id,
{% else %} {{ split_part("thread_id", "'-'", 2) }} as thread_id,
{% endif %}
status,
compile_started_at,
query_completed_at,
Expand Down
4 changes: 3 additions & 1 deletion models/staging/stg_dbt__snapshot_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ with
node_id,
run_started_at,
was_full_refresh,
{{ split_part("thread_id", "'-'", 2) }} as thread_id,
{% if target.type == "clickhouse" %} {{ split_part("coalesce(thread_id, '')", "'-'", 2) }} as thread_id,
{% else %} {{ split_part("thread_id", "'-'", 2) }} as thread_id,
{% endif %}
status,
compile_started_at,
query_completed_at,
Expand Down
5 changes: 4 additions & 1 deletion models/staging/stg_dbt__test_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ with
, node_id
, run_started_at
, was_full_refresh
, {{ split_part('thread_id', "'-'", 2) }} as thread_id
,
{% if target.type == "clickhouse" %} {{ split_part("coalesce(thread_id, '')", "'-'", 2) }} as thread_id
{% else %} {{ split_part("thread_id", "'-'", 2) }} as thread_id
{% endif %}
, status
, compile_started_at
, query_completed_at
Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ passenv =
DBT_ENV_SECRET_GCP_PROJECT
DBT_ENV_SPARK_DRIVER_PATH
DBT_ENV_SPARK_ENDPOINT
DBT_ENV_SECRET_CLICKHOUSE_HOST
DBT_ENV_SECRET_CLICKHOUSE_USER
DBT_ENV_SECRET_CLICKHOUSE_PASSWORD
GOOGLE_APPLICATION_CREDENTIALS
DBT_CLOUD_PROJECT_ID
DBT_CLOUD_JOB_ID
Expand Down Expand Up @@ -430,3 +433,11 @@ commands =
dbt clean
dbt deps
dbt build --target sqlserver

[testenv:integration_clickhouse]
changedir = integration_test_project
deps = dbt-clickhouse~=1.8.0
commands =
dbt clean
dbt deps
dbt build --target clickhouse
Loading