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

add batch property to model jinja fnction #6590

Merged
merged 11 commits into from
Dec 5, 2024
Merged

Conversation

mirnawong1
Copy link
Contributor

@mirnawong1 mirnawong1 commented Dec 4, 2024

this pr adds a new batch object to the already existing model dbt-jinja-functions.

The batch qualities available are:

id (i.e. model.batch.id)
This is the "unique" id for the batch within the context of the microbatch model
event_time_start (i.e. model.batch.event_time_start)
This is the start time of the batch's event time filter (inclusive)
event_time_end (i.e. model.batch.event_time_end)
This is the end time of the batch's event_time_filter (exclusive

Resolves #6585


🚀 Deployment available! Here are the direct links to the updated files:

@mirnawong1 mirnawong1 requested a review from a team as a code owner December 4, 2024 17:02
Copy link

vercel bot commented Dec 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs-getdbt-com ✅ Ready (Inspect) Visit Preview Dec 5, 2024 10:36am

@github-actions github-actions bot added Docs team Authored by the Docs team @dbt Labs content Improvements or additions to content size: small This change will take 1 to 2 days to address and removed Docs team Authored by the Docs team @dbt Labs labels Dec 4, 2024
@mirnawong1 mirnawong1 changed the title Add-batch-jinja add batch property to model jinja fnction Dec 4, 2024
| Property | Description | Example |
| -------- | ----------- | ------- |
| `id` | The unique identifier for the batch within the context of the microbatch model. | `model.batch.id` |
| `event_time_start` | The start time of the batch's [`event_time`](/reference/resource-configs/event-time) filter (inclusive). | `model.batch.event_time_start` |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@QMalcolm what do we mean by 'inclusive' and 'exclusive' here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mirnawong1 great question ❤️

Short answer

Inclusive means the value is included in the batch, exclusive means the value is excluded from the batch

Long answer

To think specifically about inclusivity/exclusivity means with regard to a batch, consider the batch filter statement

WHERE event_time >= event_time_start AND event_time < event_time_end

Things to note

  1. The comparison of event_time to event_time_start used >= with the = part of the operator including the event_time_start as part of the range. This means the usage of event_time_start is inclusive in the range selection
  2. In the comparison of event_time to event_time_end we used < meaning things up to, but not equal to, the event_time_end will be selected as part of the range. This means that event_time_end is exclusive in the range selection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh got it, thanks so much for taking the time to clarify 🙏

@github-actions github-actions bot added the Docs team Authored by the Docs team @dbt Labs label Dec 4, 2024
Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

🚀


### Usage notes

`model.batch` is only available during the execution of a microbatch model batch. Outside of the microbatch execution, `model.batch` is `None`, and its sub-properties aren't accessible.
Copy link
Contributor

Choose a reason for hiding this comment

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

We sort of state this above. Maybe we could combine the two into a callout if it's important enough

@mirnawong1 mirnawong1 enabled auto-merge December 5, 2024 10:33
@mirnawong1 mirnawong1 merged commit 924ad80 into current Dec 5, 2024
9 checks passed
@mirnawong1 mirnawong1 deleted the add-batch-jinja branch December 5, 2024 10:36
Copy link
Contributor

github-actions bot commented Dec 5, 2024

Check your created Crawler

Check your created index on your Algolia Application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content Docs team Authored by the Docs team @dbt Labs size: small This change will take 1 to 2 days to address trigger-crawl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Core] New jinja model.batch context
3 participants