support dynamic variables in Python models | [CT-1450] [Bug] Unable to create python model for use across BigQuery and Databricks due to submission_method var #6190
Replies: 2 comments 1 reply
-
@pgoslatara Thanks for opening! (Sorry I pressed "close" by accident while typing!) I see this code here in your linked demo (neat!): # if profile_type == "bigquery":
# dbt.config(
# submission_method="cluster"
# )
dbt.config(
materialized="incremental",
packages=["requests"],
unique_key=["currency_code", "date"],
# submission_method="cluster"
) This is a rougher edge of Python models right now. dbt doesn't support more complex configuration (like ternary operators / conditional expressions) within Python code. Why? All parse-time attributes ( Here's something you can do: # models/config.yml
version: 2
models:
- name: dbt_currency_exchange_rates
config:
submission_method: "{{ 'cluster' if target.type == 'bigquery' else 'all_purpose_cluster' }}" Short of supporting actual execution of user Python code, I'm not sure how we should seek to support this in a more ergonomic way / with in-model code only. |
Beta Was this translation helpful? Give feedback.
-
converted to a discussion to keep this more searchable and crowd-source ideas on how we can go about fixing this. related issue: #5887 in short, how do we support dynamically generated strings and variables in Python models? we do not want to run user-space Python code within dbt |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is this a new bug in dbt-core?
Current Behavior
I'm developing a package that includes a python model that runs on all three supported databases (BigQuery, Databricks, Snowflake). Running on BigQuery requires a "submission_method" config to be "cluster" to run on a dedicated Dataproc cluster. Issue is that by including this I can no longer run the same model on Databricks as I get the following error message:
I believe the error is related to this line, although I'm not sure of the intention of this check.
Expected Behavior
A python model can run across all supported databases with any desired config values.
Steps To Reproduce
bigquery_support
branch from the dbt-currency-exchange-rates repo.dbt deps
.dbt build -t bigquery
. Succeeds.dbt build -t snowflake
. Succeeds.dbt build -t databricks
. Fails.Relevant log output
Environment
- OS: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.5 LTS Release: 20.04 Codename: focal
Beta Was this translation helpful? Give feedback.
All reactions