Skip to content

Commit 7eb982a

Browse files
author
Hugo Rialan
authored
Merge pull request #9 from devoteamgcloud/fix-timestamp
Fix timestamp issue
2 parents aa58487 + b957a95 commit 7eb982a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

definitions/example.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ const commonAssertionsResult = commonAssertions({
3232
"timeZone": "America/Los_Angeles"
3333
},
3434
"second_table": {
35-
"dateColumn": "updated_date",
36-
"timeUnit": "MONTH",
35+
// If timeUnit is not DAY, WEEK, MONTH, QUARTER, or YEAR, dateColumn should be a TIMESTAMP.
36+
// Check here for valid Date time units: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_diff
37+
// Check here for valid Timestamp time units: https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#timestamp_diff
38+
"dateColumn": "TIMESTAMP(updated_date)",
39+
"timeUnit": "HOUR",
3740
"delayCondition": 3,
3841
"timeZone": "-08"
3942
}

includes/data_freshness_assertions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const createDataFreshnessAssertion = (globalParams, tableName, delayCondition, t
2727
WITH
2828
freshness AS (
2929
SELECT
30-
DATE_DIFF(CURRENT_TIMESTAMP("${timeZone}"), MAX(${dateColumn}), ${timeUnit}) AS delay
30+
${["DAY", "WEEK", "MONTH", "QUARTER", "YEAR"].includes(timeUnit)
31+
? `DATE_DIFF(CURRENT_DATE("${timeZone}"), MAX(${dateColumn}), ${timeUnit})`
32+
: `TIMESTAMP_DIFF(CURRENT_TIMESTAMP(), MAX(${dateColumn}), ${timeUnit})`} AS delay
3133
FROM
3234
${ctx.ref(tableName)}
3335
)

0 commit comments

Comments
 (0)