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

Custom offset window: support grains smaller than base grain #1663

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

courtneyholcomb
Copy link
Contributor

Support for querying a custom offset window metric with a grain that's smaller than the custom grain's base grain. Previously this would render invalid SQL.

@cla-bot cla-bot bot added the cla:yes label Feb 6, 2025
@dbt-labs dbt-labs deleted a comment from github-actions bot Feb 6, 2025
@courtneyholcomb courtneyholcomb added the Reload Test Data in SQL Engines Should be run when test data changes label Feb 6, 2025
@dbt-labs dbt-labs deleted a comment from github-actions bot Feb 6, 2025
@courtneyholcomb courtneyholcomb removed the Reload Test Data in SQL Engines Should be run when test data changes label Feb 6, 2025
@courtneyholcomb courtneyholcomb added the Reload Test Data in SQL Engines Should be run when test data changes label Feb 6, 2025
@github-actions github-actions bot removed the Reload Test Data in SQL Engines Should be run when test data changes label Feb 6, 2025
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Feb 6, 2025
@courtneyholcomb courtneyholcomb marked this pull request as ready for review February 6, 2025 23:39
@courtneyholcomb courtneyholcomb requested a review from a team as a code owner February 6, 2025 23:39
@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 Feb 6, 2025
Base automatically changed from court/time-spines to main February 7, 2025 14:59
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.

Still getting familiar with the changes - can you elaborate on why joining the 2nd time spine is needed for the smaller grain vs. starting out with the smaller grain time spine?

@courtneyholcomb
Copy link
Contributor Author

Still getting familiar with the changes - can you elaborate on why joining the 2nd time spine is needed for the smaller grain vs. starting out with the smaller grain time spine?

@plypaul yes! So for all standard grains, we can pick the smallest grain and use the time spine that satisfies that, and then just DATE_TRUNC to satisfy larger grains. For custom grains, they are defined in one time spine and can only be satisfied by that time spine. A good example is the query in this test. To satisfy metric_time__hour, we need to use the hourly time spine. But to satisfy the metric, which uses offset_window: 1 alien_day, we need to use the daily spine. That's because the alien_day column is only available in that time spine.
The query might also contain other custom grains in the group by, which could mean joining to additional time spines, but we don't need to worry about those in the time spine node logic because they will be joined later in the query (after joining to the metric source).

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