Skip to content

Commit

Permalink
feat: add create_indexes on table_with_connector and handle on_config…
Browse files Browse the repository at this point in the history
…uration_change (#51)
  • Loading branch information
MattiasMTS authored Oct 18, 2024
1 parent 5694efe commit affca43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 45 deletions.
28 changes: 28 additions & 0 deletions dbt/include/risingwave/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,31 @@
rows_affected="-1"
) %}
{% endmacro %}

{% macro risingwave__handle_on_configuration_change(old_relation, target_relation) %}
{#
This macro is used to handle the `on_configuration_change` configuration option.
It works both for `table_with_connector`, `table` and `materialized_view` materializations.
#}

{% set on_configuration_change = config.get('on_configuration_change', "continue") %}
{% set configuration_changes = get_materialized_view_configuration_changes(old_relation, config) %}

{% if configuration_changes is none %}
-- do nothing
{{ risingwave__execute_no_op(target_relation) }}
{% elif on_configuration_change == 'apply' %}
{% call statement('main') -%}
{{ risingwave__update_indexes_on_materialized_view(target_relation, configuration_changes.indexes) }}
{%- endcall %}
{% elif on_configuration_change == 'continue' %}
-- do nothing but a warning
{{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for {}".format(target_relation)) }}
{{ risingwave__execute_no_op(target_relation) }}
{% elif on_configuration_change == 'fail' %}
{{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for {}".format(target_relation)) }}
{% else %}
-- this only happens if the user provides a value other than `apply`, 'continue', 'fail'
{{ exceptions.raise_compiler_error("Unexpected configuration scenario") }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,7 @@

{{ create_indexes(target_relation) }}
{% else %}
-- get config options
{% set on_configuration_change = config.get('on_configuration_change', "continue") %}
{% set configuration_changes = get_materialized_view_configuration_changes(old_relation, config) %}

{% if configuration_changes is none %}
-- do nothing
{{ materialized_view_execute_no_op(target_relation) }}
{% elif on_configuration_change == 'apply' %}
{% call statement('main') -%}
{{ risingwave__update_indexes_on_materialized_view(target_relation, configuration_changes.indexes) }}
{%- endcall %}
{% elif on_configuration_change == 'continue' %}
-- do nothing but a warn
{{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for `" ~ target_relation ~ "`") }}
{{ materialized_view_execute_no_op(target_relation) }}
{% elif on_configuration_change == 'fail' %}
{{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for `" ~ target_relation ~ "`") }}
{% else %}
-- this only happens if the user provides a value other than `apply`, 'continue', 'fail'
{{ exceptions.raise_compiler_error("Unexpected configuration scenario") }}

{% endif %}
{{ risingwave__handle_on_configuration_change(old_relation, target_relation) }}
{% endif %}

{% do persist_docs(target_relation, model) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,7 @@

{{ create_indexes(target_relation) }}
{% else %}
-- get config options
{% set on_configuration_change = config.get('on_configuration_change', "continue") %}
{% set configuration_changes = get_materialized_view_configuration_changes(old_relation, config) %}

{% if configuration_changes is none %}
-- do nothing
{{ materialized_view_execute_no_op(target_relation) }}
{% elif on_configuration_change == 'apply' %}
{% call statement('main') -%}
{{ risingwave__update_indexes_on_materialized_view(target_relation, configuration_changes.indexes) }}
{%- endcall %}
{% elif on_configuration_change == 'continue' %}
-- do nothing but a warn
{{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for `" ~ target_relation ~ "`") }}
{{ materialized_view_execute_no_op(target_relation) }}
{% elif on_configuration_change == 'fail' %}
{{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for `" ~ target_relation ~ "`") }}
{% else %}
-- this only happens if the user provides a value other than `apply`, 'continue', 'fail'
{{ exceptions.raise_compiler_error("Unexpected configuration scenario") }}

{% endif %}
{{ risingwave__handle_on_configuration_change(old_relation, target_relation) }}
{% endif %}

{% do persist_docs(target_relation, model) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
{% call statement('main') -%}
{{ risingwave__run_sql(sql) }}
{%- endcall %}

{{ create_indexes(target_relation) }}
{% else %}
{{ risingwave__execute_no_op(target_relation) }}
{{ risingwave__handle_on_configuration_change(old_relation, target_relation) }}
{% endif %}

{% do persist_docs(target_relation, model) %}
Expand Down

0 comments on commit affca43

Please sign in to comment.