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

Bug fix: Apply metric_time filters to time spine when needed #1455

Merged
merged 9 commits into from
Oct 16, 2024

Conversation

courtneyholcomb
Copy link
Contributor

@courtneyholcomb courtneyholcomb commented Oct 10, 2024

There is currently a bug where, if you query a join_to_timespine metric with a metric_time filter that is not applied in the group by, you will end up with more rows than expected.
To fix that, we need to apply any metric_time filters to the time spine table before joining that table to the aggregated measure. This needs to happen before the join instead of after because after the join we may not have access to metric_time at the grain needed for the filter. This implements that behavior.

I recommend reviewing by commit.

@cla-bot cla-bot bot added the cla:yes label Oct 10, 2024
@courtneyholcomb courtneyholcomb changed the title Court/ts filter3 Apply metric_time filters to time spine when needed Oct 10, 2024
@courtneyholcomb courtneyholcomb changed the title Apply metric_time filters to time spine when needed Bug fix: Apply metric_time filters to time spine when needed Oct 10, 2024
@courtneyholcomb courtneyholcomb changed the base branch from court/ts-filter2 to main October 10, 2024 15:40
@courtneyholcomb courtneyholcomb force-pushed the court/ts-filter3 branch 5 times, most recently from ad1d4bf to 287cefa Compare October 15, 2024 17:30
@courtneyholcomb courtneyholcomb marked this pull request as ready for review October 15, 2024 17:30
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Oct 15, 2024
@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 Oct 15, 2024
@courtneyholcomb courtneyholcomb force-pushed the court/ts-filter3 branch 2 times, most recently from 25a0798 to 8700c5f Compare October 15, 2024 20:14
@@ -286,23 +296,81 @@ def _make_time_spine_data_set(
)
# TODO: also handle date part.

output_instance_set = InstanceSet(
Copy link
Contributor Author

@courtneyholcomb courtneyholcomb Oct 15, 2024

Choose a reason for hiding this comment

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

This output instance set was incorrect before this PR, but was never used for any real logic so it didn't matter.

@courtneyholcomb courtneyholcomb force-pushed the court/ts-filter3 branch 8 times, most recently from 4fa8671 to 0359853 Compare October 16, 2024 03:51
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Oct 16, 2024
@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 Oct 16, 2024

# Where constraints must be applied in an outer query since they are using an alias (e.g., 'metric_time__day'),
# and some engines do not support using an alias in the WHERE clause.
if not time_spine_where_constraints:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I always have a hard time with not x for these, it feels easier to read if we have like if len(time_spine_where_constraints) == 0

@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Oct 16, 2024
@courtneyholcomb courtneyholcomb merged commit d56c603 into main Oct 16, 2024
11 checks passed
@courtneyholcomb courtneyholcomb deleted the court/ts-filter3 branch October 16, 2024 18:53
@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 Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants