Skip to content
Snippets Groups Projects
Commit ebca634f authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #5982 from metabase/fix-fingerprinting-overflow

Fix integer overflow in average
parents 2ca5d34b 5bb4f8c5
No related branches found
No related tags found
No related merge requests found
(ns metabase.sync.analyze.fingerprint.number
"Logic for generating a `NumberFingerprint` from a sequence of values for a `:type/Number` Field."
(:require [metabase.sync.interface :as i]
(:require [kixi.stats.core :as stats]
[metabase.sync.interface :as i]
[schema.core :as s]))
(s/defn ^:private ^:always-validate average :- s/Num
"Return the average of VALUES."
[values :- i/FieldSample]
(/ (double (reduce + values))
(double (count values))))
(s/defn ^:always-validate number-fingerprint :- i/NumberFingerprint
"Generate a fingerprint containing information about values that belong to a `:type/Number` Field."
[values :- i/FieldSample]
{:min (apply min values)
:max (apply max values)
:avg (average values)})
:avg (transduce (map double) stats/mean values)})
(ns metabase.sync.analyze.fingerprint.number-test
(:require [expectations :refer :all]
[metabase.sync.analyze.fingerprint.number :as number]))
(expect
(approximately (double Long/MAX_VALUE))
(:avg (number/number-fingerprint [Long/MAX_VALUE Long/MAX_VALUE])))
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