Skip to content

Commit

Permalink
Merge pull request #5 from Snowflake-Labs/4-doesnt-work-when-name-=-a…
Browse files Browse the repository at this point in the history
…lias

Updated to support alias
  • Loading branch information
sfc-gh-dflippo authored Jun 4, 2022
2 parents abdffed + 17b466d commit 5edf2e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions integration_tests/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ models:
column_name: p_partkey

- name: dim_customers
# Test support for alias
config:
alias: dim_customer
description: "Customer dimension"
columns:
- name: c_custkey
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/models/sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sources:
tests:
- not_null
- relationships:
to: source('tpc_h', 'CUSTOMER')
to: source('tpc_h', 'customer')
field: c_custkey

- name: customer
Expand Down
7 changes: 4 additions & 3 deletions macros/create_constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
| selectattr("resource_type", "equalto", "source")
| selectattr("unique_id", "in", test_model.depends_on.nodes) -%}

{%- do node.update({'alias': node.alias or node.name }) -%}
{#- Append to our list of models for this test -#}
{%- do table_models.append(node) -%}
{#- If we are using a sources, we will need to verify permissions -#}
Expand Down Expand Up @@ -202,7 +203,7 @@
{%- set table_relation = adapter.get_relation(
database=table_models[0].database,
schema=table_models[0].schema,
identifier=table_models[0].name) -%}
identifier=table_models[0].alias ) -%}
{%- if dbt_constraints.table_columns_all_exist(table_relation, column_names) -%}
{%- if test_model.test_metadata.name == "primary_key" -%}
{%- do dbt_constraints.create_primary_key(table_relation, column_names, ns.verify_permissions, quote_columns) -%}
Expand Down Expand Up @@ -242,12 +243,12 @@
{%- set fk_table_relation = adapter.get_relation(
database=fk_model.database,
schema=fk_model.schema,
identifier=fk_model.name) -%}
identifier=fk_model.alias) -%}

{%- set pk_table_relation = adapter.get_relation(
database=pk_model.database,
schema=pk_model.schema,
identifier=pk_model.name) -%}
identifier=pk_model.alias) -%}

{# Attempt to identify parameters we can use for the column names #}
{%- set pk_column_names = [] -%}
Expand Down

0 comments on commit 5edf2e9

Please sign in to comment.