Skip to content
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

change partition_key_to_vars_fn to context_to_vars_fn #15084

Closed
wants to merge 1 commit into from

Conversation

gnmjulius
Copy link

Summary & Motivation

Give more options to stream events while executing dbt assets, using "context" as a variable instead of "context.partition_key" and change the name of "partition_key_to_vars_fn" to "context_to_vars_fn" for better understanding. This change relates to this GitHub issue (#15062)

How I Tested These Changes

Create the function for context_to_vars_fn (old - partition_key_to_vars_fn)

def date_from_context(context):
    # partition_key from context
    partition_key = context.partition_key

    # all_partition from context
    all_partition = context.instance.get_dynamic_partitions(partitions_def_name="test_partition")
    index = all_partition.index(partition_key)

    dbt_vars = {
        "var_1": partition_key,
        "var_2": index
    }
    return dbt_vars

Add this function to the dbt definition:

dbt_assets = load_assets_from_dbt_project(
            project_dir=DBT_PROJECT_PATH,
            profiles_dir=DBT_PROFILES,
            select=f"tag:{source}",
            op_name=f"{dbt_ops}",
            partitions_def=test_partition,
            key_prefix=source,
            context_to_vars_fn=date_from_context,   # <-------------- add the function here
            use_build_command=True,
            display_raw_sql=True
        )

Give more options to stream events while executing dbt assets, using "context" as a variable instead of "context.partition_key" and change the name of "partition_key_to_vars_fn" to "context_to_vars_fn" for better understanding.
These change relates this GitHub issue (dagster-io#15062)
@rexledesma
Copy link
Contributor

If you want more control over the execution of your dbt models, we recommend that you move over to @dbt_assets, starting in our 1.4 release of Dagster. This new API is more extensible for use cases like yours.

For example, you'll have full range to define dbt vars in your asset compute body.

Discussion Link: #14477

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants