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

fix(dbt): Support syncing derived metrics on legacy dbt versions #270

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

Vitor-Avila
Copy link
Contributor

@Vitor-Avila Vitor-Avila commented Mar 15, 2024

PR#254 introduced a new pattern for mapping metrics:

metric_map = {metric["unique_id"]: metric for metric in metrics}

This ended up affecting our ability to parse derived metrics, given the metric macro renders the metric name, rather than its unique_id. As a consequence, this condition was never met (since token.sql() would return the macro name):

for token in tokens:
      if token.sql() in metrics:

This section of the code is only used by legacy dbt versions -- for new versions we're relying on MetricFlow to provide the metric syntax.

This PR re-introduces the old mapping structure specifically for this context:

metric_map = {metric["name"]: metric for metric in metrics}

It also includes the dialect as part of the metric schema, to assist sqlglot when parsing the syntax. I was facing an issue when trying to parse below metric syntax since it's BQ-specific:

SAFE_DIVIDE(
   SUM(
      IF(
         `product_line` = "Classic Cars",
         price_each * 0.80,
         price_each * 0.70
      )
   ),
   revenue_verbose_name_from_dbt
)

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, great catch!

@Vitor-Avila Vitor-Avila merged commit 1a0e0ac into main Mar 18, 2024
4 checks passed
@Vitor-Avila Vitor-Avila deleted the fix-derived-metrics branch March 18, 2024 12:51
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