Hi there
I am started exploring the model versioning feature
For Example
If i have table called CO2_EMISSIONS_BY_COUNTRY
For this particular model I created v1 and v2
v1
SELECT
CAST("Year" AS INTEGER) AS Year,
ENTITY AS Country,
CAST(NULLIF(Annual_CO2_emissions, '') AS FLOAT) AS TotalEmissions,
FROM SOURCE
v2
SELECT
CAST("Year" AS INTEGER) AS Year,
ENTITY AS Country,
CAST(NULLIF(Annual_CO2_emissions, '') AS FLOAT) AS TotalEmissions,
CAST(NULLIF(Per_capita_CO2_emissions, '') AS FLOAT) AS PerCapitaEmissions
FROM SOURCE
In version 2 i added new column PerCapitaEmissions
In schema.yml
version: 2
models:
- name: co2_emissions_by_country
description: CO2 Emission by different Country
latest_version: 2
versions:
- v: 1
columns:
- include: all
- v: 2
columns:
- include: all
config:
alias: co2_emissions_by_country
And also add this generate_alias_name macro
{% macro generate_alias_name(custom_alias_name=none, node=none) -%}
{% do return(adapter.dispatch('generate_alias_name', 'dbt')(custom_alias_name, node)) %}
{%- endmacro %}
{% macro default__generate_alias_name(custom_alias_name=none, node=none) -%}
{%- if custom_alias_name -%}
{{ custom_alias_name | trim }}
{%- elif node.version -%}
{{ return(node.name ~ "_v" ~ (node.version | replace(".", "_"))) }}
{%- else -%}
{{ node.name }}
{%- endif -%}
{%- endmacro %}
when run dbt run i am getting error. i am running this models for the first time.
20:48:48 Database Error in model co2_emissions_by_country (models/co2_emissions_by_country_v2.sql)
20:48:48 001998 (42710): SQL compilation error:
20:48:48 Object 'CO2_EMISSIONS_BY_COUNTRY' already exists as TABLE
20:48:48 compiled Code at target/run/data_transformations/models/co2_emissions_by_country_v2.sql
and i think it is caused by alias field
config:
alias: co2_emissions_by_country
but when removed all the models works fine like it will create
co2_emissions_by_country_v1 and co2_emissions_by_country_v2
successfully
can anyone please advice me regarding the above situation.
Thank you