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 timestamp issue #9

Merged
merged 5 commits into from
May 22, 2024
Merged

Fix timestamp issue #9

merged 5 commits into from
May 22, 2024

Conversation

hrialan
Copy link
Collaborator

@hrialan hrialan commented May 22, 2024

fixes #8

@hrialan
Copy link
Collaborator Author

hrialan commented May 22, 2024

Hello,

I tried to solve your issue @alexvys, does it meet your needs?

@tanukifk, Can you please also take a look since you worked on the timezone topic?

Thanks!

@hrialan
Copy link
Collaborator Author

hrialan commented May 22, 2024

Error it fixes:

Capture d’écran 2024-05-22 à 11 38 40

Copy link
Contributor

@alexvys alexvys left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@alexvys
Copy link
Contributor

alexvys commented May 22, 2024

TIMESTAMP_DIFF(CURRENT_TIMESTAMP("${timeZone}"), MAX(${dateColumn}), ${timeUnit}) AS delay

I think this could also work

@tanukifk
Copy link
Contributor

tanukifk commented May 22, 2024

Thank you for notifying me.
Because timestamp_diff and date_diff take different granularity, we need to use both two functions based on arguments.

I think this conditional variable can fix the problem. As you know, timestamp does not need timezone.

comparisonFunction = timeUnit in ("DAY", "WEEK", "MONTH", "QUARTER", "YEAR") 
? `DATE_DIFF(CURRENT_DATE("${timeZone}"), MAX(${dateColumn}), ${timeUnit})` 
: `TIMESTAMP_DIFF(CURRENT_TIMESTAMP(), MAX(${dateColumn}), ${timeUnit})`; 

ref
https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#timestamp_diff
https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_diff

@hrialan hrialan merged commit 7eb982a into main May 22, 2024
@hrialan hrialan deleted the fix-timestamp branch June 13, 2024 09:23
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.

current_date() in data_freshness_assertions does not work with hours/minutes/seconds
3 participants