-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-2700] [Feature] Support "dynamic" configs (i.e. retrieving state from database before parsing node configs) #7868
Comments
There is a fundamental order of operations to dbt: It must be possible to know the shape of the DAG & configuration of its nodes—what's enabled, what's materialized as what—simply by parsing configuration and project code, before running any database queries (dynamic state). This foundational assumption gets us a lot of mileage. I totally hear the many (advanced) use cases for this. Rather than dynamically setting configs during parse time, for configurations that are actually applied at runtime, I'd rather we made it possible to override (define custom behavior for) the mechanism for applying those configs at runtime. In the case of -- snapshots/some_large_snapshot.sql
{% snapshot some_large_snapshot %}
{{ config(..., snowflake_warehouse = 'dynamic' ) }}
select ...
-- macros/snowflake_warehouse.sql
{% macro snowflake_warehouse(snowflake_warehouse, node) %}
{% if snowflake_warehouse == 'dynamic' %}
{% set already_exists = adapter.get_relation(node.database, node.schema, node.identifier) %}
{% if already_exists %}
{{ return('small') }}
{% else %}
{{ return('large') }}
{% endif %}
{% else %}
{{ return(snowflake_warehouse) }}
{% endmacro %} |
I appreciate having this open as a standalone feature request! I'm going to close it as Other approaches for enabling the same use case:
|
Macro does seem the better way to solve this. A call such as this worked for me: |
Is this your first time submitting a feature request?
Describe the feature
There's already going to be similar threads around this topic so feel free to close in favour of others. Since I was not able to find one (and after some discussions with Jerco), I've decided to file this as an independent feature request.
Basically dbt should have a way to fetch some state information (think
adapter.get_relation(this)
,some sql to check if a table has some value
, etc) prior to determining configuration (enabled
,snowflake_warehouse
, etc) of a node.A Snowflake example where we might want to switch up the warehouse based on whether it's the inception of the table or not.
Describe alternatives you've considered
Previous exploration in dynamically enabling a model using data from a table:
dbt-labs/docs.getdbt.com#1310
^ This won't work with true
config()
likesnowflake_warhouse
.Who will this benefit?
Use cases above but bound to have plenty that fall into "check the state of a thing before setting configs of things".
Are you interested in contributing this feature?
No response
Anything else?
From jerco:
The text was updated successfully, but these errors were encountered: