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

Fix: Cast to timestamp prior to event time comparison #1422

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Dec 4, 2024

resolves #1412
docs dbt-labs/docs.getdbt.com/#

Problem

It's not currently possible to use microbatch models with inputs that aren't of type timestamp, because BigQuery does not coerce dates or datetimes to timestamps automatically when compared to literal timestamps.

Solution

Cast event_time to timestamp on rendering, prior to comparing against timestamp literal.

https://cloud.google.com/bigquery/docs/reference/standard-sql/conversion_functions#cast_as_timestamp
works for inputs of type:

  • string
  • date - assumes midnight UTC
  • datetime - assumes UTC
  • timestamp

(shoutout to @jtcohen6 for helping with this solutioning)

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@cla-bot cla-bot bot added the cla:yes label Dec 4, 2024
Copy link
Contributor

github-actions bot commented Dec 4, 2024

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-bigquery contributing guide.

1 similar comment
Copy link
Contributor

github-actions bot commented Dec 4, 2024

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-bigquery contributing guide.

@MichelleArk MichelleArk marked this pull request as ready for review December 4, 2024 15:59
@MichelleArk MichelleArk requested a review from a team as a code owner December 4, 2024 15:59
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.

:shipit: YAAAAAY

@MichelleArk MichelleArk changed the title Microbatch date casting Fix: Cast to timestamp prior to event time comparison Dec 4, 2024
@MichelleArk MichelleArk enabled auto-merge (squash) December 4, 2024 17:44
@MichelleArk MichelleArk disabled auto-merge December 4, 2024 18:26
@MichelleArk MichelleArk enabled auto-merge (squash) December 4, 2024 18:28
@MichelleArk MichelleArk merged commit 4d255b2 into main Dec 5, 2024
15 checks passed
@MichelleArk MichelleArk deleted the microbatch-date-casting branch December 5, 2024 21:26
github-actions bot pushed a commit that referenced this pull request Dec 5, 2024
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.

[Bug] Microbatch does not work with date field types
3 participants