Skip to content

Commit

Permalink
Merge pull request #67 from Gemma-Analytics/fixing-bug-in-database-check
Browse files Browse the repository at this point in the history
Adding explicit check for whether model is enabled and which database is used
  • Loading branch information
soltanianalytics authored Nov 5, 2024
2 parents 7c6d831 + 6bb9eff commit 81012af
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions models/gemma_fx.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{{ config(enabled=var("gemma:fx:enabled")) }}

{% if target.type == 'postgres' | as_bool() %}
/*
At each dbt invocation, dbt reads all projce-related files and constructs a "manifest",
used to build the DAG later on. During parsing, Jinja statements like config(), ref()
or source() are evaluated. Thus, during parsing, dbt will evaluate the if-else
statements in this model, irrespective of whether the model is enabled or not and
whether it is actually called or not.
We explicitly check for whether the model is enabled, so that we can trigger an
exception if the model is enabled, but an unsupported adapter is used.
*/
{% if var("gemma:fx:enabled") and target.type == 'postgres' | as_bool() %}

WITH rates AS (

Expand Down Expand Up @@ -81,7 +91,7 @@ WITH rates AS (
SELECT * FROM final
ORDER BY date DESC, fx_currency ASC

{% elif target.type == 'snowflake' | as_bool() %}
{% elif var("gemma:fx:enabled") and target.type == 'snowflake' | as_bool() %}

WITH rates AS (

Expand Down Expand Up @@ -163,8 +173,8 @@ ORDER BY date DESC, fx_currency ASC
SELECT * FROM final
ORDER BY date DESC, fx_currency ASC

{% else %}
{% elif var("gemma:fx:enabled") %}

{% do exceptions.raise_compiler_error("This DB is not supported in gemma_fx model") %}
{% do exceptions.raise_compiler_error(target.type ~ " is not supported in gemma_fx model") %}

{% endif %}

0 comments on commit 81012af

Please sign in to comment.