Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Resolve columns from model metadata saved in ~<=55 correctly (#75771)

Cam Saul27852dcc4c49
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/dump_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/dump_test.clj
index ba6cc3ebeee..9014d85e1a4 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/dump_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/dump_test.clj
@@ -47,8 +47,7 @@
["Internal Metabase Database" "public" "v_users" "user_id"]]]],
:fields :none,
:stages [{:source-card "0wVIfjBJWclD0lKeABYYl", :lib/type :mbql.stage/mbql}],
- :strategy :left-join,
- :lib/options {"lib/uuid" "dc61e51d-9dfd-4fa6-a096-f70665a7d988"}}],
+ :strategy :left-join}]
:lib/type :mbql.stage/mbql}],
:database "Internal Metabase Database"},
:parameter_mappings [],
@@ -118,8 +117,6 @@ dataset_query:
- source-card: 0wVIfjBJWclD0lKeABYYl
lib/type: mbql.stage/mbql
strategy: left-join
- lib/options:
- lib/uuid: dc61e51d-9dfd-4fa6-a096-f70665a7d988
lib/type: mbql/join
source-card: skoPT2xiuEcUV8vFkHE6S
lib/type: mbql.stage/mbql
diff --git a/src/metabase/lib/field/resolution.cljc b/src/metabase/lib/field/resolution.cljc
index 483cbd52a56..d8edc061609 100644
--- a/src/metabase/lib/field/resolution.cljc
+++ b/src/metabase/lib/field/resolution.cljc
@@ -259,14 +259,22 @@
(:qp/stage-had-source-card stage)
(let [card-id (:qp/stage-had-source-card stage)]
(when-some [card (lib.metadata/card query card-id)]
- (when-some [card-cols (not-empty (cond->> (lib.metadata.calculation/returned-columns query card)
- ;; if we have `id` then filter out anything that is definitely not a
- ;; match
- (:id col) (filter #(= (:id %) (:id col)))))]
- ;; prefer resolution with `:lib/source-column-alias` over `:id` if we have it because it will be
- ;; unique/unambiguous if multiple versions of the column (e.g. with different bucketing units) are
- ;; returned
- (when-some [col (resolve-in-previous-stage-returned-columns-and-update-keys query card-cols (:lib/source-column-alias col))]
+ (when-some [potential-card-cols (not-empty (cond->> (lib.metadata.calculation/returned-columns query card)
+ ;; if we have `id` then filter out anything that is definitely
+ ;; not a match
+ (:id col) (filter #(= (:id %) (:id col)))))]
+ ;; prefer resolution with `:lib/source-column-alias` over `:id` if multiple versions of the column (e.g.
+ ;; with different bucketing units) are returned. If there's only one match then use ID for resolution. On
+ ;; very old saved Card source metadata `:lib/source-column-alias` might be set to something like `ID_2`
+ ;; rather than `Products__ID` so, matching on it is not as reliable as `:id`, which has been around since
+ ;; the dawn of human history.
+ (when-some [col (let [resolution-key (if (and (:id col)
+ (= (count potential-card-cols) 1))
+ :id
+ :lib/source-column-alias)]
+ (resolve-in-previous-stage-returned-columns-and-update-keys query
+ potential-card-cols
+ (resolution-key col)))]
(let [col (assoc col :lib/source :source/card, :lib/card-id card-id)
model? (= (:type card) :model)
col (cond-> col
diff --git a/src/metabase/lib/join.cljc b/src/metabase/lib/join.cljc
index 62771726111..eb9c84b901f 100644
--- a/src/metabase/lib/join.cljc
+++ b/src/metabase/lib/join.cljc
@@ -448,28 +448,24 @@
;;; TODO -- this probably ought to live in [[metabase.lib.query]]
(defmethod join-clause-method :mbql/query
[another-query]
- (-> {:lib/type :mbql/join
- :stages (:stages (lib.util/pipeline another-query))}
- lib.options/ensure-uuid))
+ {:lib/type :mbql/join
+ :stages (:stages (lib.util/pipeline another-query))})
;;; TODO -- this probably ought to live in [[metabase.lib.stage]]
(defmethod join-clause-method :mbql.stage/mbql
[mbql-stage]
- (-> {:lib/type :mbql/join
- :stages [mbql-stage]}
- lib.options/ensure-uuid))
+ {:lib/type :mbql/join
+ :stages [mbql-stage]})
(defmethod join-clause-method :metadata/card
[card]
- (-> {:lib/type :mbql/join
- :stages [{:source-card (:id card)
- :lib/type :mbql.stage/mbql}]}
- lib.options/ensure-uuid))
+ {:lib/type :mbql/join
+ :stages [{:source-card (:id card)
+ :lib/type :mbql.stage/mbql}]})
(defmethod join-clause-method :metadata/table
[{:keys [lib/join-alias], :as table-metadata}]
(cond-> (join-clause-method {:lib/type :mbql.stage/mbql
- :lib/options {:lib/uuid (str (random-uuid))}
:source-table (:id table-metadata)})
join-alias (with-join-alias join-alias)))
diff --git a/src/metabase/lib/schema.cljc b/src/metabase/lib/schema.cljc
index 85720dd62da..5dd20c0e0a1 100644
--- a/src/metabase/lib/schema.cljc
+++ b/src/metabase/lib/schema.cljc
@@ -383,7 +383,8 @@
{:source-metadata "A query stage should not have :source-metadata, the prior stage should have :lib/stage-metadata instead"
:source-query ":source-query is not allowed in MBQL 5 queries."
:type ":type is not allowed in a query stage in any version of MBQL"
- :database ":database is not allowed in a query stage, only at the top level of a query."})])
+ :database ":database is not allowed in a query stage, only at the top level of a query."
+ :lib/options "A stage should not have :lib/options"})])
(mr/def ::stage.initial
[:multi {:dispatch lib-type
diff --git a/src/metabase/lib/schema/join.cljc b/src/metabase/lib/schema/join.cljc
index f13c2fba38c..6f25c19a973 100644
--- a/src/metabase/lib/schema/join.cljc
+++ b/src/metabase/lib/schema/join.cljc
@@ -139,7 +139,8 @@
:filter "join should not have top-level :filters; these should belong to one of the join :stages"
:filters "join should not have top-level :filters; these should belong to one of the join :stages"
:parameters "join should not have top-level :parameters; these should belong to one of the join :stages"
- :ident ":ident is deprecated and should not be included in joins"})
+ :ident ":ident is deprecated and should not be included in joins"
+ :lib/options "A join should not have :lib/options"})
[:ref ::validate-field-aliases-match-join-alias]])
(mr/def ::joins
diff --git a/src/metabase/lib/util.cljc b/src/metabase/lib/util.cljc
index 21d24af009e..237de9bbefe 100644
--- a/src/metabase/lib/util.cljc
+++ b/src/metabase/lib/util.cljc
@@ -254,8 +254,7 @@
(dissoc :source-table :source-query :source-metadata)
(update-legacy-boolean-expression->list :condition :conditions)
(assoc :lib/type :mbql/join
- :stages stages)
- lib.options/ensure-uuid)))
+ :stages stages))))
(defn- joins->pipeline [joins]
(mapv join->pipeline joins))
diff --git a/test/metabase/lib/convert_test.cljc b/test/metabase/lib/convert_test.cljc
index bec593a9123..98d2f9c16d8 100644
--- a/test/metabase/lib/convert_test.cljc
+++ b/test/metabase/lib/convert_test.cljc
@@ -85,7 +85,6 @@
{:lib/uuid string?, :join-alias "CATEGORIES__via__CATEGORY_ID"}
(meta/id :categories :name)]]
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "CATEGORIES__via__CATEGORY_ID"
:conditions [[:=
{:lib/uuid string?}
@@ -172,7 +171,6 @@
:database (meta/id)
:stages [{:lib/type :mbql.stage/mbql
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "__join"
:conditions [[:=
{:lib/uuid string?}
@@ -186,7 +184,6 @@
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :venues)}]}
{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "__join_2"
:conditions [[:=
{:lib/uuid string?}
@@ -215,8 +212,7 @@
[:field {:lib/uuid string?} 2]]]
:lib/type :mbql/join
:stages [{:lib/type :mbql.stage/mbql
- :source-table 3}]
- :lib/options {:lib/uuid string?}}]
+ :source-table 3}]}]
:limit 1
:source-table 4}]
:database 5}
diff --git a/test/metabase/lib/field/resolution_test.cljc b/test/metabase/lib/field/resolution_test.cljc
index 077995432ea..639e3d4a47f 100644
--- a/test/metabase/lib/field/resolution_test.cljc
+++ b/test/metabase/lib/field/resolution_test.cljc
@@ -14,7 +14,9 @@
[metabase.lib.metadata.result-metadata :as lib.metadata.result-metadata]
[metabase.lib.metadata.result-metadata-test]
[metabase.lib.options :as lib.options]
+ [metabase.lib.schema :as lib.schema]
[metabase.lib.schema.id :as id]
+ [metabase.lib.schema.metadata :as lib.schema.metadata]
[metabase.lib.test-metadata :as meta]
[metabase.lib.test-util :as lib.tu]
[metabase.lib.test-util.macros :as lib.tu.macros]
@@ -102,7 +104,6 @@
:lib/metadata metabase.lib.field-test/grandparent-parent-child-metadata-provider
:database (meta/id)
:stages [{:lib/type :mbql.stage/mbql
- :lib/options {:lib/uuid (str (random-uuid))}
:source-table (meta/id :venues)}]}
-1
a-field-clause))]
@@ -1859,3 +1860,70 @@
field-ref (lib/ref (m/find-first #(= (:name %) "nested_col") (lib/fieldable-columns query)))]
(is (=? {:name "nested_col"}
(lib.field.resolution/resolve-field-ref query -1 field-ref))))))
+
+(deftest ^:parallel resolve-old-model-metadata-correctly-test
+ (testing "Resolve fields from old model metadata (saved in ~55 or older) that is missing modern lib keys correctly (#65532)"
+ (let [mp (as-> meta/metadata-provider $mp
+ (lib.tu/mock-metadata-provider
+ $mp
+ {:cards [(let [query (-> (-> (lib/query $mp (lib.metadata/table $mp (meta/id :orders)))
+ (lib/with-fields [(lib.metadata/field $mp (meta/id :orders :id))]))
+ (lib/join (-> (lib/join-clause (lib.metadata/table $mp (meta/id :products)))
+ (lib/with-join-fields [(lib.metadata/field $mp (meta/id :products :id))]))))
+ ;; simulate metadata as saved by 55
+ metadata (into []
+ (keep (fn [col]
+ (-> col
+ (assoc :name (:lib/deduplicated-name col))
+ (dissoc :lib/source-column-alias
+ :lib/desired-column-alias
+ :lib/deduplicated-name
+ :lib/original-name)
+ (cond->
+ (= (:display-name col) "Products → ID")
+ (assoc :display-name "[RENAMED]")))))
+ (lib.metadata.result-metadata/returned-columns query))]
+ {:id 1
+ :type :model
+ :dataset-query query
+ :result-metadata metadata})]})
+ (lib.tu/mock-metadata-provider
+ $mp
+ {:cards [{:id 2
+ :dataset-query (lib/query $mp (lib.metadata/card $mp 1))
+ :source-card-id 1}]}))
+ query (lib/normalize
+ ::lib.schema/query
+ {:database (meta/id)
+ :lib/type :mbql/query
+ :lib/metadata mp
+ :stages [(-> (lib/query-stage (:dataset-query (lib.metadata/card mp 1)) 0)
+ (assoc :qp/stage-is-from-source-card 1))
+ (-> (lib/query-stage (:dataset-query (lib.metadata/card mp 2)) 0)
+ (dissoc :source-card)
+ (assoc :qp/stage-had-source-card 1
+ :qp/stage-is-from-source-card 2))]})]
+ (is (=? {:base-type :type/BigInteger
+ :display-name "[RENAMED]"
+ :id (meta/id :products :id)
+ :semantic-type :type/PK
+ :table-id (meta/id :products)
+ :visibility-type :normal
+ :lib/card-id 1
+ :lib/from-model? true
+ :lib/original-display-name "[RENAMED]"
+ :lib/original-join-alias "Products"
+ :lib/original-name "ID_2"
+ :lib/type :metadata/column}
+ (lib/metadata query -1
+ (#'lib.field.resolution/additional-metadata-from-source-card
+ query
+ -1
+ (lib/normalize
+ ::lib.schema.metadata/column
+ {:lib/type :metadata/column
+ :lib/source :source/previous-stage
+ :id (meta/id :products :id)
+ :name "Products__ID"
+ :lib/source-column-alias "Products__ID"
+ :base-type :type/Integer}))))))))
diff --git a/test/metabase/lib/join_test.cljc b/test/metabase/lib/join_test.cljc
index e2a5544f7a6..25fa750bb8b 100644
--- a/test/metabase/lib/join_test.cljc
+++ b/test/metabase/lib/join_test.cljc
@@ -42,7 +42,6 @@
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :venues)
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "Categories"
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :categories)}]
@@ -76,9 +75,8 @@
(is (not (contains? (first (:stages (lib/with-join-source-fields with-it nil))) :fields)))
(is (not (contains? (first (:stages (lib/with-join-source-fields with-it []))) :fields)))))
(testing "Rejects a native-stage inner with a clear error (not a malli output-schema mess)"
- (let [native-join (assoc base-join :stages [{:lib/type :mbql.stage/native
- :lib/options {:lib/uuid (str (random-uuid))}
- :native "SELECT 1"}])]
+ (let [native-join (assoc base-join :stages [{:lib/type :mbql.stage/native
+ :native "SELECT 1"}])]
#?(:clj (is (thrown-with-msg? clojure.lang.ExceptionInfo
#"requires the join's first stage to be an MBQL stage"
(lib/with-join-source-fields native-join
@@ -156,11 +154,10 @@
(deftest ^:parallel join-clause-test
(testing "Should have :fields :all by default (#32419)"
- (is (=? {:lib/type :mbql/join
- :stages [{:lib/type :mbql.stage/mbql
- :source-table (meta/id :orders)}]
- :lib/options {:lib/uuid string?}
- :fields :all}
+ (is (=? {:lib/type :mbql/join
+ :stages [{:lib/type :mbql.stage/mbql
+ :source-table (meta/id :orders)}]
+ :fields :all}
(lib/join-clause (meta/table-metadata :orders)))))
(testing "Should allow specifying the join strategy when creating a join clause"
(is (= [:left-join :right-join :inner-join]
@@ -237,7 +234,6 @@
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :categories)
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "Venues"
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :venues)}]
@@ -268,7 +264,6 @@
(lib/visible-columns q2))]
(let [clause (lib/join-clause q2 [(lib/= categories-id-metadata venues-category-id-metadata)])]
(is (=? {:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :venues)}]
:conditions [[:=
@@ -282,7 +277,6 @@
(is (=? {:database (meta/id)
:stages [{:source-table (meta/id :categories)
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "Venues"
:stages [{:source-table (meta/id :venues)}]
:conditions [[:=
@@ -319,14 +313,12 @@
(testing "Display name for a joined field should include a nice name for the join; include other info like :source-alias"
(let [query {:lib/type :mbql/query
:stages [{:lib/type :mbql.stage/mbql
- :lib/options {:lib/uuid "fdcfaa06-8e65-471d-be5a-f1e821022482"}
:source-table (meta/id :venues)
:fields [[:field
{:join-alias "CATEGORIES__via__CATEGORY_ID"
:lib/uuid "8704e09b-496e-4045-8148-1eef28e96b51"}
(meta/id :categories :name)]]
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid "490a5abb-54c2-4e62-9196-7e9e99e8d291"}
:alias "CATEGORIES__via__CATEGORY_ID"
:conditions [[:=
{:lib/uuid "cc5f6c43-1acb-49c2-aeb5-e3ff9c70541f"}
@@ -335,7 +327,6 @@
:strategy :left-join
:fk-field-id (meta/id :venues :category-id)
:stages [{:lib/type :mbql.stage/mbql
- :lib/options {:lib/uuid "bbbae500-c972-4550-b100-e0584eb72c4d"}
:source-table (meta/id :categories)}]}]}]
:database (meta/id)
:lib/metadata meta/metadata-provider}
@@ -359,7 +350,6 @@
{:aggregation [[:count]]
:breakout [$user-id]})])
join {:lib/type :mbql/join
- :lib/options {:lib/uuid "d7ebb6bd-e7ac-411a-9d09-d8b18329ad46"}
:stages [{:lib/type :mbql.stage/mbql
:source-card 1}]
:alias "checkins_by_user"
@@ -473,7 +463,6 @@
:stages [{:lib/type :mbql.stage/mbql
:source-table (meta/id :categories)
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid "10ee93eb-6749-41ed-a48b-93c66427eb49"}
:alias join-alias
:fields [[:field
{:join-alias join-alias
@@ -488,7 +477,6 @@
{:lib/uuid "c5203ef8-d56d-474c-b176-2853a3f017b0"}
(meta/id :categories :id)]]]
:stages [{:lib/type :mbql.stage/mbql
- :lib/options {:lib/uuid "e8888108-22a7-4f97-8315-ff63503634d7"}
:source-table (meta/id :categories)}]}]}]}]
(is (=? [{:name "ID"
:display-name "ID"
diff --git a/test/metabase/lib/metadata/result_metadata_test.cljc b/test/metabase/lib/metadata/result_metadata_test.cljc
index 319499adb07..3b4bd139062 100644
--- a/test/metabase/lib/metadata/result_metadata_test.cljc
+++ b/test/metabase/lib/metadata/result_metadata_test.cljc
@@ -1070,7 +1070,6 @@
(meta/id :orders :product-id)]
[:field {:join-alias "PRODUCTS__via__PRODUCT_ID"}
(meta/id :products :id)]]]
- :lib/options {:lib/uuid "14b26511-68b9-48d6-9968-b115a5089009"}
:fk-field-id (meta/id :orders :product-id)}]
:aggregation [[:count {:lib/uuid "3a14967e-bd6c-4cdd-a837-b6d098ef513b", :name "count"}]
[:sum {:name "sum"}
diff --git a/test/metabase/lib/normalize_test.cljc b/test/metabase/lib/normalize_test.cljc
index 158af553893..46994b65828 100644
--- a/test/metabase/lib/normalize_test.cljc
+++ b/test/metabase/lib/normalize_test.cljc
@@ -131,8 +131,7 @@
:lib/uuid "ff3dc321-27a7-42d8-a7fc-518160250984"
:effective-type "type/Integer"}
76329)))
- :stages ({:lib/type "mbql.stage/mbql", :source-card 13281})
- :lib/options #:lib{:uuid "517699ac-dede-4f6b-bc53-272def3eea8b"}})
+ :stages ({:lib/type "mbql.stage/mbql", :source-card 13281})})
:lib/type "mbql.stage/mbql"
:source-table 11763
:fields (("field"
@@ -213,7 +212,6 @@
76329]]]
:fields :all
:stages [{:source-card 13281, :lib/type :mbql.stage/mbql}]
- :lib/options {:lib/uuid "517699ac-dede-4f6b-bc53-272def3eea8b"}
:lib/type :mbql/join}]
:limit 3
:source-table 11763
diff --git a/test/metabase/lib/schema_test.cljc b/test/metabase/lib/schema_test.cljc
index bce9e1e7126..11b3c189dde 100644
--- a/test/metabase/lib/schema_test.cljc
+++ b/test/metabase/lib/schema_test.cljc
@@ -118,7 +118,6 @@
{:lib/type :mbql.stage/mbql
:source-table 1
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid (str (random-uuid))}
:alias "Q1"
:fields :all
:conditions [[:=
@@ -131,7 +130,7 @@
:order-by [[:asc
{:lib/uuid (str (random-uuid))}
[:aggregation {:lib/uuid (str (random-uuid))} good-ref]]]}
- {:lib/type :mbql.stage/mbql, :lib/options {:lib/uuid (str (random-uuid))}}]}]}
+ {:lib/type :mbql.stage/mbql}]}]}
nil)))
(def ^:private valid-expression
@@ -167,7 +166,6 @@
{:lib/type :mbql.stage/mbql
:source-table 1
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid (str (random-uuid))}
:alias "Q1"
:fields :all
:conditions [[:=
@@ -180,7 +178,7 @@
:order-by [[:asc
{:lib/uuid (str (random-uuid))}
[:expression {:lib/uuid (str (random-uuid))} "price + 2"]]]}
- {:lib/type :mbql.stage/mbql, :lib/options {:lib/uuid (str (random-uuid))}}]}]}
+ {:lib/type :mbql.stage/mbql}]}]}
nil))
(defn- valid-join
@@ -194,7 +192,6 @@
([join-alias condition]
{:lib/type :mbql/join
- :lib/options {:lib/uuid (str (random-uuid))}
:alias join-alias
:conditions [condition]
:stages [{:lib/type :mbql.stage/mbql
diff --git a/test/metabase/lib/stage_test.cljc b/test/metabase/lib/stage_test.cljc
index 8aa83f69677..cadaa47af69 100644
--- a/test/metabase/lib/stage_test.cljc
+++ b/test/metabase/lib/stage_test.cljc
@@ -24,7 +24,6 @@
(testing "make sure columns are coming back the way we'd expect for :field clauses"
(let [query {:lib/type :mbql/query
:stages [{:lib/type :mbql.stage/mbql
- :lib/options {:lib/uuid "0311c049-4973-4c2a-8153-1e2c887767f9"}
:source-table (meta/id :venues)
:fields [(lib.tu/field-clause :venues :price)]}]
:database (meta/id)
diff --git a/test/metabase/lib/util_test.cljc b/test/metabase/lib/util_test.cljc
index 5c4a701cd7d..eb8dac0b4ba 100644
--- a/test/metabase/lib/util_test.cljc
+++ b/test/metabase/lib/util_test.cljc
@@ -42,9 +42,8 @@
;; already a pipeline: nothing to do
{:database 1
:lib/type :mbql/query
- :stages [{:lib/type :mbql.stage/native
- :lib/options {:lib/uuid "ef87e113-7436-41dd-9f78-3232c6778436"}
- :native "SELECT * FROM VENUES;"}]}
+ :stages [{:lib/type :mbql.stage/native
+ :native "SELECT * FROM VENUES;"}]}
{:database 1
:lib/type :mbql/query
:stages [{:lib/type :mbql.stage/native
@@ -58,7 +57,6 @@
:stages [{:lib/type :mbql.stage/mbql
:fields [[:field (meta/id :categories :name) {:join-alias "CATEGORIES__via__CATEGORY_ID"}]]
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid string?}
:alias "CATEGORIES__via__CATEGORY_ID"
:conditions [[:=
[:field (meta/id :venues :category-id)]
diff --git a/test/metabase/query_processor/model_test.clj b/test/metabase/query_processor/model_test.clj
index 7a1885a521c..4ddbf82a7a7 100644
--- a/test/metabase/query_processor/model_test.clj
+++ b/test/metabase/query_processor/model_test.clj
@@ -1,5 +1,7 @@
(ns metabase.query-processor.model-test
(:require
+ [clojure.edn :as edn]
+ [clojure.string :as str]
[clojure.test :refer [deftest is testing]]
[medley.core :as m]
[metabase.lib.core :as lib]
@@ -107,6 +109,12 @@
"Products+Reviews Summary - Reviews → Created At: Month → Sum of Price"]
(mapv :display_name (qp.preprocess/query->expected-cols question)))))))
+(defn- read-metadata [filename]
+ (->> filename
+ slurp
+ (edn/read-string {:readers {'id (fn [id]
+ (apply mt/id (map keyword (str/split (name id) #"\."))))}})))
+
(deftest ^:parallel preserve-model-display-names-test
(testing "Edited display names for columns in Models should get preserved (#65532)"
;; 1. Create a Model of ORDERS joining PRODUCTS
@@ -116,32 +124,61 @@
;; 3. Create a new Saved Question using the first Model as its source
;;
;; 4. Run the Saved Question; results metadata incorrectly returns "Products → [RENAMED]"
- (let [mp (as-> (mt/metadata-provider) $mp
- (lib.tu/mock-metadata-provider
- $mp
- {:cards [(let [query (-> (lib/query $mp (lib.metadata/table $mp (mt/id :orders)))
- (lib/join (lib.metadata/table $mp (mt/id :products))))]
- {:id 1
- :type :model
- :dataset-query query
- :result-metadata (for [col (lib.metadata.result-metadata/returned-columns query)]
- (cond-> col
- (= (:display-name col) "Products → ID")
- (assoc :display-name "[RENAMED]")))})]})
- (lib.tu/mock-metadata-provider
- $mp
- {:cards [(let [query (lib/query $mp (lib.metadata/card $mp 1))]
- {:id 2
- :dataset-query query
- :source-card-id 1})]}))
- query (lib/query mp (lib.metadata/card mp 2))
- returned-display-name (fn [query]
- (-> (lib.metadata.result-metadata/returned-columns query)
- (->> (m/find-first #(= (:lib/desired-column-alias %) "Products__ID")))
- :display-name))]
- (is (= "[RENAMED]"
- (returned-display-name query)))
- ;; the bug only seems to trigger if we preprocess the query first
- (testing "preprocessed query should have the same returned display name"
- (is (= "[RENAMED]"
- (returned-display-name (qp.preprocess/preprocess query))))))))
+ ;;
+ ;; Note that the metadata here was captured from following these repro steps in the GUI in 0.55.0; the issue does
+ ;; not seem to reproduce with newly created metadata. NOTE THAT THE METADATA CAPTURED FROM 55 IS WRONG! THE
+ ;; METADATA FOR THE SECOND CARD INCORRECTLY USES the `:id` of `orders.id` for the `products.id` column. We need to
+ ;; work around this 😢
+ (let [model-metadata-55 (read-metadata "test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-1.edn")
+ bad-card-metadata-55 (read-metadata "test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-2.edn")
+ returned-col (fn [query]
+ (m/find-first (fn [col]
+ (and (= (:table-id col) (mt/id :products))
+ ;; the column `:id` in `bad-card-metadata-55` is WRONG, we
+ ;; should be stripping it out; look for a match based on the
+ ;; source column alias instead. Note the 55 metadata will have
+ ;; `ID_2` instead of `Products__ID`
+ (#{"Products__ID" "ID_2"} (:lib/source-column-alias col))))
+ (lib.metadata.result-metadata/returned-columns query)))
+ mp (mt/metadata-provider)
+ model-query (-> (lib/query mp (lib.metadata/table mp (mt/id :orders)))
+ (lib/join (lib.metadata/table mp (mt/id :products))))
+ model-new-metadata (mapv (fn [col]
+ (cond-> col
+ (= (:display-name col) "Products → ID")
+ (assoc :display-name "[RENAMED]")))
+ (lib.metadata.result-metadata/returned-columns model-query))]
+ (doseq [with-55-model-metadata? [true false]
+ with-bad-55-card-metadata? [true false]]
+ (testing (format "with-55-model-metadata? = %b; with-bad-55-card-metadata? = %b"
+ with-55-model-metadata?
+ with-bad-55-card-metadata?)
+ (let [mp (as-> mp $mp
+ (lib.tu/mock-metadata-provider
+ $mp
+ {:cards [{:id 1
+ :type :model
+ :dataset-query model-query
+ :result-metadata (if with-55-model-metadata?
+ model-metadata-55
+ model-new-metadata)}]})
+ (lib.tu/mock-metadata-provider
+ $mp
+ {:cards [(let [query (lib/query $mp (lib.metadata/card $mp 1))]
+ (merge
+ {:id 2
+ :dataset-query query
+ :source-card-id 1}
+ (when with-bad-55-card-metadata?
+ {:result-metadata bad-card-metadata-55})))]}))
+ query (lib/query mp (lib.metadata/card mp 2))]
+ (is (=? {:display-name "[RENAMED]"
+ :id (if with-bad-55-card-metadata?
+ (mt/id :orders :id) ; note that this is the wrong ID
+ (mt/id :products :id))}
+ (returned-col query)))
+ ;; the bug only seems to trigger if we preprocess the query first
+ (testing "preprocessed query should have the same returned display name"
+ (is (=? {:display-name "[RENAMED]"
+ :id (mt/id :products :id)}
+ (returned-col (qp.preprocess/preprocess query)))))))))))
diff --git a/test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-1.edn b/test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-1.edn
new file mode 100644
index 00000000000..bff634edb51
--- /dev/null
+++ b/test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-1.edn
@@ -0,0 +1,393 @@
+[{:description
+ "This is a unique ID for the product. It is also called the “Invoice number” or “Confirmation number” in customer facing emails and screens."
+ :database_type "BIGINT"
+ :semantic_type :type/PK
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "ID"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/BigInteger
+ :id #id :orders.id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__ID"
+ :visibility_type :normal
+ :model/inner_ident "field__ID"
+ :display_name "ID"
+ :fingerprint nil
+ :base_type :type/BigInteger}
+ {:description
+ "The id of the user who made this order. Note that in some cases where an order was created on behalf of a customer who phoned the order in, this might be the employee who handled the request."
+ :database_type "INTEGER"
+ :semantic_type :type/FK
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "USER_ID"
+ :settings nil
+ :fk_target_field_id #id :people.id
+ :effective_type :type/Integer
+ :remapped_to "NAME"
+ :id #id :orders.user_id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__USER_ID"
+ :visibility_type :normal
+ :model/inner_ident "field__USER_ID"
+ :display_name "User ID"
+ :fingerprint {:global {:distinct-count 929, :nil% 0.0}}
+ :base_type :type/Integer}
+ {:description "The product ID. This is an internal identifier for the product, NOT the SKU."
+ :database_type "INTEGER"
+ :semantic_type :type/FK
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "PRODUCT_ID"
+ :settings nil
+ :fk_target_field_id #id :products.id
+ :effective_type :type/Integer
+ :remapped_to "TITLE"
+ :id #id :orders.product_id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__PRODUCT_ID"
+ :visibility_type :normal
+ :model/inner_ident "field__PRODUCT_ID"
+ :display_name "Product ID"
+ :fingerprint {:global {:distinct-count 200, :nil% 0.0}}
+ :base_type :type/Integer}
+ {:description
+ "The raw, pre-tax cost of the order. Note that this might be different in the future from the product price due to promotions, credits, etc."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "SUBTOTAL"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.subtotal
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__SUBTOTAL"
+ :visibility_type :normal
+ :model/inner_ident "field__SUBTOTAL"
+ :display_name "Subtotal"
+ :fingerprint
+ {:global {:distinct-count 340, :nil% 0.0}
+ :type
+ {:type/Number
+ {:min 15.691943673970439
+ :q1 49.74894519060184
+ :q3 105.42965746993103
+ :max 148.22900526552291
+ :sd 32.53705013056317
+ :avg 77.01295465356547}}}
+ :base_type :type/Float}
+ {:description
+ "This is the amount of local and federal taxes that are collected on the purchase. Note that other governmental fees on some products are not included here, but instead are accounted for in the subtotal."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "TAX"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.tax
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__TAX"
+ :visibility_type :normal
+ :model/inner_ident "field__TAX"
+ :display_name "Tax"
+ :fingerprint
+ {:global {:distinct-count 797, :nil% 0.0}
+ :type
+ {:type/Number
+ {:min 0.0
+ :q1 2.273340386603857
+ :q3 5.337275338216307
+ :max 11.12
+ :sd 2.3206651358900316
+ :avg 3.8722100000000004}}}
+ :base_type :type/Float}
+ {:description "The total billed amount."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "TOTAL"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.total
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__TOTAL"
+ :visibility_type :normal
+ :model/inner_ident "field__TOTAL"
+ :display_name "Total"
+ :fingerprint
+ {:global {:distinct-count 4426, :nil% 0.0}
+ :type
+ {:type/Number
+ {:min 8.93914247937167
+ :q1 51.34535490743823
+ :q3 110.29428389265787
+ :max 159.34900526552292
+ :sd 34.26469575709948
+ :avg 80.35871658771228}}}
+ :base_type :type/Float}
+ {:description "Discount amount."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type :type/Discount
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "DISCOUNT"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.discount
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__DISCOUNT"
+ :visibility_type :normal
+ :model/inner_ident "field__DISCOUNT"
+ :display_name "Discount"
+ :fingerprint
+ {:global {:distinct-count 701, :nil% 0.898}
+ :type
+ {:type/Number
+ {:min 0.17088996672584322
+ :q1 2.9786226681458743
+ :q3 7.338187788658235
+ :max 61.69684269960571
+ :sd 3.053663125001991
+ :avg 5.161255547580326}}}
+ :base_type :type/Float}
+ {:description "The date and time an order was submitted."
+ :database_type "TIMESTAMP"
+ :semantic_type :type/CreationTimestamp
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "CREATED_AT"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/DateTime
+ :id #id :orders.created_at
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__CREATED_AT"
+ :visibility_type :normal
+ :model/inner_ident "field__CREATED_AT"
+ :display_name "Created At"
+ :fingerprint
+ {:global {:distinct-count 10001, :nil% 0.0}
+ :type {:type/DateTime {:earliest "2022-04-30T18:56:13.352Z", :latest "2026-04-19T14:07:15.657Z"}}}
+ :base_type :type/DateTime}
+ {:description "Number of products bought."
+ :database_type "INTEGER"
+ :semantic_type :type/Quantity
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "QUANTITY"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Integer
+ :id #id :orders.quantity
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__QUANTITY"
+ :visibility_type :normal
+ :model/inner_ident "field__QUANTITY"
+ :display_name "Quantity"
+ :fingerprint
+ {:global {:distinct-count 62, :nil% 0.0}
+ :type
+ {:type/Number
+ {:min 0.0, :q1 1.755882607764982, :q3 4.882654507928044, :max 100.0, :sd 4.214258386403798, :avg 3.7015}}}
+ :base_type :type/Integer}
+ {:description "The name of the user who owns an account"
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Name
+ :table_id #id :people
+ :coercion_strategy nil
+ :name "NAME"
+ :settings nil
+ :fk_target_field_id nil
+ :remapped_from "USER_ID"
+ :effective_type :type/Text
+ :id #id :people.name
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[implicit_via__field__USER_ID]__field__NAME"
+ :visibility_type :normal
+ :model/inner_ident "join[implicit_via__field__USER_ID]__field__NAME"
+ :display_name "User ID"
+ :fingerprint
+ {:global {:distinct-count 2499, :nil% 0.0}
+ :type
+ {:type/Text
+ {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :percent-state 0.0, :average-length 13.532}}}
+ :base_type :type/Text}
+{:description "The name of the product as it should be displayed to customers."
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Title
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "TITLE"
+ :settings nil
+ :fk_target_field_id nil
+ :remapped_from "PRODUCT_ID"
+ :effective_type :type/Text
+ :id #id :products.title
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[implicit_via__field__PRODUCT_ID]__field__TITLE"
+ :visibility_type :normal
+ :model/inner_ident "join[implicit_via__field__PRODUCT_ID]__field__TITLE"
+ :display_name "Product ID"
+ :fingerprint
+ {:global {:distinct-count 199, :nil% 0.0}
+ :type
+ {:type/Text
+ {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :percent-state 0.0, :average-length 21.495}}}
+ :base_type :type/Text}
+ {:description
+ "The numerical product number. Only used internally. All external communication should use the title or EAN."
+ :database_type "BIGINT"
+ :semantic_type :type/PK
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "ID_2"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/BigInteger
+ :id #id :products.id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__ID"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__ID"
+ :display_name "[RENAMED]"
+ :fingerprint nil
+ :base_type :type/BigInteger}
+ {:description "The international article number. A 13 digit number uniquely identifying the product."
+ :database_type "CHARACTER"
+ :semantic_type nil
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "EAN"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.ean
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__EAN"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__EAN"
+ :display_name "Products → Ean"
+ :fingerprint
+ {:global {:distinct-count 200, :nil% 0.0}
+ :type
+ {:type/Text {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :percent-state 0.0, :average-length 13.0}}}
+ :base_type :type/Text}
+ {:description "The name of the product as it should be displayed to customers."
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Title
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "TITLE_2"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.title
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__TITLE"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__TITLE"
+ :display_name "Products → Title"
+ :fingerprint
+ {:global {:distinct-count 199, :nil% 0.0}
+ :type
+ {:type/Text
+ {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :percent-state 0.0, :average-length 21.495}}}
+ :base_type :type/Text}
+ {:description "The type of product, valid values include: Doohicky, Gadget, Gizmo and Widget"
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Category
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "CATEGORY"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.category
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__CATEGORY"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__CATEGORY"
+ :display_name "Products → Category"
+ :fingerprint
+ {:global {:distinct-count 4, :nil% 0.0}
+ :type
+ {:type/Text
+ {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :percent-state 0.0, :average-length 6.375}}}
+ :base_type :type/Text}
+ {:description "The source of the product."
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Company
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "VENDOR"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.vendor
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__VENDOR"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__VENDOR"
+ :display_name "Products → Vendor"
+ :fingerprint
+ {:global {:distinct-count 200, :nil% 0.0}
+ :type
+ {:type/Text {:percent-json 0.0, :percent-url 0.0, :percent-email 0.0, :percent-state 0.0, :average-length 20.6}}}
+ :base_type :type/Text}
+ {:description
+ "The list price of the product. Note that this is not always the price the product sold for due to discounts, promotions, etc."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "PRICE"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :products.price
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__PRICE"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__PRICE"
+ :display_name "Products → Price"
+ :fingerprint
+ {:global {:distinct-count 170, :nil% 0.0}
+ :type
+ {:type/Number
+ {:min 15.691943673970439
+ :q1 37.25154462926434
+ :q3 75.45898071609447
+ :max 98.81933684368194
+ :sd 21.711481557852057
+ :avg 55.74639966792074}}}
+ :base_type :type/Float}
+ {:description "The average rating users have given the product. This ranges from 1 - 5"
+ :database_type "DOUBLE PRECISION"
+ :semantic_type :type/Score
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "RATING"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :products.rating
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__RATING"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__RATING"
+ :display_name "Products → Rating"
+ :fingerprint
+ {:global {:distinct-count 23, :nil% 0.0}
+ :type
+ {:type/Number
+ {:min 0.0, :q1 3.5120465053408525, :q3 4.216124969497314, :max 5.0, :sd 1.3605488657451452, :avg 3.4715}}}
+ :base_type :type/Float}
+ {:description "The date the product was added to our catalog."
+ :database_type "TIMESTAMP"
+ :semantic_type :type/CreationTimestamp
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "CREATED_AT_2"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/DateTime
+ :id #id :products.created_at
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__CREATED_AT"
+ :visibility_type :normal
+ :model/inner_ident "join[7k7GhJ8XH5wF75PHE8Z_Y]__field__CREATED_AT"
+ :display_name "Products → Created At"
+ :fingerprint
+ {:global {:distinct-count 200, :nil% 0.0}
+ :type {:type/DateTime {:earliest "2022-04-26T19:29:55.147Z", :latest "2025-04-15T13:34:19.931Z"}}}
+ :base_type :type/DateTime}]
diff --git a/test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-2.edn b/test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-2.edn
new file mode 100644
index 00000000000..00a9fe05c4d
--- /dev/null
+++ b/test/metabase/query_processor/model_test/preserve-model-display-names-test-metadata-2.edn
@@ -0,0 +1,367 @@
+;; ⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠
+;; THIS IS BAD METADATA, SEE NOTES IN [[metabase.query-processor.model-test/preserve-model-display-names-test]]
+;; ⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠
+[{:description
+ "This is a unique ID for the product. It is also called the “Invoice number” or “Confirmation number” in customer facing emails and screens."
+ :database_type "BIGINT"
+ :semantic_type :type/PK
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "ID"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/BigInteger
+ :id #id :orders.id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__ID"
+ :visibility_type :normal
+ :display_name "ID"
+ :fingerprint nil
+ :base_type :type/BigInteger}
+ {:description
+ "The id of the user who made this order. Note that in some cases where an order was created on behalf of a customer who phoned the order in, this might be the employee who handled the request."
+ :database_type "INTEGER"
+ :semantic_type :type/FK
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "USER_ID"
+ :settings nil
+ :fk_target_field_id #id :people.id
+ :effective_type :type/Integer
+ :remapped_to "NAME"
+ :id #id :orders.user_id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__USER_ID"
+ :visibility_type :normal
+ :display_name "User ID"
+ :fingerprint {:global {:distinct-count 929, :nil% 0}}
+ :base_type :type/Integer}
+ {:description "The product ID. This is an internal identifier for the product, NOT the SKU."
+ :database_type "INTEGER"
+ :semantic_type :type/FK
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "PRODUCT_ID"
+ :settings nil
+ :fk_target_field_id #id :products.id
+ :effective_type :type/Integer
+ :remapped_to "TITLE_2"
+ :id #id :orders.product_id
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__PRODUCT_ID"
+ :visibility_type :normal
+ :display_name "Product ID"
+ :fingerprint {:global {:distinct-count 200, :nil% 0}}
+ :base_type :type/Integer}
+ {:description
+ "The raw, pre-tax cost of the order. Note that this might be different in the future from the product price due to promotions, credits, etc."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "SUBTOTAL"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.subtotal
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__SUBTOTAL"
+ :visibility_type :normal
+ :display_name "Subtotal"
+ :fingerprint
+ {:global {:distinct-count 340, :nil% 0}
+ :type
+ {:type/Number
+ {:min 15.691943673970439
+ :q1 49.74894519060184
+ :q3 105.42965746993103
+ :max 148.22900526552291
+ :sd 32.53705013056317
+ :avg 77.01295465356547}}}
+ :base_type :type/Float}
+ {:description
+ "This is the amount of local and federal taxes that are collected on the purchase. Note that other governmental fees on some products are not included here, but instead are accounted for in the subtotal."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "TAX"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.tax
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__TAX"
+ :visibility_type :normal
+ :display_name "Tax"
+ :fingerprint
+ {:global {:distinct-count 797, :nil% 0}
+ :type
+ {:type/Number
+ {:min 0
+ :q1 2.273340386603857
+ :q3 5.337275338216307
+ :max 11.12
+ :sd 2.3206651358900316
+ :avg 3.8722100000000004}}}
+ :base_type :type/Float}
+ {:description "The total billed amount."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "TOTAL"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.total
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__TOTAL"
+ :visibility_type :normal
+ :display_name "Total"
+ :fingerprint
+ {:global {:distinct-count 4426, :nil% 0}
+ :type
+ {:type/Number
+ {:min 8.93914247937167
+ :q1 51.34535490743823
+ :q3 110.29428389265787
+ :max 159.34900526552292
+ :sd 34.26469575709948
+ :avg 80.35871658771228}}}
+ :base_type :type/Float}
+ {:description "Discount amount."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type :type/Discount
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "DISCOUNT"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :orders.discount
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__DISCOUNT"
+ :visibility_type :normal
+ :display_name "Discount"
+ :fingerprint
+ {:global {:distinct-count 701, :nil% 0.898}
+ :type
+ {:type/Number
+ {:min 0.17088996672584322
+ :q1 2.9786226681458743
+ :q3 7.338187788658235
+ :max 61.69684269960571
+ :sd 3.053663125001991
+ :avg 5.161255547580326}}}
+ :base_type :type/Float}
+ {:description "The date and time an order was submitted."
+ :database_type "TIMESTAMP"
+ :semantic_type :type/CreationTimestamp
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "CREATED_AT"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/DateTime
+ :id #id :orders.created_at
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__CREATED_AT"
+ :visibility_type :normal
+ :display_name "Created At"
+ :fingerprint
+ {:global {:distinct-count 10001, :nil% 0}
+ :type {:type/DateTime {:earliest "2022-04-30T18:56:13.352Z", :latest "2026-04-19T14:07:15.657Z"}}}
+ :base_type :type/DateTime}
+ {:description "Number of products bought."
+ :database_type "INTEGER"
+ :semantic_type :type/Quantity
+ :table_id #id :orders
+ :coercion_strategy nil
+ :name "QUANTITY"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Integer
+ :id #id :orders.quantity
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__field__QUANTITY"
+ :visibility_type :normal
+ :display_name "Quantity"
+ :fingerprint
+ {:global {:distinct-count 62, :nil% 0}
+ :type
+ {:type/Number
+ {:min 0, :q1 1.755882607764982, :q3 4.882654507928044, :max 100, :sd 4.214258386403798, :avg 3.7015}}}
+ :base_type :type/Integer}
+ {:description
+ "This is a unique ID for the product. It is also called the “Invoice number” or “Confirmation number” in customer facing emails and screens."
+ :database_type "BIGINT"
+ :semantic_type :type/PK
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "ID_2"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/BigInteger
+ :id #id :orders.id, ; <= NOTE THAT THIS IS WRONG!!!!!!!
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__ID"
+ :visibility_type :normal
+ :display_name "ID"
+ :fingerprint nil
+ :base_type :type/BigInteger}
+ {:description "The international article number. A 13 digit number uniquely identifying the product."
+ :database_type "CHARACTER"
+ :semantic_type nil
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "EAN"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.ean
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__EAN"
+ :visibility_type :normal
+ :display_name "Products → Ean"
+ :fingerprint
+ {:global {:distinct-count 200, :nil% 0}
+ :type {:type/Text {:percent-json 0, :percent-url 0, :percent-email 0, :percent-state 0, :average-length 13}}}
+ :base_type :type/Text}
+ {:description "The name of the product as it should be displayed to customers."
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Title
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "TITLE"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.title
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__TITLE"
+ :visibility_type :normal
+ :display_name "Products → Title"
+ :fingerprint
+ {:global {:distinct-count 199, :nil% 0}
+ :type {:type/Text {:percent-json 0, :percent-url 0, :percent-email 0, :percent-state 0, :average-length 21.495}}}
+ :base_type :type/Text}
+ {:description "The type of product, valid values include: Doohicky, Gadget, Gizmo and Widget"
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Category
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "CATEGORY"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.category
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__CATEGORY"
+ :visibility_type :normal
+ :display_name "Products → Category"
+ :fingerprint
+ {:global {:distinct-count 4, :nil% 0}
+ :type {:type/Text {:percent-json 0, :percent-url 0, :percent-email 0, :percent-state 0, :average-length 6.375}}}
+ :base_type :type/Text}
+ {:description "The source of the product."
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Company
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "VENDOR"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Text
+ :id #id :products.vendor
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__VENDOR"
+ :visibility_type :normal
+ :display_name "Products → Vendor"
+ :fingerprint
+ {:global {:distinct-count 200, :nil% 0}
+ :type {:type/Text {:percent-json 0, :percent-url 0, :percent-email 0, :percent-state 0, :average-length 20.6}}}
+ :base_type :type/Text}
+ {:description
+ "The list price of the product. Note that this is not always the price the product sold for due to discounts, promotions, etc."
+ :database_type "DOUBLE PRECISION"
+ :semantic_type nil
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "PRICE"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :products.price
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__PRICE"
+ :visibility_type :normal
+ :display_name "Products → Price"
+ :fingerprint
+ {:global {:distinct-count 170, :nil% 0}
+ :type
+ {:type/Number
+ {:min 15.691943673970439
+ :q1 37.25154462926434
+ :q3 75.45898071609447
+ :max 98.81933684368194
+ :sd 21.711481557852057
+ :avg 55.74639966792074}}}
+ :base_type :type/Float}
+ {:description "The average rating users have given the product. This ranges from 1 - 5"
+ :database_type "DOUBLE PRECISION"
+ :semantic_type :type/Score
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "RATING"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/Float
+ :id #id :products.rating
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__RATING"
+ :visibility_type :normal
+ :display_name "Products → Rating"
+ :fingerprint
+ {:global {:distinct-count 23, :nil% 0}
+ :type
+ {:type/Number
+ {:min 0, :q1 3.5120465053408525, :q3 4.216124969497314, :max 5, :sd 1.3605488657451452, :avg 3.4715}}}
+ :base_type :type/Float}
+{:description "The date and time an order was submitted."
+ :database_type "TIMESTAMP"
+ :semantic_type :type/CreationTimestamp
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "CREATED_AT_2"
+ :settings nil
+ :fk_target_field_id nil
+ :effective_type :type/DateTime
+ :id #id :orders.created_at
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__CREATED_AT"
+ :visibility_type :normal
+ :display_name "Created At"
+ :fingerprint
+ {:global {:distinct-count 200, :nil% 0}
+ :type {:type/DateTime {:earliest "2022-04-26T19:29:55.147Z", :latest "2025-04-15T13:34:19.931Z"}}}
+ :base_type :type/DateTime}
+ {:description "The name of the user who owns an account"
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Name
+ :table_id #id :people
+ :coercion_strategy nil
+ :name "NAME"
+ :settings nil
+ :fk_target_field_id nil
+ :remapped_from "USER_ID"
+ :effective_type :type/Text
+ :id #id :people.name
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[implicit_via__field__USER_ID]__field__NAME"
+ :visibility_type :normal
+ :display_name "User ID"
+ :fingerprint
+ {:global {:distinct-count 2499, :nil% 0}
+ :type {:type/Text {:percent-json 0, :percent-url 0, :percent-email 0, :percent-state 0, :average-length 13.532}}}
+ :base_type :type/Text}
+ {:description "The name of the product as it should be displayed to customers."
+ :database_type "CHARACTER VARYING"
+ :semantic_type :type/Title
+ :table_id #id :products
+ :coercion_strategy nil
+ :name "TITLE_2"
+ :settings nil
+ :fk_target_field_id nil
+ :remapped_from "PRODUCT_ID"
+ :effective_type :type/Text
+ :id #id :products.title
+ :ident "model[RB_S8B85ntQ_sLmZKF0lP]__join[7k7GhJ8XH5wF75PHE8Z_Y]__field__TITLE"
+ :visibility_type :normal
+ :display_name "Product ID"
+ :fingerprint
+ {:global {:distinct-count 199, :nil% 0}
+ :type {:type/Text {:percent-json 0, :percent-url 0, :percent-email 0, :percent-state 0, :average-length 21.495}}}
+ :base_type :type/Text}]
diff --git a/test/metabase/util/malli/humanize_test.cljc b/test/metabase/util/malli/humanize_test.cljc
index bf76a287d71..4813d28af7b 100644
--- a/test/metabase/util/malli/humanize_test.cljc
+++ b/test/metabase/util/malli/humanize_test.cljc
@@ -167,7 +167,6 @@
:stages [{:lib/type :mbql.stage/mbql
:source-table 1
:joins [{:lib/type :mbql/join
- :lib/options {:lib/uuid (str (random-uuid))}
:stages [{}]
:conditions [true]}]}]})]
(are [f expected] (= expected