Skip to content

feat: dbt microbatch ref filter support#5292

Merged
eakmanrq merged 2 commits intomainfrom
eakmanrq/dbt_microbatch_filter_support
Sep 8, 2025
Merged

feat: dbt microbatch ref filter support#5292
eakmanrq merged 2 commits intomainfrom
eakmanrq/dbt_microbatch_filter_support

Conversation

@eakmanrq
Copy link
Collaborator

@eakmanrq eakmanrq commented Sep 3, 2025

One behavior difference between dbt microbatch and SQLMesh incremental by time range is that dbt microbatch, by default, includes the date filter for you. You can opt-out of this by adding a .render() after the ref. This PR adds that functionality.

Some tricky parts of this:

  • To add the filter we need to know the event column and the start/end dates. All of that is known at load time for dbt but we only know event column at load time in SQLMesh. Therefore preparing the EventTimeFilter happens in two stages on SQLMesh - one when we load to record the event column and then at execution we add the start/end
  • dbt uses end as exclusive and therefore doesn't use BETWEEN in the expression. Therefore the end is made exclusive. An alternative approach is to patch the filter render method to have it use between which you can see that implementation in this commit: a595791

@eakmanrq eakmanrq force-pushed the eakmanrq/dbt_microbatch_filter_support branch from f7c5e95 to c52d415 Compare September 3, 2025 21:04
)
for ref in all_refs:
if ref.event_time_filter:
ref.event_time_filter["start"] = render_kwargs["start_tstz"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I use tstz since my testing with Postgres showed that dbt rendered a tstz. It might end up being adapter specific so this could change after more testing.

@eakmanrq eakmanrq force-pushed the eakmanrq/dbt_microbatch_filter_support branch 4 times, most recently from 71295e5 to 6e137a4 Compare September 4, 2025 19:56
@eakmanrq eakmanrq force-pushed the eakmanrq/dbt_microbatch_filter_support branch from 6e137a4 to 1929b4f Compare September 8, 2025 15:08
@eakmanrq eakmanrq enabled auto-merge (squash) September 8, 2025 15:09
@eakmanrq eakmanrq merged commit 971eccf into main Sep 8, 2025
35 checks passed
@eakmanrq eakmanrq deleted the eakmanrq/dbt_microbatch_filter_support branch September 8, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants