Skip to content

Commit

Permalink
drop bespoke mat, intro simpler macros
Browse files Browse the repository at this point in the history
  • Loading branch information
dataders committed Oct 11, 2023
1 parent 0f6c616 commit e7c15a2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 59 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% macro databricks__get_alter_materialized_view_as_sql(
relation,
configuration_changes,
sql,
existing_relation,
backup_relation,
intermediate_relation
) %}

-- apply a full refresh immediately if needed
{% if configuration_changes.requires_full_refresh %}

{{ get_replace_sql(existing_relation, relation, sql) }}

-- otherwise apply individual changes as needed
{% else %}

{{ databricks__update_indexes_on_materialized_view(relation, configuration_changes.indexes) }}

{%- endif -%}

{% endmacro %}


{%- macro databricks__update_indexes_on_materialized_view(relation, index_changes) -%}
{{- log("Applying UPDATE INDEXES to: " ~ relation) -}}

{%- for _index_change in index_changes -%}
{%- set _index = _index_change.context -%}

{%- if _index_change.action == "drop" -%}

{{ databricks__get_drop_index_sql(relation, _index.name) }};

{%- elif _index_change.action == "create" -%}

{{ databricks__get_create_index_sql(relation, _index.as_node_config) }}

{%- endif -%}

{%- endfor -%}

{%- endmacro -%}


{% macro databricks__get_materialized_view_configuration_changes(existing_relation, new_config) %}
{% set _existing_materialized_view = databricks__describe_materialized_view(existing_relation) %}
{% set _configuration_changes = existing_relation.get_materialized_view_config_change_collection(_existing_materialized_view, new_config) %}
{% do return(_configuration_changes) %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% macro databricks__get_create_materialized_view_as_sql(relation, sql) %}
create materialized view if not exists {{ relation }} as {{ sql }};

{% for _index_dict in config.get('indexes', []) -%}
{{- get_create_index_sql(relation, _index_dict) -}}
{%- endfor -%}

{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro databricks__describe_materialized_view(relation) %}
-- for now just get the indexes, we don't need the name or the query yet
{% set _indexes = run_query(get_show_indexes_sql(relation)) %}
{% do return({'indexes': _indexes}) %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro databricks__drop_materialized_view(relation) -%}
drop materialized view if exists {{ relation }} cascade
{%- endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro databricks__refresh_materialized_view(relation) %}
refresh materialized view {{ relation }}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro databricks__get_rename_materialized_view_sql(relation, new_name) %}
alter materialized view {{ relation }} rename to {{ new_name }}
{% endmacro %}

0 comments on commit e7c15a2

Please sign in to comment.