Skip to content
Snippets Groups Projects
Unverified Commit 443da22c authored by Cam Saul's avatar Cam Saul
Browse files

Fix sync type inference for MongoDB completely null fields

parent a3936976
Branches
Tags
No related merge requests found
......@@ -106,12 +106,12 @@
(find-nested-fields field-value nested-fields)
nested-fields)))))
(s/defn ^:private most-common-object-type :- Class
(s/defn ^:private ^Class most-common-object-type :- (s/maybe Class)
"Given a sequence of tuples like [Class <number-of-occurances>] return the Class with the highest number of
occurances. The basic idea here is to take a sample of values for a Field and then determine the most common type
for its values, and use that as the Metabase base type. For example if we have a Field called `zip_code` and it's a
number 90% of the time and a string the other 10%, we'll just call it a `:type/Number`."
[field-types :- [(s/pair Class "Class", s/Int "Int")]]
[field-types :- [(s/pair (s/maybe Class) "Class", s/Int "Int")]]
(->> field-types
(sort-by second)
last
......
......@@ -6,6 +6,7 @@
[driver :as driver]
[query-processor :as qp]
[query-processor-test :refer [rows]]]
[metabase.driver.mongo :as mongo]
[metabase.driver.mongo.query-processor :as mongo-qp]
[metabase.models
[field :refer [Field]]
......@@ -237,3 +238,14 @@
:collection "venues"}
:type :native
:database (data/id)}))))
;; tests for `most-common-object-type`
(expect
String
(#'mongo/most-common-object-type [[Float 20] [Integer 10] [String 30]]))
;; make sure it handles `nil` types correctly as well (#6880)
(expect
nil
(#'mongo/most-common-object-type [[Float 20] [nil 40] [Integer 10] [String 30]]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment