|
8 | 8 | DROP MATERIALIZED VIEW {{ relation }} |
9 | 9 | {%- endmacro %} |
10 | 10 |
|
11 | | -{% macro oracle__get_replace_materialized_view_as_sql(relation, sql, existing_relation, backup_relation, intermediate_relation) %} |
12 | | - {{ oracle__drop_relation(existing_relation) }} |
13 | | - {{ oracle__get_create_materialized_view_as_sql(relation, sql) }} |
14 | | -{% endmacro %} |
15 | 11 |
|
16 | 12 | {% macro oracle__get_create_materialized_view_as_sql(relation, sql) %} |
17 | 13 | {%- set materialized_view = relation.from_runtime_config(config) -%} |
|
30 | 26 | backup_relation, |
31 | 27 | intermediate_relation |
32 | 28 | ) %} |
33 | | - |
34 | | - -- apply a full refresh immediately if needed |
35 | 29 | {% if configuration_changes.requires_full_refresh %} |
36 | | - |
37 | | - {{ get_replace_materialized_view_as_sql(relation, sql, existing_relation, backup_relation, intermediate_relation) }} |
38 | | - |
39 | | - -- otherwise apply individual changes as needed |
| 30 | + {{- log('Applying REPLACE to: ' ~ existing_relation ) -}} |
| 31 | + {{ oracle__drop_relation(existing_relation) }} |
| 32 | + {{ oracle__get_create_materialized_view_as_sql(relation, sql) }} |
40 | 33 | {% else %} |
41 | 34 |
|
42 | 35 | {%- set refresh_method = configuration_changes.refresh_method -%} |
|
80 | 73 | {% do return({'materialized_view': _materialized_view}) %} |
81 | 74 | {%- endmacro %} |
82 | 75 |
|
| 76 | + |
| 77 | +{% macro materialized_view_get_build_sql(existing_relation, target_relation, backup_relation, intermediate_relation) %} |
| 78 | + |
| 79 | + {% set full_refresh_mode = should_full_refresh() %} |
| 80 | + |
| 81 | + -- determine the scenario we're in: create, full_refresh, alter, refresh data |
| 82 | + {% if existing_relation is none %} |
| 83 | + {% set build_sql = get_create_materialized_view_as_sql(target_relation, sql) %} |
| 84 | + {% elif full_refresh_mode or not existing_relation.is_materialized_view %} |
| 85 | + {{- log('Applying REPLACE to: ' ~ existing_relation ) -}} |
| 86 | + {{ oracle__drop_relation(existing_relation) }} |
| 87 | + {% set build_sql = oracle__get_create_materialized_view_as_sql(target_relation, sql) %} |
| 88 | + {% else %} |
| 89 | + |
| 90 | + -- get config options |
| 91 | + {% set on_configuration_change = config.get('on_configuration_change') %} |
| 92 | + {% set configuration_changes = get_materialized_view_configuration_changes(existing_relation, config) %} |
| 93 | + |
| 94 | + {% if configuration_changes is none %} |
| 95 | + {% set build_sql = refresh_materialized_view(target_relation) %} |
| 96 | + |
| 97 | + {% elif on_configuration_change == 'apply' %} |
| 98 | + {% set build_sql = get_alter_materialized_view_as_sql(target_relation, configuration_changes, sql, existing_relation, backup_relation, intermediate_relation) %} |
| 99 | + {% elif on_configuration_change == 'continue' %} |
| 100 | + {% set build_sql = '' %} |
| 101 | + {{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for `" ~ target_relation ~ "`") }} |
| 102 | + {% elif on_configuration_change == 'fail' %} |
| 103 | + {{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for `" ~ target_relation ~ "`") }} |
| 104 | + |
| 105 | + {% else %} |
| 106 | + -- this only happens if the user provides a value other than `apply`, 'skip', 'fail' |
| 107 | + {{ exceptions.raise_compiler_error("Unexpected configuration scenario") }} |
| 108 | + |
| 109 | + {% endif %} |
| 110 | + |
| 111 | + {% endif %} |
| 112 | + |
| 113 | + {% do return(build_sql) %} |
| 114 | + |
| 115 | +{% endmacro %} |
0 commit comments