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

Fix syncing of Mongo tables w/ all-NULL columns :wrench: [ci drivers]

parent be8a5dd1
No related branches found
No related tags found
No related merge requests found
......@@ -392,7 +392,8 @@
[clojure.lang.IPersistentMap :type/Dictionary]
[clojure.lang.IPersistentVector :type/Array]
[org.bson.types.ObjectId :type/MongoBSONID]
[org.postgresql.util.PGobject :type/*]])
[org.postgresql.util.PGobject :type/*]
[nil :type/*]]) ; all-NULL columns in DBs like Mongo w/o explicit types
(log/warn (trs "Don''t know how to map class ''{0}'' to a Field base_type, falling back to :type/*." klass))
:type/*))
......
......@@ -116,7 +116,7 @@
(defn- describe-table-field [field-kw field-info]
(let [most-common-object-type (most-common-object-type (vec (:types field-info)))]
(cond-> {:name (name field-kw)
:database-type (.getName most-common-object-type)
:database-type (some-> most-common-object-type .getName)
:base-type (driver/class->base-type most-common-object-type)}
(= :_id field-kw) (assoc :pk? true)
(:special-types field-info) (assoc :special-type (->> (vec (:special-types field-info))
......
......@@ -22,7 +22,7 @@
(def TableMetadataField
"Schema for a given Field as provided in `describe-table`."
{:name su/NonBlankString
:database-type su/NonBlankString
:database-type (s/maybe su/NonBlankString) ; blank if the Field is all NULL & untyped, i.e. in Mongo
:base-type su/FieldType
(s/optional-key :special-type) (s/maybe su/FieldType)
(s/optional-key :pk?) s/Bool
......
......@@ -74,7 +74,7 @@
{:table_id (u/get-id table)
:name field-name
:display_name (humanization/name->human-readable-name field-name)
:database_type database-type
:database_type (or database-type "NULL") ; placeholder for Fields w/ no type info (e.g. Mongo) & all NULL
:base_type base-type
:special_type (special-type field)
:parent_id parent-id}))))
......
......@@ -122,6 +122,24 @@
:pk? true}}}
(driver/describe-table (MongoDriver.) (data/db) (Table (data/id :venues))))
;; Make sure that all-NULL columns work are synced correctly (#6875)
(i/def-database-definition ^:private all-null-columns
[["bird_species"
[{:field-name "name", :base-type :type/Text}
{:field-name "favorite_snack", :base-type :type/Text}]
[["House Finch" nil]
["Mourning Dove" nil]]]])
(datasets/expect-with-engine :mongo
[{:name "_id", :database_type "java.lang.Long", :base_type :type/Integer, :special_type :type/PK}
{:name "favorite_snack", :database_type "NULL", :base_type :type/*, :special_type nil}
{:name "name", :database_type "java.lang.String", :base_type :type/Text, :special_type :type/Name}]
(data/dataset metabase.driver.mongo-test/all-null-columns
(map (partial into {})
(db/select [Field :name :database_type :base_type :special_type]
:table_id (data/id :bird_species)
{:order-by [:name]}))))
;;; table-rows-sample
(datasets/expect-with-engine :mongo
......
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