Skip to content
Snippets Groups Projects
Unverified Commit a99ec1df authored by metamben's avatar metamben Committed by GitHub
Browse files

Add ISO-8601 coercion support for BigQuery (#23521)

parent 79337de1
No related branches found
No related tags found
No related merge requests found
...@@ -722,3 +722,15 @@ ...@@ -722,3 +722,15 @@
(if (instance? java.time.temporal.Temporal arg) (if (instance? java.time.temporal.Temporal arg)
(->temporal-type field-temporal-type arg) (->temporal-type field-temporal-type arg)
arg))))))) arg)))))))
(defmethod sql.qp/cast-temporal-string [:bigquery-cloud-sdk :Coercion/ISO8601->DateTime]
[_driver _semantic_type expr]
(hx/->timestamp expr))
(defmethod sql.qp/cast-temporal-string [:bigquery-cloud-sdk :Coercion/ISO8601->Date]
[_driver _semantic_type expr]
(hx/->date expr))
(defmethod sql.qp/cast-temporal-string [:bigquery-cloud-sdk :Coercion/ISO8601->Time]
[_driver _semantic_type expr]
(hx/->time expr))
...@@ -212,6 +212,16 @@ ...@@ -212,6 +212,16 @@
[2 "bar" "2008-10-19 10:23:54" "2008-10-19" "10:23:54"] [2 "bar" "2008-10-19 10:23:54" "2008-10-19" "10:23:54"]
[3 "baz" "2012-10-19 10:23:54" "2012-10-19" "10:23:54"]] [3 "baz" "2012-10-19 10:23:54" "2012-10-19" "10:23:54"]]
;; string-times dataset has three text fields, ts, d, t for timestamp, date, and time ;; string-times dataset has three text fields, ts, d, t for timestamp, date, and time
(mt/rows (mt/dataset string-times
(qp/process-query
(assoc (mt/mbql-query times)
:middleware {:format-rows? false}))))))))
(testing "bigquery adds UTC"
(mt/test-drivers #{:bigquery-cloud-sdk}
(is (= [[1 "foo" #t "2004-10-19T10:23:54Z[UTC]" #t "2004-10-19T00:00Z[UTC]" #t "10:23:54"]
[2 "bar" #t "2008-10-19T10:23:54Z[UTC]" #t "2008-10-19T00:00Z[UTC]" #t "10:23:54"]
[3 "baz" #t "2012-10-19T10:23:54Z[UTC]" #t "2012-10-19T00:00Z[UTC]" #t "10:23:54"]]
;; string-times dataset has three text fields, ts, d, t for timestamp, date, and time
(mt/rows (mt/dataset string-times (mt/rows (mt/dataset string-times
(qp/process-query (qp/process-query
(assoc (mt/mbql-query times) (assoc (mt/mbql-query times)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment