forked from databricks/dbt-databricks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
passing fixtures
- Loading branch information
Showing
3 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{% macro databricks__can_clone_table() %} | ||
{{ return(True) }} | ||
{% endmacro %} | ||
|
||
{% macro databricks__create_or_replace_clone(this_relation, defer_relation) %} | ||
create or replace | ||
table {{ this_relation }} | ||
shallow clone {{ defer_relation }} | ||
{% endmacro %} | ||
|
||
{%- materialization clone, adapter='databricks' -%} | ||
|
||
{%- set relations = {'relations': []} -%} | ||
|
||
{%- if not defer_relation -%} | ||
-- nothing to do | ||
{{ log("No relation found in state manifest for " ~ model.unique_id, info=True) }} | ||
{{ return(relations) }} | ||
{%- endif -%} | ||
|
||
{%- set existing_relation = load_cached_relation(this) -%} | ||
|
||
{%- if existing_relation and not flags.FULL_REFRESH -%} | ||
-- noop! | ||
{{ log("Relation " ~ existing_relation ~ " already exists", info=True) }} | ||
{{ return(relations) }} | ||
{%- endif -%} | ||
|
||
{%- set other_existing_relation = load_cached_relation(defer_relation) -%} | ||
{%- set file_format = config.get('file_format', validator=validation.any[basestring]) -%} | ||
|
||
-- If this is a database that can do zero-copy cloning of tables, and the other relation is a table, then this will be a table | ||
-- Otherwise, this will be a view | ||
|
||
{% set can_clone_table = can_clone_table() %} | ||
|
||
{%- if other_existing_relation and other_existing_relation.type == 'table' and can_clone_table -%} | ||
|
||
{%- set target_relation = this.incorporate(type='table') -%} | ||
{% if existing_relation is not none and not existing_relation.is_table %} | ||
{{ log("Dropping relation " ~ existing_relation ~ " because it is of type " ~ existing_relation.type) }} | ||
{{ drop_relation_if_exists(existing_relation) }} | ||
{% endif %} | ||
|
||
-- as a general rule, data platforms that can clone tables can also do atomic 'create or replace' | ||
{% call statement('main') %} | ||
{{ create_or_replace_clone(target_relation, defer_relation) }} | ||
{% endcall %} | ||
|
||
{% set should_revoke = should_revoke(existing_relation, full_refresh_mode=True) %} | ||
{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %} | ||
{% do persist_docs(target_relation, model) %} | ||
|
||
{{ return({'relations': [target_relation]}) }} | ||
|
||
{%- else -%} | ||
|
||
{%- set target_relation = this.incorporate(type='view') -%} | ||
|
||
-- reuse the view materialization | ||
-- TODO: support actual dispatch for materialization macros | ||
-- Tracking ticket: https://github.com/dbt-labs/dbt-core/issues/7799 | ||
{% set search_name = "materialization_view_" ~ adapter.type() %} | ||
{% if not search_name in context %} | ||
{% set search_name = "materialization_view_default" %} | ||
{% endif %} | ||
{% set materialization_macro = context[search_name] %} | ||
{% set relations = materialization_macro() %} | ||
{{ return(relations) }} | ||
{% endif %} | ||
|
||
{%- endmaterialization -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ pytz | |
tox>=3.2.0 | ||
types-requests | ||
|
||
dbt-spark==1.6.0rc1 | ||
dbt-core==1.6.0rc1 | ||
dbt-tests-adapter==1.6.0rc1 | ||
# git+https://github.com/dbt-labs/[email protected]#egg=dbt-spark | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
from dbt.tests.adapter.dbt_clone.test_dbt_clone import BaseClonePossible | ||
|
||
|
||
class TestDatabricksClonePossible(BaseClonePossible): | ||
@pytest.fixture(autouse=True) | ||
def clean_up(self, project): | ||
yield | ||
with project.adapter.connection_named("__test"): | ||
relation = project.adapter.Relation.create( | ||
database=project.database, schema=f"{project.test_schema}_seeds" | ||
) | ||
project.adapter.drop_schema(relation) | ||
|
||
relation = project.adapter.Relation.create( | ||
database=project.database, schema=project.test_schema | ||
) | ||
project.adapter.drop_schema(relation) | ||
|
||
pass |