Skip to content

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

Remove group prefixes from Explorations, use curated dimension display name (#79603)

Kevin Kelleher323518210200
diff --git a/src/metabase/explorations/api.clj b/src/metabase/explorations/api.clj
index 20af658530e..b89e0d77cfc 100644
--- a/src/metabase/explorations/api.clj
+++ b/src/metabase/explorations/api.clj
@@ -54,18 +54,6 @@
(api/write-check :model/Collection new-coll)
(api/write-check collection/root-collection)))))
-(defn- exploration-query-dim-label
- "Display label for a dimension inside an ExplorationQuery `name`. When `ambiguous?` and the dim
- has a known group, prefixes with the group's display name and the canonical ` → ` separator
- (matches `metabase.lib.display-name/separator`). Otherwise falls back to the dim's display name
- (or id when missing)."
- [dim ambiguous?]
- (let [dn (or (:display-name dim) (:dimension-id dim))
- group-dn (some-> dim :group :display-name)]
- (if (and ambiguous? (not (str/blank? group-dn)))
- (str group-dn " → " dn)
- dn)))
-
(defn- blocks-by-thread-id
"The persisted blocks (`ExplorationBlock`) for `thread-ids`, in authoring order, grouped by
`:exploration_thread_id`."
@@ -76,51 +64,32 @@
:exploration_thread_id [:in thread-ids]
{:order-by [[:position :asc] [:id :asc]]}))))
-(defn- enrich-block-dimensions
- "Attach each block dimension's `:group` (source) label from `card-dim-by-id` so the read tree
- can qualify same-named dimension headings by their source."
- [blocks card-dim-by-id]
- (mapv (fn [block]
- (update block :dimensions
- (fn [dims]
- (mapv #(block/enrich-with-card-group % card-dim-by-id) dims))))
- blocks))
-
(defn- attach-query-dimension-labels
"Attach `:dimension_name` to each query on `thread`. Dimension snapshots come from the
- thread's `blocks` (deduped by id); each is enriched with `:group` looked up from
- `card-dim-by-id` (the metric Cards' snapshotted `:dimensions`, the only place that group
- metadata lives), then `exploration-query-dim-label` is applied with ambiguity scoped to the
- thread's dimensions."
- [thread blocks card-dim-by-id]
- (let [thread-dims (vals (u/index-by :dimension-id (mapcat :dimensions blocks)))
- enriched-dims (mapv #(block/enrich-with-card-group % card-dim-by-id)
- thread-dims)
- dim-by-id (u/index-by :dimension-id enriched-dims)
- name-counts (frequencies (keep :display-name enriched-dims))]
+ thread's `blocks` (deduped by id via [[u/index-by]]); each query gets the dim's curated
+ [[block/dimension-label]]."
+ [thread blocks]
+ (let [dim-by-id (u/index-by :dimension-id (mapcat :dimensions blocks))]
(update thread :queries
(fn [queries]
(some->> queries
(mapv (fn [q]
;; `:dimension_id` on a query is the exploration_query DB column.
- (let [dim-id (:dimension_id q)
- dim (or (get dim-by-id dim-id)
- {:dimension-id dim-id})
- ambiguous? (> (get name-counts (:display-name dim) 0) 1)]
+ (let [dim-id (:dimension_id q)
+ dim (or (get dim-by-id dim-id)
+ {:dimension-id dim-id})]
(assoc q :dimension_name
- (exploration-query-dim-label dim ambiguous?))))))))))
+ (block/dimension-label dim))))))))))
(defn- attach-thread-read-data
"Compute the read-side nested `:blocks` (each with its `:pages`) and per-query
- `:dimension_name` labels for `thread` from its pre-fetched `blocks`, `pages`, and the shared
- metric-Card lookup maps (`card-name-by-id` for page/heading names, `card-dim-by-id` for
- dimension source metadata)."
- [thread blocks pages card-name-by-id card-dim-by-id]
- (let [enriched-blocks (enrich-block-dimensions blocks card-dim-by-id)
- ;; Label queries first so blocks-tree can name metric-anchored pages "By <dimension>".
- labeled (attach-query-dimension-labels thread enriched-blocks card-dim-by-id)]
+ `:dimension_name` labels for `thread` from its pre-fetched `blocks`, `pages`, and
+ `card-name-by-id` (metric Card id → name, for page/heading names)."
+ [thread blocks pages card-name-by-id]
+ ;; Label queries first so blocks-tree can name metric-anchored pages "By <dimension>".
+ (let [labeled (attach-query-dimension-labels thread blocks)]
(assoc labeled :blocks (explorations.blocks/blocks-tree
- enriched-blocks pages card-name-by-id (:queries labeled)))))
+ blocks pages card-name-by-id (:queries labeled)))))
(defn- attach-threads-read-data
"Batch [[attach-thread-read-data]] across `threads`: select every thread's blocks, their
@@ -136,15 +105,12 @@
:exploration_block_id [:in block-ids])))
card-ids (distinct (mapcat #(map :card_id (:metrics %)) all-blocks))
cards (when (seq card-ids)
- (t2/select [:model/Card :id :name :dimensions] :id [:in card-ids]))
- card-name-by-id (into {} (map (juxt :id :name)) cards)
- card-dim-by-id (into {}
- (mapcat (fn [c] (map (juxt :id identity) (:dimensions c))))
- cards)]
+ (t2/select [:model/Card :id :name] :id [:in card-ids]))
+ card-name-by-id (into {} (map (juxt :id :name)) cards)]
(mapv (fn [thread]
(let [blocks (get blocks-by-thread (:id thread) [])
pages (mapcat #(get pages-by-block (:id %) []) blocks)]
- (attach-thread-read-data thread blocks pages card-name-by-id card-dim-by-id)))
+ (attach-thread-read-data thread blocks pages card-name-by-id)))
threads)))
(defn- gate-threads-derived-data
diff --git a/src/metabase/explorations/blocks.clj b/src/metabase/explorations/blocks.clj
index 386827d7fbc..7c85eaf596f 100644
--- a/src/metabase/explorations/blocks.clj
+++ b/src/metabase/explorations/blocks.clj
@@ -3,11 +3,11 @@
persisted `ExplorationBlock` + `ExplorationPage` rows and its hydrated query rows.
Each block becomes one sidebar heading; within it, each persisted page becomes a child
- bundling that page's query ids (sorted by interestingness). The block heading (with
- ambiguity disambiguation) and each page's display name are computed here — they're not
- persisted."
+ bundling that page's query ids (sorted by interestingness). The block heading and each
+ page's display name are computed here — they're not persisted."
(:require
[clojure.string :as str]
+ [metabase.explorations.models.exploration-block :as block]
[metabase.explorations.query-plan.variants :as variants]
[metabase.util.i18n :refer [tru]]))
@@ -30,40 +30,20 @@
[block]
(first (:dimensions block)))
-(defn- dimension-base-name
- [dim]
- (or (:display-name dim) (:dimension-id dim) ""))
-
-(defn- dimension-long-name
- "Disambiguated dimension label `<source> - <name>` when the dim carries a source (`:group`)
- label, else the plain base name."
- [dim]
- (let [base (dimension-base-name dim)
- source (some-> dim :group :display-name)]
- (if (str/blank? source)
- base
- (tru "{0} - {1}" source base))))
-
(defn- by-dimension
"Render a `By <dimension>` label."
[label]
(tru "By {0}" label))
(defn block-display-name
- "Sidebar heading for a block: `By <dimension>` for a dimension-anchored block, otherwise the
- metric's name. `card-name-by-id` maps a metric Card id to its name. When `ambiguous?` (the
- base dimension name is shared by another block), the dimension is qualified by its source —
- `By <source> - <dimension>` — so same-named blocks stay identifiable. Public so the LLM
- planner context can label a block the same way the read tree does."
- ([block card-name-by-id]
- (block-display-name block card-name-by-id false))
- ([block card-name-by-id ambiguous?]
- (if (dimension-anchored? block)
- (let [dim (anchor-dimension block)]
- (by-dimension (if ambiguous?
- (dimension-long-name dim)
- (dimension-base-name dim))))
- (or (get card-name-by-id (:card_id (first (:metrics block)))) ""))))
+ "Sidebar heading for a block: `By <dimension>` for a dimension-anchored block (using the
+ dim's curated [[block/dimension-label]]), otherwise the metric's name. `card-name-by-id`
+ maps a metric Card id to its name. Public so the LLM planner context can label a block
+ the same way the read tree does."
+ [block card-name-by-id]
+ (if (dimension-anchored? block)
+ (by-dimension (or (block/dimension-label (anchor-dimension block)) ""))
+ (or (get card-name-by-id (:card_id (first (:metrics block)))) "")))
(defn- page-metric-name
"The metric (Card) name for `page` — present even on an empty (comment-retained) page."
@@ -165,16 +145,7 @@
Pages are sorted by interestingness desc within their block. Pages whose block isn't in
`blocks` are dropped; queries are matched to their page via `page_id`."
[blocks pages card-name-by-id queries]
- (let [base-name-counts (->> blocks
- (filter dimension-anchored?)
- (map #(dimension-base-name (anchor-dimension %)))
- frequencies)
- ambiguous? (fn [block]
- (and (dimension-anchored? block)
- (> (get base-name-counts
- (dimension-base-name (anchor-dimension block)) 0)
- 1)))
- queries-by-page (group-by :page_id queries)
+ (let [queries-by-page (group-by :page_id queries)
pages-by-block (group-by :exploration_block_id pages)]
(into []
(map-indexed
@@ -192,7 +163,7 @@
vec)]
{:id (:id block)
:type (if (dimension-anchored? block) "dimension" "metric")
- :name (block-display-name block card-name-by-id (ambiguous? block))
+ :name (block-display-name block card-name-by-id)
:position block-pos
:explore_filters (:explore_filters (first (:metrics block)))
:pages block-pages})))
diff --git a/src/metabase/explorations/impl.clj b/src/metabase/explorations/impl.clj
index 3f38b821070..58aec70fea0 100644
--- a/src/metabase/explorations/impl.clj
+++ b/src/metabase/explorations/impl.clj
@@ -9,6 +9,7 @@
(:require
[clojure.string :as str]
[metabase.collections.models.collection :as collection]
+ [metabase.explorations.models.exploration-block :as block]
[metabase.lib-be.core :as lib-be]
[metabase.lib-metric.core :as lib-metric]
[metabase.lib.core :as lib]
@@ -65,33 +66,21 @@
:name)
(catch Exception _ nil))))
-(defn- dimension-display-name
- "Combination name shown in the UI for a dimension: '<group display name> - <dimension display name>'
- when the dimension has a group, otherwise just the dimension's display name."
- [d]
- (let [dn (or (:display-name d) (:name d) "")
- group-dn (some-> d :group :display-name)]
- (if (str/blank? group-dn)
- dn
- (str group-dn " - " dn))))
-
(defn- metric-matches-search?
"Case-insensitive match of `q-lower` against the metric's name or any of its dimensions'
- *displayed* names — the `<group> - <dimension>` combination the picker shows (see
- [[dimension-display-name]]), so searching a group name, a dimension name, or the combined
- string all match what the user sees."
+ curated [[block/dimension-label]]s — the same text the picker surfaces."
[metric q-lower]
(or (str/includes? (u/lower-case-en (or (:name metric) "")) q-lower)
(some (fn [d]
- (str/includes? (u/lower-case-en (dimension-display-name d)) q-lower))
+ (str/includes? (u/lower-case-en (or (block/dimension-label d) "")) q-lower))
(:dimensions metric))))
(defn- group-dimensions
"Collapse dimensions across the supplied metrics into a list of dimension groups. Dimensions that
share at least one source entry are unioned into the same group (matching the semantics of
- `lib-metric/same-source?`). Each group exposes the user-facing combination name, a representative
- interestingness, and the list of underlying dimensions that callers must echo back to
- `POST /api/exploration` when the user starts an exploration."
+ `lib-metric/same-source?`). Each group exposes the curated [[block/dimension-label]], a
+ representative interestingness, and the list of underlying dimensions that callers must echo
+ back to `POST /api/exploration` when the user starts an exploration."
[metrics]
(let [;; Flatten + filter once. Keep dims whose interestingness is nil (didn't score) or above
;; the threshold
@@ -105,7 +94,7 @@
(mapv (fn [dims]
(let [head (first dims)
scores (keep :dimension-interestingness dims)]
- {:name (dimension-display-name head)
+ {:name (or (block/dimension-label head) "")
:dimension_interestingness (when (seq scores) (apply max scores))
:dimensions (vec dims)})))
(sort-by (fn [g]
@@ -481,7 +470,7 @@
[m dim->group-name]
(mapv (fn [d]
(let [group-name (dim->group-name (:id d))
- own-name (dimension-display-name d)]
+ own-name (or (block/dimension-label d) "")]
(cond-> {:id (:id d) :group group-name}
(not= own-name group-name) (assoc :name own-name))))
(:dimensions m)))
diff --git a/src/metabase/explorations/models/exploration_block.clj b/src/metabase/explorations/models/exploration_block.clj
index 6d224c58984..b0a18a576c8 100644
--- a/src/metabase/explorations/models/exploration_block.clj
+++ b/src/metabase/explorations/models/exploration_block.clj
@@ -54,35 +54,9 @@
(when-let [g (t2/select-one [:model/ExplorationBlock :exploration_thread_id] :id pk)]
(mi/can-write? :model/ExplorationThread (:exploration_thread_id g)))))
-(defn enrich-with-card-group
- "Look up `:group` for `dim` (a group dimension snapshot) on a `card-dim-by-id` map (the
- metric Card's `:dimensions` snapshot indexed by id) and `assoc` it onto the dim. Returns
- `dim` unchanged when no group is recorded. The group label is metadata authored on the
- Card's dimension; it doesn't live on the snapshot, so any consumer that wants to render it
- needs this lookup."
- [dim card-dim-by-id]
- (if-let [group (get-in card-dim-by-id [(:dimension-id dim) :group])]
- (assoc dim :group group)
- dim))
-
-(defn- thread-blocks [thread-id]
- (t2/select :model/ExplorationBlock
- :exploration_thread_id thread-id
- {:order-by [[:position :asc] [:id :asc]]}))
-
-(defn selected-metric-names
- "Distinct names of the metric Cards selected across `thread-id`'s blocks, in authoring order."
- [thread-id]
- (let [card-ids (distinct (mapcat #(map :card_id (:metrics %)) (thread-blocks thread-id)))
- names (when (seq card-ids)
- (t2/select-pk->fn :name [:model/Card :id :name] :id [:in card-ids]))]
- (keep names card-ids)))
-
-(defn selected-dimension-names
- "Distinct display names (falling back to the raw `dimension-id`) of the dimensions
- selected across `thread-id`'s blocks, in authoring order."
- [thread-id]
- (->> (thread-blocks thread-id)
- (mapcat :dimensions)
- (keep (fn [d] (or (:display-name d) (:dimension-id d))))
- distinct))
+(defn dimension-label
+ "User-facing label for a dimension: the curated `:display-name` when set, else the raw
+ `:dimension-id` (block snapshots) or `:name` (metric Card dimensions). Returns nil when
+ none of those are present."
+ [dim]
+ (or (:display-name dim) (:dimension-id dim) (:name dim)))
diff --git a/src/metabase/explorations/query_plan.clj b/src/metabase/explorations/query_plan.clj
index d904bdfaab2..615d9a2fc15 100644
--- a/src/metabase/explorations/query_plan.clj
+++ b/src/metabase/explorations/query_plan.clj
@@ -14,6 +14,7 @@
instance, and teaching `pick-planner!` to dispatch to it."
(:require
[clojure.set :as set]
+ [metabase.explorations.models.exploration-block :as block]
[metabase.explorations.query-plan.context :as qp.context]
[metabase.explorations.query-plan.mechanical :as qp.mechanical]
[metabase.explorations.query-plan.planner :as planner]
@@ -57,7 +58,7 @@
(let [metric (get metric-by-key [(:block_id item) (:metric_id item)])
appl (get-in metric [:applicability (:dimension_id item)])
dim (:dim appl)
- dim-label (or (:display-name dim) (:dimension-id dim))
+ dim-label (block/dimension-label dim)
item-seg (segment-for metric (get-in item [:params :segment_id]))
plan-ctx {:segment item-seg :params (:params item)}]
(mapv (fn [recipe]
diff --git a/src/metabase/explorations/query_plan/context.clj b/src/metabase/explorations/query_plan/context.clj
index ee4be0f256a..38b291b997b 100644
--- a/src/metabase/explorations/query_plan/context.clj
+++ b/src/metabase/explorations/query_plan/context.clj
@@ -86,15 +86,10 @@
dim-by-id)))
(defn- metric-context
- "Per-metric entry for [[metric-and-dim-context]]'s `:metrics` list. Enriches
- the shared `dim-by-id` with this Card's `:group` metadata before computing
- applicability, so the planners and the variant builders see the same
- enrichment."
+ "Per-metric entry for [[metric-and-dim-context]]'s `:metrics` list."
[tm card mp dim-by-id]
(let [base-query (try (lib/query mp (:dataset_query card)) (catch Exception _ nil))
- card-dims (u/index-by :id (:dimensions card))
- enriched-thread-dims (update-vals dim-by-id #(block/enrich-with-card-group % card-dims))
- appl (applicability enriched-thread-dims tm base-query)
+ appl (applicability dim-by-id tm base-query)
default-temp (when base-query
(qp.mbql/default-temporal-breakout-col base-query))]
{:metric-id (:card_id tm)
@@ -139,10 +134,10 @@
{}
metrics)
;; Take the per-dim enriched dim from the first metric whose applicability
- ;; resolves it — that copy carries both `:group` (the dim's source label) and
- ;; `:fingerprint`. Dims that resolve on no metric in this block are dropped:
- ;; nothing can be charted from them here, so surfacing them to a planner would
- ;; just be noise.
+ ;; resolves it — that copy carries the column `:fingerprint` looked up through
+ ;; the metadata provider. Dims that resolve on no metric in this block are
+ ;; dropped: nothing can be charted from them here, so surfacing them to a
+ ;; planner would just be noise.
enriched-by-id (into {}
(keep (fn [dim-id]
(when-let [d (some #(get-in % [:applicability dim-id :dim]) metrics)]
@@ -157,8 +152,7 @@
:when dim]
{:dimension-id dim-id
:dim dim
- :display-name (or (:display-name dim) dim-id)
- :group-label (some-> dim :group :display-name)
+ :display-name (block/dimension-label dim)
:effective-type (:effective-type dim)
:semantic-type (:semantic-type dim)
;; effective-cardinality returns the bin count for auto-binned
@@ -193,14 +187,14 @@
...]}
The underlying Card is hydrated with the columns the variant builders need
- (`:id :name :description :database_id :dataset_query :card_schema :dimensions`), once per
- Card even when it appears in several blocks."
+ (`:id :name :description :database_id :dataset_query :card_schema`), once per Card even
+ when it appears in several blocks."
[blocks]
(let [card-ids (distinct (mapcat #(map :card_id (:metrics %)) blocks))
cards (when (seq card-ids)
(t2/select-pk->fn identity
[:model/Card :id :name :description :database_id
- :dataset_query :card_schema :dimensions]
+ :dataset_query :card_schema]
:id [:in card-ids]))
mp-by-db (memoize (fn [db-id] (lib-be/application-database-metadata-provider db-id)))]
{:blocks (mapv #(block-context % cards mp-by-db) blocks)}))
@@ -219,24 +213,8 @@
binning (lib/with-binning target binning)
:else target)))
-(defn- dim-base-display-name
- [dim]
- (or (:display-name dim) (:dimension-id dim)))
-
-(defn- explore-filter-dimension-label
- "Display label for an explore filter's matched dimension snapshot. Qualifies with the dim's
- source group only when the base display name is shared by another dimension in the block."
- [matched-dim block-dimensions]
- (let [base (dim-base-display-name matched-dim)
- name-counts (frequencies (map dim-base-display-name block-dimensions))
- ambiguous? (> (get name-counts base 0) 1)
- group-dn (some-> matched-dim :group :display-name)]
- (if (and ambiguous? (not (str/blank? group-dn)))
- (str group-dn " → " base)
- base)))
-
(defn- block-dims-by-field-id
- "Index enriched block dimensions by the integer Field id of their mapping `:target`, given a
+ "Index block dimensions by the integer Field id of their mapping `:target`, given a
prebuilt `{dimension_id → target}` index. Used to resolve an explore-filter `field_ref` to a
dim without per-dim lib column matching."
[block-dimensions target-by-dim-id]
@@ -248,8 +226,8 @@
[fid dim])))
(defn- dimension-for-explore-filter
- "Match `filter-spec` to one of `block-dimensions` via the metric's `:dimension_mappings`,
- comparing on Field id. `block-dimensions` should already be group-enriched."
+ "Match `filter-spec` to one of the block's dimensions via the metric's `:dimension_mappings`,
+ comparing on Field id."
[block-dims-by-fid {:keys [field_ref]}]
(when-let [fid (qp.mbql/target-field-id field_ref)]
(get block-dims-by-fid fid)))
@@ -268,9 +246,9 @@
(defn- explore-filter-dimension-name
"Resolve the dimension label for one explore filter given a prebuilt field-id → dim index."
- [mp card block-dims block-dims-by-fid filter-spec]
+ [mp card block-dims-by-fid filter-spec]
(or (some-> (dimension-for-explore-filter block-dims-by-fid filter-spec)
- (explore-filter-dimension-label block-dims))
+ block/dimension-label)
(explore-filter-column-display-name mp card filter-spec)))
(defn- expression-ref-name
@@ -292,7 +270,7 @@
[block-dimensions target-by-dim-id field-ref]
(when-let [expr-name (expression-ref-name field-ref)]
(some (fn [dim]
- (when (= expr-name (or (:display-name dim) (:dimension-id dim) "value"))
+ (when (= expr-name (or (block/dimension-label dim) "value"))
(get target-by-dim-id (:dimension-id dim))))
block-dimensions)))
@@ -300,13 +278,11 @@
"Normalize and label each request filter. A `top-n-other` bucket's click ref is a synthetic
expression that exists only on the variant query; remap it to its underlying dimension target
first, so the drill scopes the real column and the Field-id label lookup below can resolve it.
- Then stamp the BE-computed `:dimension_name`, preserving the FE-supplied `:display_value` when
- present. Enriches block dims with `:group` from the metric Card so same-named dimensions qualify
- the same way as query `:dimension_name` labels."
+ Then stamp the BE-computed `:dimension_name` (the dim's curated [[block/dimension-label]],
+ falling back to the metric query column display name), preserving the FE-supplied
+ `:display_value` when present."
[mp card block metric-selection explore-filters]
- (let [card-dims (u/index-by :id (:dimensions card))
- block-dims (mapv #(block/enrich-with-card-group % card-dims)
- (or (:dimensions block) []))
+ (let [block-dims (or (:dimensions block) [])
target-by-dim-id (qp.mbql/index-dimension-targets (:dimension_mappings metric-selection))
block-dims-by-fid (block-dims-by-field-id block-dims target-by-dim-id)]
(mapv (fn [filter-spec]
@@ -314,7 +290,7 @@
(:field_ref filter-spec))
filter-spec (cond-> filter-spec
target (assoc :field_ref target))
- dimension-name (explore-filter-dimension-name mp card block-dims
+ dimension-name (explore-filter-dimension-name mp card
block-dims-by-fid filter-spec)]
(cond-> filter-spec
dimension-name (assoc :dimension_name dimension-name))))
@@ -404,7 +380,7 @@
:card card
:target target
:dim thread-dim
- :dim-label (or (:display-name thread-dim) dimension_id)
+ :dim-label (or (block/dimension-label thread-dim) dimension_id)
:segment segment
:params params
:explore-filters explore-filters}))))
diff --git a/src/metabase/explorations/query_plan/variants.clj b/src/metabase/explorations/query_plan/variants.clj
index ff862c3a96e..83e59383207 100644
--- a/src/metabase/explorations/query_plan/variants.clj
+++ b/src/metabase/explorations/query_plan/variants.clj
@@ -9,6 +9,7 @@
[clojure.core.cache :as cache]
[clojure.core.cache.wrapped :as cache.wrapped]
[metabase.api.common :as api]
+ [metabase.explorations.models.exploration-block :as block]
[metabase.explorations.query-plan.mbql :as qp.mbql]
[metabase.lib.core :as lib]
[metabase.query-processor.core :as qp]
@@ -355,7 +356,7 @@
;; Postgres and other strict warehouses. No-op for text dims.
pairs (mapv (fn [v] [(lib/= (or field-ref ref-clause) v) (str v)]) top-values)
case-expr (lib/case pairs other-bucket-label)
- expr-name (or (:display-name dim) (:dimension-id dim) "value")
+ expr-name (or (block/dimension-label dim) "value")
with-expr (lib/expression base-query expr-name case-expr)
with-bo (lib/breakout with-expr (lib/expression-ref with-expr expr-name))]
;; Order by metric desc within the named buckets. One note: `(Other)`
diff --git a/test/metabase/explorations/api_test.clj b/test/metabase/explorations/api_test.clj
index 4299f01cbf7..d941b4ca2eb 100644
--- a/test/metabase/explorations/api_test.clj
+++ b/test/metabase/explorations/api_test.clj
@@ -408,8 +408,8 @@
(testing "long_name is self-describing (carries the dimension the heading drops)"
(is (= #{"Revenue by Price" "Signups by Price"} (long-names dimension-block)))))))))
-(deftest exploration-dimension-group-heading-disambiguation-test
- (testing "GET qualifies same-named dimension-anchored group headings by their source"
+(deftest exploration-dimension-group-heading-uses-curated-name-test
+ (testing "GET uses each dimension's curated display_name for dimension-anchored headings"
(let [users-created "00000000-0000-0000-0000-0000000a1111"
orders-created "00000000-0000-0000-0000-0000000b2222"]
(mt/with-temp
@@ -433,12 +433,12 @@
(filter #(= "dimension" (:type %)))
(map :name)
set))]
- (testing "two dimension blocks sharing a base name → headings qualified by source"
- (is (= #{"By Users - Created At" "By Orders - Created At"}
+ (testing "two dimension blocks sharing a display_name keep the curated heading (no group prefix)"
+ (is (= #{"By Created At"}
(headings {:name "ambig-headings"
:blocks [(dim-grp users-created 1)
(dim-grp orders-created 2)]}))))
- (testing "a single dimension group keeps the plain heading even with a known source"
+ (testing "a single dimension group uses the curated heading"
(is (= #{"By Created At"}
(headings {:name "single-heading"
:blocks [(dim-grp users-created 1)]})))))))))
@@ -1033,8 +1033,8 @@
(is (= (str "Revenue by " (duid "no-name")) (get by-dim (duid "no-name")))
"falls back to dimension_id when display_name is absent")))))
-(deftest exploration-create-disambiguates-same-named-dimensions-test
- (testing "POST / qualifies same-named dimensions with their group's display name"
+(deftest exploration-create-uses-curated-dimension-names-test
+ (testing "POST / stamps each query's :dimension_name from the dim's curated display_name"
(let [users-created "00000000-0000-0000-0000-00000000aaaa"
orders-created "00000000-0000-0000-0000-00000000bbbb"
users-country "00000000-0000-0000-0000-00000000cccc"]
@@ -1049,7 +1049,7 @@
:group {:id "g-orders" :type "connection" :display-name "Orders"}}
{:id users-country :name "COUNTRY" :display-name "Country"
:group {:id "g-users" :type "main" :display-name "Users"}}])]
- (testing "two dims sharing a display_name → both dimension_names get the group prefix"
+ (testing "two dims sharing a display_name keep the curated label (no group prefix)"
(let [body {:name "ambig"
:metrics [{:card_id (:id revenue)
:dimension_mappings
@@ -1057,14 +1057,12 @@
{:dimension_id orders-created :table_id 1 :target ["field" {} 2]}]}]
:dimensions [{:dimension_id users-created :display_name "Created At"}
{:dimension_id orders-created :display_name "Created At"}]}
- ;; :dimension_name is the API-computed dimension label (with disambiguation).
- ;; The full query :name stored in DB is plain "Revenue by Created At".
by-dim (->> (create-exploration! u body)
:threads first :queries
(into {} (map (juxt :dimension_id :dimension_name))))]
- (is (= "Users → Created At" (get by-dim users-created)))
- (is (= "Orders → Created At" (get by-dim orders-created)))))
- (testing "distinct display_names → no qualification"
+ (is (= "Created At" (get by-dim users-created)))
+ (is (= "Created At" (get by-dim orders-created)))))
+ (testing "distinct display_names are used as-is"
(let [body {:name "no-ambig"
:metrics [{:card_id (:id revenue)
:dimension_mappings
@@ -1076,34 +1074,7 @@
:threads first :queries
(into {} (map (juxt :dimension_id :dimension_name))))]
(is (= "Created At" (get by-dim users-created)))
- (is (= "Country" (get by-dim users-country)))))
- (testing "single dim → no qualification even when it has a group"
- (let [body {:name "single"
- :metrics [{:card_id (:id revenue)
- :dimension_mappings
- [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}]}]
- :dimensions [{:dimension_id users-created :display_name "Created At"}]}
- q (-> (create-exploration! u body)
- :threads first :queries first)]
- (is (= "Created At" (:dimension_name q)))))))))
-
-(deftest exploration-create-name-falls-back-without-group-test
- (testing "POST / leaves ambiguous dims unqualified when neither has a known :group (no NPE / no malformed name)"
- (mt/with-temp
- [:model/User u {:email "[email protected]"}
- ;; `:dimensions` left absent (nil) — represents pre-existing Cards without computed groups.
- :model/Card revenue (assoc (valid-metric-card (:id u)) :name "Revenue")]
- (let [body {:name "no-group"
- :metrics [{:card_id (:id revenue)
- :dimension_mappings
- [{:dimension_id (duid "a") :table_id 1 :target ["field" {} 1]}
- {:dimension_id (duid "b") :table_id 1 :target ["field" {} 2]}]}]
- :dimensions [{:dimension_id (duid "a") :display_name "Created At"}
- {:dimension_id (duid "b") :display_name "Created At"}]}
- queries (-> (mt/user-http-request u :post 200 "exploration" body)
- :threads first :queries)]
- (is (every? #(= "Revenue by Created At" (:name %)) queries)
- "falls back to plain display_name when no :group is available")))))
+ (is (= "Country" (get by-dim users-country)))))))))
(deftest exploration-get-attaches-dimension-name-test
(testing "hydrate-exploration assoc's :dimension_name onto each query using the dim's display_name"
@@ -1120,15 +1091,14 @@
:threads first :queries
(into {} (map (juxt :dimension_id :dimension_name))))]
(is (= "Country" (get by-dim (duid "country")))
- "ships the dim's display_name as :dimension_name when unambiguous")
+ "ships the dim's curated display_name as :dimension_name")
(is (= (duid "no-name") (get by-dim (duid "no-name")))
"falls back to dimension_id when display_name is missing")))))
-(deftest exploration-get-dimension-name-disambiguates-test
- (testing "hydrate-exploration prefixes :dimension_name with the dim's group when two dims share a display_name"
+(deftest exploration-get-dimension-name-uses-curated-name-test
+ (testing "hydrate-exploration uses each dim's curated display_name even when two dims share it"
(let [users-created "00000000-0000-0000-0000-00000000dddd"
- orders-created "00000000-0000-0000-0000-00000000eeee"
- users-country "00000000-0000-0000-0000-00000000ffff"]
+ orders-created "00000000-0000-0000-0000-00000000eeee"]
(mt/with-temp
[:model/User u {:email "[email protected]"}
:model/Card metric (assoc (valid-metric-card (:id u))
@@ -1136,35 +1106,19 @@
[{:id users-created :name "CREATED_AT" :display-name "Created At"
:group {:id "g-users" :type "main" :display-name "Users"}}
{:id orders-created :name "CREATED_AT" :display-name "Created At"
- :group {:id "g-orders" :type "connection" :display-name "Orders"}}
- {:id users-country :name "COUNTRY" :display-name "Country"
- :group {:id "g-users" :type "main" :display-name "Users"}}])]
- (testing "shared display_name → both :dimension_names carry the group prefix"
- (let [body {:name "ambig"
- :metrics [{:card_id (:id metric)
- :dimension_mappings
- [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}
- {:dimension_id orders-created :table_id 1 :target ["field" {} 2]}]}]
- :dimensions [{:dimension_id users-created :display_name "Created At"}
- {:dimension_id orders-created :display_name "Created At"}]}
- by-dim (->> (create-exploration! u body)
- :threads first :queries
- (into {} (map (juxt :dimension_id :dimension_name))))]
- (is (= "Users → Created At" (get by-dim users-created)))
- (is (= "Orders → Created At" (get by-dim orders-created)))))
- (testing "distinct display_names → no qualification"
- (let [body {:name "no-ambig"
- :metrics [{:card_id (:id metric)
- :dimension_mappings
- [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}
- {:dimension_id users-country :table_id 1 :target ["field" {} 3]}]}]
- :dimensions [{:dimension_id users-created :display_name "Created At"}
- {:dimension_id users-country :display_name "Country"}]}
- by-dim (->> (create-exploration! u body)
- :threads first :queries
- (into {} (map (juxt :dimension_id :dimension_name))))]
- (is (= "Created At" (get by-dim users-created)))
- (is (= "Country" (get by-dim users-country))))))))) ; binding+let+with-temp+testing+deftest
+ :group {:id "g-orders" :type "connection" :display-name "Orders"}}])]
+ (let [body {:name "ambig"
+ :metrics [{:card_id (:id metric)
+ :dimension_mappings
+ [{:dimension_id users-created :table_id 1 :target ["field" {} 1]}
+ {:dimension_id orders-created :table_id 1 :target ["field" {} 2]}]}]
+ :dimensions [{:dimension_id users-created :display_name "Created At"}
+ {:dimension_id orders-created :display_name "Created At"}]}
+ by-dim (->> (create-exploration! u body)
+ :threads first :queries
+ (into {} (map (juxt :dimension_id :dimension_name))))]
+ (is (= "Created At" (get by-dim users-created)))
+ (is (= "Created At" (get by-dim orders-created))))))))
(deftest exploration-get-includes-interestingness-on-queries-test
(testing "GET /:id hydrates both interestingness scores on each nested query"
@@ -2358,8 +2312,8 @@
(is (= "Number of venues → Category: gadget, Price: 2" (:name new-thread))
"top-level follow-up names all filters as Metric → Column: Value")))))))
-(deftest explore-further-disambiguates-same-named-filter-dimensions-test
- (testing "POST /:id/explore-further qualifies ambiguous explore-filter dimension_names with the dim's group"
+(deftest explore-further-uses-curated-filter-dimension-names-test
+ (testing "POST /:id/explore-further labels explore-filter dimension_names with the curated display_name"
(let [users-created "00000000-0000-0000-0000-00000000aaaa"
orders-created "00000000-0000-0000-0000-00000000bbbb"
users-field (mt/id :venues :latitude)
@@ -2384,18 +2338,26 @@
{:dimension_id orders-created :display_name "Created At"}]}
created (create-exploration! u body)
expl-id (:id created)
- page-id (->> created :threads first :blocks first :pages
- (some #(when (= "Users → Created At" (:name %)) (:id %))))
- _ (is (some? page-id) "find the users-created page by its disambiguated name")
+ ;; Pages for the two same-named dims share the short name "Created At"; pick the
+ ;; users-created page via its queries' :dimension_id.
+ page-id (let [queries-by-id (into {} (map (juxt :id identity)
+ (-> created :threads first :queries)))]
+ (->> created :threads first :blocks first :pages
+ (some (fn [page]
+ (when (some #(= users-created
+ (:dimension_id (get queries-by-id %)))
+ (:query_ids page))
+ (:id page))))))
+ _ (is (some? page-id) "find the users-created page")
filter-spec {:operator "=" :field_ref ["field" {} users-field] :value 40.7 :display_value "40.7"}
hydrated (explore-further-and-hydrate! u expl-id page-id [filter-spec])
new-thread (->> hydrated :threads (sort-by :position) last)
persisted (t2/select-one :model/ExplorationBlock :exploration_thread_id (:id new-thread))]
- (is (= "Revenue → Users → Created At: 40.7" (:name new-thread))
- "thread name uses the group-qualified filter dimension label")
- (is (= "Users → Created At"
+ (is (= "Revenue → Created At: 40.7" (:name new-thread))
+ "thread name uses the curated filter dimension label")
+ (is (= "Created At"
(:dimension_name (first (:explore_filters (first (:metrics persisted))))))
- "persisted explore_filters carry the group-qualified dimension_name"))))))
+ "persisted explore_filters carry the curated dimension_name"))))))
;;; | Create-time reference permission checks |
;;; +----------------------------------------------------------------------------------------------------------------+
diff --git a/test/metabase/explorations/impl_test.clj b/test/metabase/explorations/impl_test.clj
index 36641f39ba0..9a571fa7692 100644
--- a/test/metabase/explorations/impl_test.clj
+++ b/test/metabase/explorations/impl_test.clj
@@ -510,18 +510,16 @@
;;; --------------------------------------- metric search matching ---------------------------------------
(deftest metric-search-matches-displayed-names-test
- (testing "search matches the '<group> - <dimension>' combination the picker displays"
+ (testing "search matches the metric name and each dimension's curated display_name"
(let [matches? #(#'explorations.impl/metric-matches-search? %1 %2)
metric {:name "Revenue"
:dimensions [{:display-name "Created At"
:group {:display-name "Orders"}}]}]
(testing "metric name still matches"
(is (matches? metric "revenue")))
- (testing "the raw dimension name still matches"
+ (testing "the curated dimension name matches"
(is (matches? metric "created at")))
- (testing "the group name matches"
- (is (matches? metric "orders")))
- (testing "the displayed combination matches"
- (is (matches? metric "orders - created")))
+ (testing "the source group name is not part of the search text"
+ (is (not (matches? metric "orders"))))
(testing "non-matches stay non-matches"
(is (not (matches? metric "customers")))))))
diff --git a/test/metabase/explorations/query_plan/context_test.clj b/test/metabase/explorations/query_plan/context_test.clj
index 11e82fc75c3..d740e7f03a1 100644
--- a/test/metabase/explorations/query_plan/context_test.clj
+++ b/test/metabase/explorations/query_plan/context_test.clj
@@ -366,12 +366,8 @@
(is (= :default (:strategy (lib/binning lhs)))
"click ref's default binning is applied to the explore filter target")))))
-(deftest enrich-explore-filters-disambiguates-same-named-dimensions-test
- (testing "enrich-explore-filters qualifies ambiguous explore-filter dimension_names with the dim's group"
- ;; Block snapshots don't carry :group — it lives on the metric Card's :dimensions. When two
- ;; block dims share a display_name, explore-filter labels should mirror query :dimension_name
- ;; disambiguation (e.g. \"Users → Created At\"), not fall back to the bare name or the raw
- ;; column display name.
+(deftest enrich-explore-filters-uses-curated-dimension-name-test
+ (testing "enrich-explore-filters labels explore-filter dimension_names with the curated display_name"
(let [users-created "00000000-0000-0000-0000-00000000aaaa"
orders-created "00000000-0000-0000-0000-00000000bbbb"
users-field (mt/id :venues :latitude)
@@ -395,8 +391,8 @@
:target ["field" {} orders-field]}]}
filter-spec {:operator "=" :field_ref ["field" {} users-field] :value 40.7}
[enriched] (qp.context/enrich-explore-filters mp metric block metric-selection [filter-spec])]
- (is (= "Users → Created At" (:dimension_name enriched))
- "the clicked filter is labeled with the dim's group when the display_name is shared"))))))
+ (is (= "Created At" (:dimension_name enriched))
+ "the clicked filter is labeled with the curated display_name"))))))
;;; ---------------------------------------------------------------------------
;;; build-row-context — "Explore further" filter edge cases