Skip to content

Commit

Permalink
Merge pull request #33 from wusanny/my_new_branch
Browse files Browse the repository at this point in the history
My new branch
  • Loading branch information
wusanny authored Nov 18, 2024
2 parents 70de51e + 9295077 commit b973ce0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ models:
# warn_error_options:
# include: # Previously called "include"
# - NoNodesForSelectionCriteria


40 changes: 40 additions & 0 deletions macros/generate_alias_name.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% macro generate_alias_name(custom_alias_name=none, node=none) -%}

{%- if custom_alias_name is none -%}

{% set tier_folder_name = node.fqn[1] %}
{% set function_folder_name = node.fqn[2] %}
{% set model_name = node.name %}
{% set schema_name = node.config.get('schema') %}

{#
2. Generate the alias name based on the target name.
(1) For "deploy" target:
Use the model name as the table name
Examples:
a. <schema>.client_private_api_crud_requests
b. <schema>.marketing_contribution
b. <schema>.adv_filter_use_by_base_day
(2) For "dev", "development", "default", "ci" targets:
The table name is prefixed with the tier/function folder name, and suffixed with value of env "DBT_DEV_TABLE_SUFFIX"
Examples:
a. ds_dev.<schema>__client_private_api_crud_requests{DBT_DEV_TABLE_SUFFIX}
b. ds_dev.<schema>__marketing_contribution{DBT_DEV_TABLE_SUFFIX}
b. ds_dev.<schema>__adv_filter_use_by_base_day{DBT_DEV_TABLE_SUFFIX}
(3) For all other targets, raise an error
#}
{% if target.name == 'deploy' %}
{% set destination_model_name = model_name -%}
{% elif target.name == 'dev' or target.name == 'development' or target.name == 'default' or target.name == 'ci' %}
{% set destination_model_name = schema_name ~ '__' ~ model_name -%}
{% else %}
{% do exceptions.warn("Invalid `target` in generate_alias_name macro. Got: " ~ target.name) %}
{% endif %}
{%- else -%}
{% set destination_model_name = custom_alias_name | trim -%}
{%- endif -%}

{{ log("model " ~ node.fqn[1:] ~ " will be created as: " ~ destination_model_name, info=True) }}
{{ destination_model_name }}

{%- endmacro %}
1 change: 1 addition & 0 deletions models/first_layer/second_layer/bar.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from {{ref("foo")}}
1 change: 1 addition & 0 deletions models/first_layer/second_layer/foo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
8 changes: 8 additions & 0 deletions models/sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2

sources:
- name: dbt_sprawira
database: development
schema: dbt_sprawira
tables:
- name: dev_source
1 change: 0 additions & 1 deletion models/two/two.sql

This file was deleted.

1 change: 1 addition & 0 deletions models/wait_long.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select system$wait(240) as c
1 change: 0 additions & 1 deletion package-lock.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
packages:
- package: dbt-labs/dbt_utils
version: 1.1.1
sha1_hash: a158c48c59c2bb7d729d2a4e215aabe5bb4f3353

0 comments on commit b973ce0

Please sign in to comment.