Skip to content
Snippets Groups Projects
Commit 19dda64e authored by Ryan Senior's avatar Ryan Senior
Browse files

Round fingerprints (in test) to 3 decimal places [ci drivers]

Oracle specifically has long unrounded decimals that cause tests to
fail. This munges results to round the decimals to 3 places before comparing.
parent ce68eb0c
No related branches found
No related tags found
No related merge requests found
......@@ -115,7 +115,7 @@
:base_type (data/expected-base-type->actual :type/Text)
:name (data/format-name "name")
:display_name "Name"
:fingerprint {:global {:distinct-count 75}, :type {:type/Text {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :average-length 8.333333333333334}}}})))
:fingerprint {:global {:distinct-count 75}, :type {:type/Text {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :average-length 8.333}}}})))
;; #### users
(defn users-col
......@@ -135,7 +135,7 @@
:base_type (data/expected-base-type->actual :type/Text)
:name (data/format-name "name")
:display_name "Name"
:fingerprint {:global {:distinct-count 15}, :type {:type/Text {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :average-length 13.266666666666667}}}}
:fingerprint {:global {:distinct-count 15}, :type {:type/Text {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :average-length 13.267}}}}
:last_login {:special_type nil
:base_type (data/expected-base-type->actual :type/DateTime)
:name (data/format-name "last_login")
......@@ -172,22 +172,22 @@
:base_type (data/expected-base-type->actual :type/Integer)
:name (data/format-name "category_id")
:display_name "Category ID"
:fingerprint {:global {:distinct-count 28}, :type {:type/Number {:min 2, :max 74, :avg 29.98}}},}
:fingerprint {:global {:distinct-count 28}, :type {:type/Number {:min 2, :max 74, :avg 29.98}}}}
:price {:special_type :type/Category
:base_type (data/expected-base-type->actual :type/Integer)
:name (data/format-name "price")
:display_name "Price"
:fingerprint {:global {:distinct-count 4}, :type {:type/Number {:min 1, :max 4, :avg 2.03}}},}
:fingerprint {:global {:distinct-count 4}, :type {:type/Number {:min 1, :max 4, :avg 2.03}}}}
:longitude {:special_type :type/Longitude
:base_type (data/expected-base-type->actual :type/Float)
:name (data/format-name "longitude")
:fingerprint {:global {:distinct-count 84}, :type {:type/Number {:min -165.374, :max -73.9533, :avg -115.99848699999991}}},
:fingerprint {:global {:distinct-count 84}, :type {:type/Number {:min -165.374, :max -73.953, :avg -115.998}}}
:display_name "Longitude"}
:latitude {:special_type :type/Latitude
:base_type (data/expected-base-type->actual :type/Float)
:name (data/format-name "latitude")
:display_name "Latitude"
:fingerprint {:global {:distinct-count 94}, :type {:type/Number {:min 10.0646, :max 40.7794, :avg 35.50589199999998}}},}
:fingerprint {:global {:distinct-count 94}, :type {:type/Number {:min 10.065, :max 40.779, :avg 35.506}}}}
:name {:special_type :type/Name
:base_type (data/expected-base-type->actual :type/Text)
:name (data/format-name "name")
......
......@@ -5,7 +5,8 @@
[util :as u]]
[metabase.query-processor.middleware.expand :as ql]
[metabase.test.data :as data]
[metabase.test.data.datasets :as datasets]))
[metabase.test.data.datasets :as datasets]
[metabase.test.util :as tu]))
;;; ------------------------------------------------------------ "COUNT" AGGREGATION ------------------------------------------------------------
......@@ -72,11 +73,12 @@
:columns (venues-columns)
:cols (venues-cols)
:native_form true}
(->> (data/run-query venues
(-> (data/run-query venues
(ql/limit 10)
(ql/order-by (ql/asc $id)))
booleanize-native-form
formatted-venues-rows))
booleanize-native-form
formatted-venues-rows
tu/round-fingerprint-cols))
;;; ------------------------------------------------------------ STDDEV AGGREGATION ------------------------------------------------------------
......@@ -230,7 +232,8 @@
(ql/aggregation (ql/cum-sum $id))
(ql/breakout $name))
booleanize-native-form
(format-rows-by [str int])))
(format-rows-by [str int])
tu/round-fingerprint-cols))
;;; Cumulative sum w/ a different breakout field that requires grouping
......@@ -295,7 +298,8 @@
(ql/aggregation (ql/cum-count))
(ql/breakout $name))
booleanize-native-form
(format-rows-by [str int])))
(format-rows-by [str int])
tu/round-fingerprint-cols))
;;; Cumulative count w/ a different breakout field that requires grouping
......
......@@ -217,6 +217,7 @@
(-> (data/run-query venues
(ql/aggregation (ql/count))
(ql/breakout (ql/binning-strategy $latitude :default)))
tu/round-fingerprint-cols
(get-in [:data :cols])
first))
......@@ -228,6 +229,7 @@
(-> (data/run-query venues
(ql/aggregation (ql/count))
(ql/breakout (ql/binning-strategy $latitude :num-bins 5)))
tu/round-fingerprint-cols
(get-in [:data :cols])
first))
......
......@@ -5,7 +5,9 @@
[util :as u]]
[metabase.models.field :refer [Field]]
[metabase.query-processor.middleware.expand :as ql]
[metabase.test.data :as data]
[metabase.test
[data :as data]
[util :as tu]]
[toucan.db :as db]))
;;; ------------------------------------------------------------ :details-only fields ------------------------------------------------------------
......@@ -14,7 +16,10 @@
(-> (data/run-query venues
(ql/order-by (ql/asc $id))
(ql/limit 1))
:data :cols set))
tu/round-fingerprint-cols
:data
:cols
set))
(expect-with-non-timeseries-dbs
[(set (venues-cols))
......@@ -58,5 +63,6 @@
(-> (data/run-query users
(ql/order-by (ql/asc $id)))
booleanize-native-form
tu/round-fingerprint-cols
(update-in [:data :rows] (partial mapv (fn [[id name last-login]]
[(int id) name])))))
......@@ -76,4 +76,5 @@
booleanize-native-form
(format-rows-by [int str int double double int str])
(select-columns (set (map data/format-name ["name" "price" "name_2"])))
tu/round-fingerprint-cols
:data)))
......@@ -314,3 +314,32 @@
(vec form)
form))
x))
(defn- update-in-if-present
"If the path `KS` is found in `M`, call update-in with the original
arguments to this function, otherwise, return `M`"
[m ks f & args]
(if (= ::not-found (get-in m ks ::not-found))
m
(apply update-in m ks f args)))
(defn- round-fingerprint-fields [fprint-type-map fields]
(reduce (fn [fprint field]
(update-in-if-present fprint [field] (fn [num]
(if (integer? num)
num
(u/round-to-decimals 3 num)))))
fprint-type-map fields))
(defn round-fingerprint
"Rounds the numerical fields of a fingerprint to 4 decimal places"
[field]
(-> field
(update-in-if-present [:fingerprint :type :type/Number] round-fingerprint-fields [:min :max :avg])
(update-in-if-present [:fingerprint :type :type/Text] round-fingerprint-fields [:percent-json :percent-url :percent-email :average-length])))
(defn round-fingerprint-cols [query-results]
(let [maybe-data-cols (if (contains? query-results :data)
[:data :cols]
[:cols])]
(update-in query-results maybe-data-cols #(map round-fingerprint %))))
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