-
Notifications
You must be signed in to change notification settings - Fork 453
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
dbt-materialize: support generate_cluster_name
#27159
Comments
Just as an FYI, we already have a macro called generate_cluster_name that is invoked in all the places described in this ticket. |
Ah ok thanks, Seth, so then we should just update the macro to support this new option? |
I was just looking into doing this after the dbt adapter migration to v1.8.0 is done. Just to make sure that I have the full picture here, as we already have the {% macro generate_cluster_name(custom_cluster_name) -%}
{%- set default_cluster = target.cluster -%}
{%- set deploy_suffix = "_dbt_deploy" if var('deploy', False) else "" -%}
{%- if custom_cluster_name is none -%}
{{ default_cluster }}{{ deploy_suffix }}
{%- else -%}
{{ target.name }}_{{ custom_cluster_name | trim }}{{ deploy_suffix }}
{%- endif -%}
{%- endmacro %} That way users who want to override the logic, will be able to do that, but also users who prefer the default behavior (eg. just using the default cluster name without prefixing it with the Or do we prefer to actually extend the macro? Maybe introduce another var that users could pass to prefix cluster names? |
Because of the away dependency resolution works, I think you'll need to update the callers to use the adapter dispatch method 1. And then more broadly, there's a question of if the deploy suffix handling should happen inside this macro or not. If users override it, they will break blue/green if they don't copy the suffix handling exactly. Maybe what we should do it create an internal macro that handles deploy suffixes and calls generate_cluster_name. {% macro generate_cluster_name_internal(custom_cluster_name) -%}
{%- set cluster_name = adapter.dispatch('generate_cluster_name')(custom_cluster_name) -%}
{%- set deploy_suffix = "_dbt_deploy" if var('deploy', False) else "" -%}
{{ cluster_name }}{{ deploy_suffix }}
{%- endmacro %} Footnotes |
Thanks @sjwiesman this is very helpful! I started putting together a PR for this. |
<!-- Describe the contents of the PR briefly but completely. If you write detailed commit messages, it is acceptable to copy/paste them here, or write "see commit messages for details." If there is only one commit in the PR, GitHub will have already added its commit message above. --> ### Motivation Fixes #27159 This PR introduces a couple of things: * A new `generate_deploy_cluster_name` macro responsible for appending the `_dbt_deploy` suffix for the blue/green deployments. * A new `generate_final_cluster_name` adapter method. * Users can define their own `generate_cluster_name` macro in their dbt project to override the cluster name generation logic, like one that automatically prefixes each cluster with the target name: ```jinja {% macro generate_cluster_name(custom_cluster_name, node) -%} {%- set default_cluster = target.cluster -%} {%- if custom_cluster_name is none -%} {{ default_cluster }} {%- else -%} {{target.name}}_{{ custom_cluster_name }} {%- endif -%} {%- endmacro %} ```
Outcome: support
generate_cluster_name
so users can prefix a cluster name per dbt target. E.g. so that when running in dev, thedev_
cluster is used and in prod, theprod_
cluster is used.Context - slack thread:
Introduce a macro called
generate_cluster_name
, akin togenerate_schema_name
, that was invoked on every model’s cluster with the following default definition:We should automatically call
generate_cluster_name(model.cluster)
on each model’s cluster to determine the true cluster name to use.The user can plug in their own version of the macro, like one that automatically prefixes each cluster with the target name:
The text was updated successfully, but these errors were encountered: