Feat: implement builtin date spine macro#2990
Merged
sungchun12 merged 23 commits intomainfrom Aug 21, 2024
Merged
Conversation
georgesittas
reviewed
Aug 8, 2024
|
Sung Won Chung seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
Author
|
I signed the CLA with the correct github username. Commits under my personal name is likely due to using my personal laptop for commits. For all purposes, both commit signatures are the same person. |
georgesittas
approved these changes
Aug 21, 2024
Contributor
georgesittas
left a comment
There was a problem hiding this comment.
Sick how simple the implementation is now 🚀
The PR looks good, just a few comments to consider re: docs and test refactoring.
Co-authored-by: Jo <46752250+georgesittas@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to bring a lot of UX familiarity from dbt-utils into SQLMesh native macros similar to the deduplicate macro I just contributed.
dbt-utils version of this macro: https://github.com/dbt-labs/dbt-utils/blob/main/macros/sql/date_spine.sql
This renders to SQL to generate a date spine table. It's typically used to join in unique, hard-coded, date ranges to join with other tables/views so people don't have to constantly adjust date ranges in
whereclauses everywhere.Design Highlights
generate_date_arraytranspiling and behaving very differently across query engines. Huge thanks to @georgesittas to making this PR way easier for me. He's a real one.25.11.2.dev1Differences from dbt-utils' version
start_date(if it is aligned to the datepart), AND it will include theend_date@date_spine('quarter', '2022-01-01', '2024-12-16')generate_series-like sql functions to be faster and cheaper for the majority of query engines. If those functions don't exist for a particular engine (ex: redshift), recursion will be used.Other examples of ad hoc queries working across engines:

BigQuery
Redshift

Snowflake
