Skip to content

Commit

Permalink
Add self reference for macro (#163)
Browse files Browse the repository at this point in the history
Co-authored-by: Lasse Benninga <lassebenninga@gmail.com>
  • Loading branch information
jeremyyeo and lassebenni authored Sep 21, 2022
1 parent ce3ee3e commit 410b219
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions macros/plugins/spark/get_external_build_plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
{% set build_plan = build_plan + dbt_external_tables.refresh_external_table(source_node) %}
{% endif %}

{% set recover_partitions = spark__recover_partitions(source_node) %}
{% if recover_partitions|length > 0 %}
{% set recover_partitions = dbt_external_tables.recover_partitions(source_node) %}
{% if recover_partitions %}
{% set build_plan = build_plan + [
recover_partitions
] %}
Expand Down
21 changes: 18 additions & 3 deletions macros/plugins/spark/helpers/recover_partitions.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{% macro spark__recover_partitions(source_node) %}
{# https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-alter-table.html #}

{% set ddl %}
{%- if source_node.external.partitions and source_node.external.using and source_node.external.using|lower != 'delta' -%}
ALTER TABLE {{ source(source_node.source_name, source_node.name) }} RECOVER PARTITIONS
{% set ddl %}
ALTER TABLE {{ source(source_node.source_name, source_node.name) }} RECOVER PARTITIONS
{% endset %}
{%- else -%}
{% set ddl = none %}
{%- endif -%}
{% endset %}

{{return(ddl)}}

{% endmacro %}

{% macro recover_partitions(source_node) %}
{{ return(adapter.dispatch('recover_partitions', 'dbt_external_tables')(source_node)) }}
{% endmacro %}

{% macro default__recover_partitions(source_node) %}
/*{#
We're dispatching this macro so that users can override it if required on other adapters
but this will work for spark/databricks.
#}*/

{{ exceptions.raise_not_implemented('recover_partitions macro not implemented for adapter ' + adapter.type()) }}
{% endmacro %}

0 comments on commit 410b219

Please sign in to comment.