dynamic value in the cluster_by

The problem I’m having

I’m encountering an issue with retrieving values using a macro within a config block. Here’s the code snippet:
{% set category = get_cluster_key(‘CATEGORY’) %}
{{ config(materialized=“table”, schema=“schema”, cluster_by=[‘start’~category~‘_end’, ‘col2’]) }}

However, I’m not getting the expected value.

The context of why I’m trying to do this

I need to dynamically retrieve a value from a table that undergoes changes.

What I’ve already tried

I attempted to address this by implementing an execution block within the macro file and returning a dummy value when the macro isn’t executed. I followed the guidance provided : About execute variable | dbt Developer Hub (getdbt.com)

I understand that I’m getting an empty value when dbt isn’t in execution mode, but I’m unsure how to make it read the value within the execution block.

If get_cluster_by is meant to run a sql query and return some results back - you’re out of luck unfortunately. Configs are set before dbt is able to run sql query.

Note: @Jeremy Yeo originally posted this reply in Slack. It might not have transferred perfectly.

Read this https://github.com/dbt-labs/docs.getdbt.com/discussions/1310|https://github.com/dbt-labs/docs.getdbt.com/discussions/1310

Note: @Jeremy Yeo originally posted this reply in Slack. It might not have transferred perfectly.