diff --git a/dbt/include/risingwave/macros/adapters.sql b/dbt/include/risingwave/macros/adapters.sql index 45cc47f..2e64b6a 100644 --- a/dbt/include/risingwave/macros/adapters.sql +++ b/dbt/include/risingwave/macros/adapters.sql @@ -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 %} diff --git a/dbt/include/risingwave/macros/materializations/materialized_view.sql b/dbt/include/risingwave/macros/materializations/materialized_view.sql index 4471ece..88bf48d 100644 --- a/dbt/include/risingwave/macros/materializations/materialized_view.sql +++ b/dbt/include/risingwave/macros/materializations/materialized_view.sql @@ -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) %} diff --git a/dbt/include/risingwave/macros/materializations/materializedview.sql b/dbt/include/risingwave/macros/materializations/materializedview.sql index b72e5e0..1000ee0 100644 --- a/dbt/include/risingwave/macros/materializations/materializedview.sql +++ b/dbt/include/risingwave/macros/materializations/materializedview.sql @@ -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) %} diff --git a/dbt/include/risingwave/macros/materializations/table_with_connector.sql b/dbt/include/risingwave/macros/materializations/table_with_connector.sql index 9872466..5b4d58a 100644 --- a/dbt/include/risingwave/macros/materializations/table_with_connector.sql +++ b/dbt/include/risingwave/macros/materializations/table_with_connector.sql @@ -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) %}