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

Updates to support a broader class of incremental functionality #181

Merged
merged 2 commits into from
Jun 12, 2023
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
8 changes: 0 additions & 8 deletions dbt/include/duckdb/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,6 @@ def materialize(df, con):
{% do return(get_incremental_delete_insert_sql(arg_dict)) %}
{% endmacro %}

{% macro duckdb__get_incremental_delete_insert_sql(arg_dict) %}
{% do return(get_delete_insert_merge_sql(arg_dict["target_relation"].include(database=adapter.use_database()), arg_dict["temp_relation"], arg_dict["unique_key"], arg_dict["dest_columns"])) %}
{% endmacro %}

{% macro duckdb__get_incremental_append_sql(arg_dict) %}
{% do return(get_insert_into_sql(arg_dict["target_relation"].include(database=adapter.use_database()), arg_dict["temp_relation"], arg_dict["dest_columns"])) %}
{% endmacro %}

{% macro location_exists(location) -%}
{% do return(adapter.location_exists(location)) %}
{% endmacro %}
Expand Down
23 changes: 23 additions & 0 deletions dbt/include/duckdb/macros/columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% macro duckdb__alter_relation_add_remove_columns(relation, add_columns, remove_columns) %}

{% if add_columns %}
{% for column in add_columns %}
{% set sql -%}
alter {{ relation.type }} {{ relation }} add column
{{ column.name }} {{ column.data_type }}
{%- endset -%}
{% do run_query(sql) %}
{% endfor %}
{% endif %}

{% if remove_columns %}
{% for column in remove_columns %}
{% set sql -%}
alter {{ relation.type }} {{ relation }} drop column
{{ column.name }}
{%- endset -%}
{% do run_query(sql) %}
{% endfor %}
{% endif %}

{% endmacro %}
4 changes: 2 additions & 2 deletions dbt/include/duckdb/macros/materializations/incremental.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

{#-- Get the incremental_strategy, the macro to use for the strategy, and build the sql --#}
{% set incremental_strategy = config.get('incremental_strategy') or 'default' %}
{% set incremental_predicates = config.get('incremental_predicates', none) %}
{% set incremental_predicates = config.get('predicates', none) or config.get('incremental_predicates', none) %}
{% set strategy_sql_macro_func = adapter.get_incremental_strategy_macro(context, incremental_strategy) %}
{% set strategy_arg_dict = ({'target_relation': target_relation, 'temp_relation': temp_relation, 'unique_key': unique_key, 'dest_columns': dest_columns, 'predicates': incremental_predicates }) %}
{% set strategy_arg_dict = ({'target_relation': target_relation, 'temp_relation': temp_relation, 'unique_key': unique_key, 'dest_columns': dest_columns, 'incremental_predicates': incremental_predicates }) %}
{% set build_sql = strategy_sql_macro_func(strategy_arg_dict) %}
{% set language = "sql" %}

Expand Down
16 changes: 15 additions & 1 deletion tests/functional/adapter/test_incremental.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
from dbt.tests.adapter.incremental.test_incremental_unique_id import (
BaseIncrementalUniqueKey,
)
from dbt.tests.adapter.incremental.test_incremental_predicates import (
BaseIncrementalPredicates,
)
from dbt.tests.adapter.incremental.test_incremental_on_schema_change import (
BaseIncrementalOnSchemaChange,
)


class TestIncrementalUniqueKey(BaseIncrementalUniqueKey):
pass


class TestIncrementalPredicates(BaseIncrementalPredicates):
pass


class TestBaseIncrementalUniqueKey(BaseIncrementalUniqueKey):
class TestIncrementalOnSchemaChange(BaseIncrementalOnSchemaChange):
pass