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

drop bespoke mat, intro simpler macros #1

Merged
merged 1 commit into from
Oct 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

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) -}}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Databricks doesn't have traditional indexes.

{%- 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 }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MVs in Databricks cannot be renamed. What should we do instead?

{% endmacro %}
Loading