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

Appropriate handling for group by source nodes in ComputeMetricsBranchCombiner #1212

Merged
merged 4 commits into from
May 15, 2024

Conversation

courtneyholcomb
Copy link
Contributor

@courtneyholcomb courtneyholcomb commented May 14, 2024

Description

Jordan found a bug when using metric filters on ratio metrics in prod. The error indicates that a ComputeMetricsNode is being unexpectedly created with MetricSpecs instead of GroupByMetricSpecs.
I was able to reproduce the error in check query tests. You can see the test case & the CI failures in the first commit here. To fix that bug, I updated the ComputeMetricsBranchCombiner to use the ComputeMetricsNode.for_group_by_source_node param where missed. I also added a step to ensure we don't combine nodes if only one is a group by source node (since that needs to be aggregated separately before joining to the outer query).

@courtneyholcomb courtneyholcomb requested review from tlento and plypaul May 14, 2024 14:32
@cla-bot cla-bot bot added the cla:yes label May 14, 2024
@dbt-labs dbt-labs deleted a comment from github-actions bot May 14, 2024
@courtneyholcomb courtneyholcomb marked this pull request as draft May 14, 2024 14:52
@courtneyholcomb courtneyholcomb changed the title Add missed for_group_by_source_node arg Don't combine nodes if they're used for group by metric source nodes May 14, 2024
@courtneyholcomb courtneyholcomb requested review from plypaul and tlento May 14, 2024 15:54
@courtneyholcomb courtneyholcomb marked this pull request as ready for review May 14, 2024 15:54
@courtneyholcomb courtneyholcomb changed the title Don't combine nodes if they're used for group by metric source nodes Appropriate handling for group by source nodes in ComputeMetricsBranchCombiner May 15, 2024
@courtneyholcomb courtneyholcomb force-pushed the court/ratio-bug branch 4 times, most recently from 22f6a35 to 5357c8e Compare May 15, 2024 16:41
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label May 15, 2024
@courtneyholcomb courtneyholcomb temporarily deployed to DW_INTEGRATION_TESTS May 15, 2024 16:48 — with GitHub Actions Inactive
@courtneyholcomb courtneyholcomb temporarily deployed to DW_INTEGRATION_TESTS May 15, 2024 16:48 — with GitHub Actions Inactive
This test case demonstrates the bug, as you can see in CI failures for this commit. This error is only triggered in e2e tests where we ensure the ComputeMetricsBranchCombiner is used.
@courtneyholcomb courtneyholcomb added Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment and removed Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment labels May 15, 2024
@courtneyholcomb courtneyholcomb temporarily deployed to DW_INTEGRATION_TESTS May 15, 2024 17:06 — with GitHub Actions Inactive
@courtneyholcomb courtneyholcomb temporarily deployed to DW_INTEGRATION_TESTS May 15, 2024 17:06 — with GitHub Actions Inactive
@courtneyholcomb courtneyholcomb temporarily deployed to DW_INTEGRATION_TESTS May 15, 2024 17:06 — with GitHub Actions Inactive
@courtneyholcomb courtneyholcomb temporarily deployed to DW_INTEGRATION_TESTS May 15, 2024 17:06 — with GitHub Actions Inactive
@github-actions github-actions bot removed the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label May 15, 2024
@@ -293,6 +293,14 @@ def visit_compute_metrics_node(self, node: ComputeMetricsNode) -> ComputeMetrics
)
return ComputeMetricsBranchCombinerResult()

if self._current_left_node.for_group_by_source_node != current_right_node.for_group_by_source_node:
Copy link
Contributor

@plypaul plypaul May 15, 2024

Choose a reason for hiding this comment

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

Can you move this check (and the above aggregated_to_elements check) to a method in ComputeMetricsNode similar to:

def combine(self, other: ComputeMetricsNode) -> CombinationResult
    ...

That should make it easier update that node in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be easier to do can_combine instead for now.

Copy link
Contributor

@plypaul plypaul left a comment

Choose a reason for hiding this comment

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

LGTM if the ComputeMetricsNode.combine works.

@courtneyholcomb courtneyholcomb enabled auto-merge (squash) May 15, 2024 18:32
@courtneyholcomb courtneyholcomb merged commit 8a4d342 into main May 15, 2024
15 checks passed
@courtneyholcomb courtneyholcomb deleted the court/ratio-bug branch May 15, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants