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

[CT-2707] Derived metrics throw an error when using the run based semantic manifest. #7884

Closed
2 tasks done
Tracked by #7498
Jstein77 opened this issue Jun 15, 2023 · 1 comment · Fixed by #7984
Closed
2 tasks done
Tracked by #7498
Assignees
Labels
bug Something isn't working semantic Issues related to the semantic layer

Comments

@Jstein77
Copy link

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

I'm getting this error when querying a derived metric: ins.ValueError: Unknown metric: MetricReference(element_name='order_gross_profit') in element set. I noticed that the measures list in the semantic manifest is empty, which is likely causing the error:

@QMalcolm per our conversation today in standup we need to update the way we populate measures.

 {
            "name": "order_gross_profit",
            "description": "Gross profit from each order.",
            "type": "derived",
            "type_params": {
                "measure": null,
                "measures": [],
                "numerator": null,
                "denominator": null,
                "expr": "revenue - cost",
                "window": null,
                "grain_to_date": null,
                "metrics": [
                    {
                        "name": "food_order_amount",
                        "filter": null,
                        "alias": "revenue",
                        "offset_window": null,
                        "offset_to_grain": null
                    },
                    {
                        "name": "order_amount",
                        "filter": null,
                        "alias": "cost",
                        "offset_window": null,
                        "offset_to_grain": null
                    }
                ]
            },
            "filter": null,
            "metadata": null
        },

Expected Behavior

I should be able to query derived metrics from the run based manifest.

Steps To Reproduce

  1. Create a derived metric like the one in jaffle-sl-template: https://github.com/dbt-labs/jaffle-sl-template/blob/d7ce5ba300bbe809a9d36578912c36d1379175f5/models/metrics/example_metrics.yaml#L48
  2. Kick of a run in dbt cloud
  3. Run semantic_layer.query()

Relevant log output

No response

Environment

- OS:
- Python:
- dbt:

Which database adapter are you using with dbt?

No response

Additional Context

No response

@Jstein77 Jstein77 added bug Something isn't working triage labels Jun 15, 2023
@github-actions github-actions bot changed the title Derived metrics throw an error when using the run based semantic manifest. [CT-2707] Derived metrics throw an error when using the run based semantic manifest. Jun 15, 2023
@dbeatty10 dbeatty10 added semantic Issues related to the semantic layer and removed triage labels Jun 15, 2023
@QMalcolm
Copy link
Contributor

QMalcolm commented Jun 17, 2023

So what we haven't been doing is properly populating the measures attribute of metric type params (additionally measures on metric type params because input_measures once work for #7898 is merged). The input_measures can only get populated once all metrics have gone through initial parsing. This is because of derived metrics. If a derived metric depends on a metric that hasn't been parsed yet, then it won't be able to properly populate the input_measures. An example of how the logic for setting input_measures plays out can be found in dbt-semantic-interfaces' add_input_metric_measures.py transformation rule. I imagine the logic we used would be quite similar. If so we should longer term coordinate with the semantic layer team to abstract this logic in dbt-semantic-interfaces to make it more accessible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working semantic Issues related to the semantic layer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants