The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix bug with temporal values in bigquery incremental transforms (#71291)
Nicola Momettod6d3bbb89a95
diff --git a/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.cljindex c27ce039172..15e3fbcf10b 100644--- a/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj+++ b/enterprise/backend/test/metabase_enterprise/transforms/incremental_test.clj@@ -4,6 +4,7 @@[clojure.string :as str][clojure.test :refer :all][honey.sql :as sql]+ [java-time.api :as t][metabase-enterprise.transforms-python.python-runner :as python-runner][metabase.driver :as driver][metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]@@ -174,7 +175,7 @@:integer (= (bigint expected) (bigint actual)):float (and (number? actual)(< (Math/abs (double (- expected actual))) 0.01))- :temporal (= expected actual)))+ :temporal (= (t/local-date-time expected) (t/local-date-time actual))))(defn- insert-test-products!"Insert new products into the transforms_products table."diff --git a/src/metabase/transforms_base/util.clj b/src/metabase/transforms_base/util.cljindex 333dab141f3..2c8c4f29081 100644--- a/src/metabase/transforms_base/util.clj+++ b/src/metabase/transforms_base/util.clj@@ -174,14 +174,31 @@lo (assoc :checkpoint_lo_value (encode-checkpoint-value (:value lo)))hi (assoc :checkpoint_hi_value (encode-checkpoint-value (:value hi))))))))+(defn- coerce-to-local-datetime+ "Coerce a temporal value to LocalDateTime, stripping any timezone information."+ [t]+ (condp instance? t+ OffsetDateTime (t/local-date-time t)+ ZonedDateTime (t/local-date-time t)+ Instant (t/local-date-time t (t/zone-id "UTC"))+ t))++(defn- maybe-coerce-temporal+ [base-type t]+ (cond-> t+ (and (isa? base-type :type/DateTime)+ (not (isa? base-type :type/DateTimeWithTZ)))+ coerce-to-local-datetime))+(defn- parse-checkpoint-value- "Parse a serialized checkpoint value string according to its base-type keyword."+ "Parse a serialized checkpoint value string according to its base-type keyword.+ For temporal types, coerces the result to match the column's base-type."[base-type s](cond- (not (string? s)) s+ (not (string? s)) (maybe-coerce-temporal base-type s)(isa? base-type :type/Float) (bigdec s)(isa? base-type :type/Number) (biginteger s)- (isa? base-type :type/Temporal) (u.date/parse s)+ (isa? base-type :type/Temporal) (maybe-coerce-temporal base-type (u.date/parse s)):else (throw (ex-info (str "Unsupported checkpoint type: " (pr-str base-type)){:base-type base-type}))))