Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230303-112519.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: allow adapters to change model name resolution in py models
time: 2023-03-03T11:25:19.276637-08:00
custom:
Author: colin-rogers-dbt
Issue: "7114"
16 changes: 13 additions & 3 deletions core/dbt/include/global_project/macros/python_model/python.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{% macro resolve_model_name(input_model_name) %}

{{ return(adapter.dispatch('resolve_model_name', 'dbt')(input_model_name)) }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is actually the first time I see dispatch being implemented since I join

{% endmacro %}

{% macro default__resolve_model_name(input_model_name) %}

return input_model_name | string | replace('"', '\"')
{% endmacro %}

{% macro build_ref_function(model) %}

{%- set ref_dict = {} -%}
{%- for _ref in model.refs -%}
{%- set resolved = ref(*_ref) -%}
{%- do ref_dict.update({_ref | join("."): resolved | string | replace('"', '\"')}) -%}
{%- do ref_dict.update({_ref | join("."): resolve_model_name(resolved)}) -%}
{%- endfor -%}

def ref(*args,dbt_load_df_function):
Expand All @@ -18,7 +28,7 @@ def ref(*args,dbt_load_df_function):
{%- set source_dict = {} -%}
{%- for _source in model.sources -%}
{%- set resolved = source(*_source) -%}
{%- do source_dict.update({_source | join("."): resolved | string | replace('"', '\"')}) -%}
{%- do source_dict.update({_source | join("."): resolve_model_name(resolved)}) -%}
{%- endfor -%}

def source(*args, dbt_load_df_function):
Expand Down Expand Up @@ -65,7 +75,7 @@ class this:
database = "{{ this.database }}"
schema = "{{ this.schema }}"
identifier = "{{ this.identifier }}"
{% set this_relation_name = this | string | replace('"', '\\"') %}
{% set this_relation_name = resolve_model_name(this) %}
def __repr__(self):
return "{{ this_relation_name }}"

Expand Down