Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1526 from fishtown-analytics/fix/refs-in-run-oper…
…ations Add ref and source support to run-operation macros (#1507)
- Loading branch information
Showing
11 changed files
with
182 additions
and
100 deletions.
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
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
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,29 @@ | ||
import dbt.context.common | ||
from dbt.context import runtime | ||
from dbt.exceptions import raise_compiler_error | ||
|
||
|
||
class RefResolver(runtime.BaseRefResolver): | ||
def __call__(self, *args): | ||
# When you call ref(), this is what happens at operation runtime | ||
target_model, name = self.resolve(args) | ||
return self.create_relation(target_model, name) | ||
|
||
def create_ephemeral_relation(self, target_model, name): | ||
# In operations, we can't ref() ephemeral nodes, because ParsedMacros | ||
# do not support set_cte | ||
raise_compiler_error( | ||
'Operations can not ref() ephemeral nodes, but {} is ephemeral' | ||
.format(target_model.name), | ||
self.model | ||
) | ||
|
||
|
||
class Provider(runtime.Provider): | ||
ref = RefResolver | ||
|
||
|
||
def generate(model, runtime_config, manifest): | ||
return dbt.context.common.generate_execute_macro( | ||
model, runtime_config, manifest, Provider() | ||
) |
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
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
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
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
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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
{% macro override_me() -%} | ||
{{ exceptions.raise_compiler_error('this is a bad macro') }} | ||
{{ exceptions.raise_compiler_error('this is a bad macro') }} | ||
{%- endmacro %} | ||
|
||
{% macro happy_little_macro() -%} | ||
{{ override_me() }} | ||
{{ override_me() }} | ||
{%- endmacro %} | ||
|
||
|
||
{% macro vacuum_source(source_name, table_name) -%} | ||
{% call statement('stmt', auto_begin=false, fetch_result=false) %} | ||
vacuum {{ source(source_name, table_name) }} | ||
{% endcall %} | ||
{%- endmacro %} |
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
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
Oops, something went wrong.