Skip to content

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

Remove dead dimension options code (#62630)

Cam Saulf4da670b8579
diff --git a/frontend/src/metabase-types/api/field.ts b/frontend/src/metabase-types/api/field.ts
index eb70ead9b11..b1738a34fb0 100644
--- a/frontend/src/metabase-types/api/field.ts
+++ b/frontend/src/metabase-types/api/field.ts
@@ -66,12 +66,6 @@ export type FieldDimension = {
human_readable_field?: Field;
};
-export type FieldDimensionOption = {
- name: string;
- mbql: unknown[] | null;
- type: string;
-};
-
export interface Field {
id: FieldId | FieldReference;
table_id: TableId;
@@ -100,8 +94,6 @@ export interface Field {
settings?: FieldFormattingSettings;
dimensions?: FieldDimension[];
- default_dimension_option?: FieldDimensionOption;
- dimension_options?: FieldDimensionOption[];
name_field?: Field;
max_value?: number;
diff --git a/frontend/src/metabase-types/api/mocks/presets/sample_database.ts b/frontend/src/metabase-types/api/mocks/presets/sample_database.ts
index 9e9aab510b9..48e3961c066 100644
--- a/frontend/src/metabase-types/api/mocks/presets/sample_database.ts
+++ b/frontend/src/metabase-types/api/mocks/presets/sample_database.ts
@@ -2,7 +2,6 @@ import type {
Database,
DatasetColumn,
Field,
- FieldDimensionOption,
GetFieldValuesResponse,
Table,
} from "metabase-types/api";
@@ -250,24 +249,6 @@ export const SAMPLE_DB_FIELD_VALUES = [
PEOPLE_STATE_VALUES,
];
-const DEFAULT_NUMERIC_BINNING_OPTION: FieldDimensionOption = {
- name: "Auto bin",
- mbql: ["field", null, { binning: { strategy: "default" } }],
- type: "type/Number",
-};
-
-const DEFAULT_COORDINATE_BINNING_OPTION: FieldDimensionOption = {
- name: "Auto bin",
- mbql: ["field", null, { binning: { strategy: "default" } }],
- type: "type/Coordinate",
-};
-
-const DEFAULT_TEMPORAL_BUCKETING_OPTION: FieldDimensionOption = {
- name: "Day",
- mbql: ["field", null, { "temporal-unit": "day" }],
- type: "type/DateTime",
-};
-
export const createSampleDatabase = (opts?: Partial<Database>): Database =>
createMockDatabase({
id: SAMPLE_DB_ID,
@@ -300,7 +281,6 @@ export const createOrdersTable = (opts?: Partial<Table>): Table =>
createOrdersCreatedAtField(),
createOrdersQuantityField(),
],
- dimension_options: createTableDimensionOptions(),
...opts,
});
@@ -326,7 +306,6 @@ export const createPeopleTable = (opts?: Partial<Table>): Table =>
createPeopleLatitudeField(),
createPeopleCreatedAtField(),
],
- dimension_options: createTableDimensionOptions(),
...opts,
});
@@ -348,7 +327,6 @@ export const createProductsTable = (opts?: Partial<Table>): Table =>
createProductsRatingField(),
createProductsCreatedAtField(),
],
- dimension_options: createTableDimensionOptions(),
...opts,
});
@@ -367,7 +345,6 @@ export const createReviewsTable = (opts?: Partial<Table>): Table =>
createReviewsBodyField(),
createReviewsCreatedAtField(),
],
- dimension_options: createTableDimensionOptions(),
...opts,
});
@@ -430,8 +407,6 @@ export const createOrdersSubtotalField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: null,
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 340,
@@ -459,8 +434,6 @@ export const createOrdersTaxField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: null,
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 797,
@@ -488,8 +461,6 @@ export const createOrdersTotalField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: null,
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 4426,
@@ -517,8 +488,6 @@ export const createOrdersDiscountField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: "type/Discount",
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 701,
@@ -548,8 +517,6 @@ export const createOrdersCreatedAtField = (opts?: Partial<Field>): Field =>
effective_type: "type/DateTime",
semantic_type: "type/CreationTimestamp",
description: "The timestamp the order was created",
- default_dimension_option: DEFAULT_TEMPORAL_BUCKETING_OPTION,
- dimension_options: createTemporalFieldBucketingOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 9998,
@@ -573,8 +540,6 @@ export const createOrdersQuantityField = (opts?: Partial<Field>): Field =>
base_type: "type/Integer",
effective_type: "type/Integer",
semantic_type: "type/Quantity",
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
has_field_values: "list",
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
@@ -738,8 +703,6 @@ export const createPeopleLongitudeField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: "type/Longitude",
- default_dimension_option: DEFAULT_COORDINATE_BINNING_OPTION,
- dimension_options: createCoordinateFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 2491,
@@ -814,8 +777,6 @@ export const createPeopleBirthDateField = (opts?: Partial<Field>): Field =>
base_type: "type/Date",
effective_type: "type/Date",
semantic_type: null,
- default_dimension_option: DEFAULT_TEMPORAL_BUCKETING_OPTION,
- dimension_options: createTemporalFieldBucketingOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 2308,
@@ -862,8 +823,6 @@ export const createPeopleLatitudeField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: "type/Latitude",
- default_dimension_option: DEFAULT_COORDINATE_BINNING_OPTION,
- dimension_options: createCoordinateFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 2491,
@@ -891,8 +850,6 @@ export const createPeopleCreatedAtField = (opts?: Partial<Field>): Field =>
base_type: "type/DateTime",
effective_type: "type/DateTime",
semantic_type: "type/CreationTimestamp",
- default_dimension_option: DEFAULT_TEMPORAL_BUCKETING_OPTION,
- dimension_options: createTemporalFieldBucketingOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 2500,
@@ -1023,8 +980,6 @@ export const createProductsPriceField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: null,
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 170,
@@ -1052,8 +1007,6 @@ export const createProductsRatingField = (opts?: Partial<Field>): Field =>
base_type: "type/Float",
effective_type: "type/Float",
semantic_type: "type/Score",
- default_dimension_option: DEFAULT_NUMERIC_BINNING_OPTION,
- dimension_options: createNumericFieldBinningOptions(),
has_field_values: "list",
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
@@ -1082,8 +1035,6 @@ export const createProductsCreatedAtField = (opts?: Partial<Field>): Field =>
base_type: "type/DateTime",
effective_type: "type/DateTime",
semantic_type: "type/CreationTimestamp",
- default_dimension_option: DEFAULT_TEMPORAL_BUCKETING_OPTION,
- dimension_options: createTemporalFieldBucketingOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 200,
@@ -1212,8 +1163,6 @@ export const createReviewsCreatedAtField = (opts?: Partial<Field>): Field =>
base_type: "type/DateTime",
effective_type: "type/DateTime",
semantic_type: "type/CreationTimestamp",
- default_dimension_option: DEFAULT_TEMPORAL_BUCKETING_OPTION,
- dimension_options: createTemporalFieldBucketingOptions(),
fingerprint: createMockFingerprint({
global: createMockGlobalFieldFingerprint({
"distinct-count": 1112,
@@ -1228,267 +1177,6 @@ export const createReviewsCreatedAtField = (opts?: Partial<Field>): Field =>
...opts,
});
-function createTemporalBucketingOptions(): Record<
- string,
- FieldDimensionOption
-> {
- return {
- "0": {
- name: "Day",
- mbql: ["field", null, { "temporal-unit": "day" }],
- type: "type/Date",
- },
- "1": {
- name: "Week",
- mbql: ["field", null, { "temporal-unit": "week" }],
- type: "type/Date",
- },
- "2": {
- name: "Month",
- mbql: ["field", null, { "temporal-unit": "month" }],
- type: "type/Date",
- },
- "3": {
- name: "Quarter",
- mbql: ["field", null, { "temporal-unit": "quarter" }],
- type: "type/Date",
- },
- "4": {
- name: "Year",
- mbql: ["field", null, { "temporal-unit": "year" }],
- type: "type/Date",
- },
- "5": {
- name: "Day of week",
- mbql: ["field", null, { "temporal-unit": "day-of-week" }],
- type: "type/Date",
- },
- "6": {
- name: "Day of month",
- mbql: ["field", null, { "temporal-unit": "day-of-month" }],
- type: "type/Date",
- },
- "7": {
- name: "Day of year",
- mbql: ["field", null, { "temporal-unit": "day-of-year" }],
- type: "type/Date",
- },
- "8": {
- name: "Week of year",
- mbql: ["field", null, { "temporal-unit": "week-of-year" }],
- type: "type/Date",
- },
- "9": {
- name: "Month of year",
- mbql: ["field", null, { "temporal-unit": "month-of-year" }],
- type: "type/Date",
- },
- "10": {
- name: "Quarter of year",
- mbql: ["field", null, { "temporal-unit": "quarter-of-year" }],
- type: "type/Date",
- },
- "11": {
- name: "Minute",
- mbql: ["field", null, { "temporal-unit": "minute" }],
- type: "type/DateTime",
- },
- "12": {
- name: "Hour",
- mbql: ["field", null, { "temporal-unit": "hour" }],
- type: "type/DateTime",
- },
- "13": {
- name: "Day",
- mbql: ["field", null, { "temporal-unit": "day" }],
- type: "type/DateTime",
- },
- "14": {
- name: "Week",
- mbql: ["field", null, { "temporal-unit": "week" }],
- type: "type/DateTime",
- },
- "15": {
- name: "Month",
- mbql: ["field", null, { "temporal-unit": "month" }],
- type: "type/DateTime",
- },
- "16": {
- name: "Quarter",
- mbql: ["field", null, { "temporal-unit": "quarter" }],
- type: "type/DateTime",
- },
- "17": {
- name: "Year",
- mbql: ["field", null, { "temporal-unit": "year" }],
- type: "type/DateTime",
- },
- "18": {
- name: "Minute of hour",
- mbql: ["field", null, { "temporal-unit": "minute-of-hour" }],
- type: "type/DateTime",
- },
- "19": {
- name: "Hour of day",
- mbql: ["field", null, { "temporal-unit": "hour-of-day" }],
- type: "type/DateTime",
- },
- "20": {
- name: "Day of week",
- mbql: ["field", null, { "temporal-unit": "day-of-week" }],
- type: "type/DateTime",
- },
- "21": {
- name: "Day of month",
- mbql: ["field", null, { "temporal-unit": "day-of-month" }],
- type: "type/DateTime",
- },
- "22": {
- name: "Day of year",
- mbql: ["field", null, { "temporal-unit": "day-of-year" }],
- type: "type/DateTime",
- },
- "23": {
- name: "Week of year",
- mbql: ["field", null, { "temporal-unit": "week-of-year" }],
- type: "type/DateTime",
- },
- "24": {
- name: "Month of year",
- mbql: ["field", null, { "temporal-unit": "month-of-year" }],
- type: "type/DateTime",
- },
- "25": {
- name: "Quarter of year",
- mbql: ["field", null, { "temporal-unit": "quarter-of-year" }],
- type: "type/DateTime",
- },
- "26": {
- name: "Minute",
- mbql: ["field", null, { "temporal-unit": "minute" }],
- type: "type/Time",
- },
- "27": {
- name: "Hour",
- mbql: ["field", null, { "temporal-unit": "hour" }],
- type: "type/Time",
- },
- "28": {
- name: "Minute of hour",
- mbql: ["field", null, { "temporal-unit": "minute-of-hour" }],
- type: "type/Time",
- },
- };
-}
-``;
-function createNumericBinningOptions(): Record<string, FieldDimensionOption> {
- return {
- "29": {
- name: "Auto bin",
- mbql: ["field", null, { binning: { strategy: "default" } }],
- type: "type/Number",
- },
- "30": {
- name: "10 bins",
- mbql: [
- "field",
- null,
- { binning: { strategy: "num-bins", "num-bins": 10 } },
- ],
- type: "type/Number",
- },
- "31": {
- name: "50 bins",
- mbql: [
- "field",
- null,
- { binning: { strategy: "num-bins", "num-bins": 50 } },
- ],
- type: "type/Number",
- },
- "32": {
- name: "100 bins",
- mbql: [
- "field",
- null,
- { binning: { strategy: "num-bins", "num-bins": 100 } },
- ],
- type: "type/Number",
- },
- "33": { name: "Don't bin", mbql: null, type: "type/Number" },
- };
-}
-
-function createCoordinateBinningOptions(): Record<
- string,
- FieldDimensionOption
-> {
- return {
- "34": {
- name: "Auto bin",
- mbql: ["field", null, { binning: { strategy: "default" } }],
- type: "type/Coordinate",
- },
- "35": {
- name: "Bin every 0.1 degrees",
- mbql: [
- "field",
- null,
- { binning: { strategy: "bin-width", "bin-width": 0.1 } },
- ],
- type: "type/Coordinate",
- },
- "36": {
- name: "Bin every 1 degree",
- mbql: [
- "field",
- null,
- { binning: { strategy: "bin-width", "bin-width": 1 } },
- ],
- type: "type/Coordinate",
- },
- "37": {
- name: "Bin every 10 degrees",
- mbql: [
- "field",
- null,
- { binning: { strategy: "bin-width", "bin-width": 10 } },
- ],
- type: "type/Coordinate",
- },
- "38": {
- name: "Bin every 20 degrees",
- mbql: [
- "field",
- null,
- { binning: { strategy: "bin-width", "bin-width": 20 } },
- ],
- type: "type/Coordinate",
- },
- "39": { name: "Don't bin", mbql: null, type: "type/Coordinate" },
- };
-}
-
-function createTableDimensionOptions() {
- return {
- ...createTemporalBucketingOptions(),
- ...createNumericBinningOptions(),
- ...createCoordinateBinningOptions(),
- };
-}
-
-function createTemporalFieldBucketingOptions() {
- return Object.values(createTemporalBucketingOptions());
-}
-
-function createNumericFieldBinningOptions() {
- return Object.values(createNumericBinningOptions());
-}
-
-function createCoordinateFieldBinningOptions() {
- return Object.values(createCoordinateBinningOptions());
-}
-
export const createOrdersIdDatasetColumn = (
opts?: Partial<DatasetColumn>,
): DatasetColumn =>
diff --git a/frontend/src/metabase-types/api/table.ts b/frontend/src/metabase-types/api/table.ts
index b80b9216ff4..6640364852c 100644
--- a/frontend/src/metabase-types/api/table.ts
+++ b/frontend/src/metabase-types/api/table.ts
@@ -1,6 +1,6 @@
import type { Card, CardType } from "./card";
import type { Database, DatabaseId, InitialSyncStatus } from "./database";
-import type { Field, FieldDimensionOption, FieldId } from "./field";
+import type { Field, FieldId } from "./field";
import type { Segment } from "./segment";
export type ConcreteTableId = number;
@@ -36,7 +36,6 @@ export type Table = {
fields?: Field[];
segments?: Segment[];
metrics?: Card[];
- dimension_options?: Record<string, FieldDimensionOption>;
field_order: TableFieldOrder;
active: boolean;
diff --git a/src/metabase/lib/field.cljc b/src/metabase/lib/field.cljc
index ac79f8b85e5..c19c413918b 100644
--- a/src/metabase/lib/field.cljc
+++ b/src/metabase/lib/field.cljc
@@ -361,8 +361,7 @@
(isa? semantic-type :type/Coordinate) (lib.binning/coordinate-binning-strategies)
(and (isa? effective-type :type/Number)
(not (isa? semantic-type :Relation/*))) (lib.binning/numeric-binning-strategies))]
- ;; TODO: Include the time and date binning strategies too;
- ;; see [[metabase.warehouse-schema.api.table/assoc-field-dimension-options]].
+ ;; TODO: Include the time and date binning strategies too
(for [strat strategies]
(cond-> strat
(or (:lib/original-binning field-metadata) existing) (dissoc :default)
diff --git a/src/metabase/lib/js/metadata.cljs b/src/metabase/lib/js/metadata.cljs
index 5d44f24b054..62488ee2633 100644
--- a/src/metabase/lib/js/metadata.cljs
+++ b/src/metabase/lib/js/metadata.cljs
@@ -184,7 +184,7 @@
(defmethod excluded-keys :table
[_object-type]
- #{:database :fields :segments :metrics :dimension-options})
+ #{:database :fields :segments :metrics})
(defmethod parse-field-fn :table
[_object-type]
@@ -213,8 +213,6 @@
[_object-type]
#{:_comesFromEndpoint
:database
- :default-dimension-option
- :dimension-options
:metrics
:table})
@@ -355,7 +353,6 @@
[_object-type]
#{:database
:db
- :dimension-options
:fks
:metadata
:metrics
diff --git a/src/metabase/warehouse_schema/table.clj b/src/metabase/warehouse_schema/table.clj
index 412427008de..7d61a985a17 100644
--- a/src/metabase/warehouse_schema/table.clj
+++ b/src/metabase/warehouse_schema/table.clj
@@ -1,14 +1,10 @@
(ns metabase.warehouse-schema.table
(:require
- [flatland.ordered.map :as ordered-map]
[medley.core :as m]
[metabase.api.common :as api]
- [metabase.driver.util :as driver.u]
[metabase.models.interface :as mi]
[metabase.premium-features.core :refer [defenterprise]]
- [metabase.types.core :as types]
[metabase.util :as u]
- [metabase.util.i18n :refer [deferred-tru deferred-trun]]
[metabase.warehouse-schema.models.field-values :as field-values]
[toucan2.core :as t2]))
@@ -21,202 +17,6 @@
(update :db dissoc :router_database_id)
(update :schema str)))
-(def ^:private auto-bin-str (deferred-tru "Auto bin"))
-(def ^:private dont-bin-str (deferred-tru "Don''t bin"))
-
-;;; Apparently `msgcat` is not cool with us using a string as both a singular message ID and a plural message ID, and
-;;; since we're using stuff like `Minute` as a plural string elsewhere (see [[metabase.lib.temporal-bucket]]) we're
-;;; forced to use `*-trun` here as well
-(def ^:private unit->deferred-i18n-description
- {:minute (deferred-trun "Minute" "Minutes" 1)
- :hour (deferred-trun "Hour" "Hours" 1)
- :day (deferred-trun "Day" "Days" 1)
- :week (deferred-trun "Week" "Weeks" 1)
- :month (deferred-trun "Month" "Months" 1)
- :quarter (deferred-trun "Quarter" "Quarters" 1)
- :year (deferred-trun "Year" "Years" 1)
- :minute-of-hour (deferred-trun "Minute of hour" "Minutes of hour" 1)
- :hour-of-day (deferred-trun "Hour of day" "Hours of day" 1)
- :day-of-week (deferred-trun "Day of week" "Days of week" 1)
- :day-of-month (deferred-trun "Day of month" "Days of month" 1)
- :day-of-year (deferred-trun "Day of year" "Days of year" 1)
- :week-of-year (deferred-trun "Week of year" "Weeks of year" 1)
- :month-of-year (deferred-trun "Month of year" "Months of year" 1)
- :quarter-of-year (deferred-trun "Quarter of year" "Quarters of year" 1)})
-
-;; note the order of these options corresponds to the order they will be shown to the user in the UI
-(def ^:private time-options
- (mapv (fn [unit]
- [(unit->deferred-i18n-description unit) (name unit)])
- [:minute :hour :minute-of-hour]))
-
-(def ^:private datetime-options
- (mapv (fn [unit]
- [(unit->deferred-i18n-description unit) (name unit)])
- [:minute
- :hour
- :day
- :week
- :month
- :quarter
- :year
- :minute-of-hour
- :hour-of-day
- :day-of-week
- :day-of-month
- :day-of-year
- :week-of-year
- :month-of-year
- :quarter-of-year]))
-
-(def ^:private date-options
- (mapv (fn [unit]
- [(unit->deferred-i18n-description unit) (name unit)])
- [:day
- :week
- :month
- :quarter
- :year
- :day-of-week
- :day-of-month
- :day-of-year
- :week-of-year
- :month-of-year
- :quarter-of-year]))
-
-(def ^:private dimension-options
- (let [default-entry [auto-bin-str ["default"]]]
- (into (ordered-map/ordered-map)
- (comp cat
- (map-indexed vector))
- [(map (fn [[name param]]
- {:name name
- :mbql [:field nil {:temporal-unit param}]
- :type :type/Date})
- date-options)
- (map (fn [[name param]]
- {:name name
- :mbql [:field nil {:temporal-unit param}]
- :type :type/DateTime})
- datetime-options)
- (map (fn [[name param]]
- {:name name
- :mbql [:field nil {:temporal-unit param}]
- :type :type/Time})
- time-options)
- (map (fn [[name [strategy param]]]
- {:name name
- :mbql [:field nil {:binning (merge {:strategy strategy}
- (when param
- {strategy param}))}]
- :type :type/Number})
- [default-entry
- [(deferred-tru "10 bins") ["num-bins" 10]]
- [(deferred-tru "50 bins") ["num-bins" 50]]
- [(deferred-tru "100 bins") ["num-bins" 100]]])
- [{:name dont-bin-str
- :mbql nil
- :type :type/Number}]
- (map (fn [[name [strategy param]]]
- {:name name
- :mbql [:field nil {:binning (merge {:strategy strategy}
- (when param
- {strategy param}))}]
- :type :type/Coordinate})
- [default-entry
- [(deferred-tru "Bin every 0.1 degrees") ["bin-width" 0.1]]
- [(deferred-tru "Bin every 1 degree") ["bin-width" 1.0]]
- [(deferred-tru "Bin every 10 degrees") ["bin-width" 10.0]]
- [(deferred-tru "Bin every 20 degrees") ["bin-width" 20.0]]])
- [{:name dont-bin-str
- :mbql nil
- :type :type/Coordinate}]])))
-
-(def ^:private dimension-options-for-response
- (m/map-keys str dimension-options))
-
-(defn- create-dim-index-seq [dim-type]
- (->> dimension-options
- (m/filter-vals (fn [v] (= (:type v) dim-type)))
- keys
- sort
- (map str)))
-
-(def ^:private datetime-dimension-indexes
- (create-dim-index-seq :type/DateTime))
-
-(def ^:private time-dimension-indexes
- (create-dim-index-seq :type/Time))
-
-(def ^:private date-dimension-indexes
- (create-dim-index-seq :type/Date))
-
-(def ^:private numeric-dimension-indexes
- (create-dim-index-seq :type/Number))
-
-(def ^:private coordinate-dimension-indexes
- (create-dim-index-seq :type/Coordinate))
-
-(defn- dimension-index-for-type [dim-type pred]
- (let [dim' (keyword dim-type)]
- (first (m/find-first (fn [[_k v]]
- (and (= dim' (:type v))
- (pred v))) dimension-options-for-response))))
-
-(def ^:private datetime-default-index
- (dimension-index-for-type :type/DateTime #(= (str (unit->deferred-i18n-description :day)) (str (:name %)))))
-
-(def ^:private date-default-index
- (dimension-index-for-type :type/Date #(= (str (unit->deferred-i18n-description :day)) (str (:name %)))))
-
-(def ^:private time-default-index
- (dimension-index-for-type :type/Time #(= (str (unit->deferred-i18n-description :hour)) (str (:name %)))))
-
-(def ^:private numeric-default-index
- (dimension-index-for-type :type/Number #(.contains ^String (str (:name %)) (str auto-bin-str))))
-
-(def ^:private coordinate-default-index
- (dimension-index-for-type :type/Coordinate #(.contains ^String (str (:name %)) (str auto-bin-str))))
-
-(defn- supports-numeric-binning? [db]
- (and db (driver.u/supports? (:engine db) :binning db)))
-
-;; TODO: Remove all this when the FE is fully ported to [[metabase.lib.binning/available-binning-strategies]].
-(defn- assoc-field-dimension-options [{:keys [base_type semantic_type fingerprint] :as field} db]
- (let [{min_value :min, max_value :max} (get-in fingerprint [:type :type/Number])
- [default-option all-options] (cond
- (types/field-is-type? :type/Time field)
- [time-default-index time-dimension-indexes]
-
- (types/field-is-type? :type/Date field)
- [date-default-index date-dimension-indexes]
-
- (types/temporal-field? field)
- [datetime-default-index datetime-dimension-indexes]
-
- (and min_value max_value
- (isa? semantic_type :type/Coordinate)
- (supports-numeric-binning? db))
- [coordinate-default-index coordinate-dimension-indexes]
-
- (and min_value max_value
- (isa? base_type :type/Number)
- (not (isa? semantic_type :Relation/*))
- (supports-numeric-binning? db))
- [numeric-default-index numeric-dimension-indexes]
-
- :else
- [nil []])]
- (assoc field
- :default_dimension_option default-option
- :dimension_options all-options)))
-
-(defn- assoc-dimension-options [resp db]
- (-> resp
- (assoc :dimension_options dimension-options-for-response)
- (update :fields (fn [fields]
- (mapv #(assoc-field-dimension-options % db) fields)))))
-
(defn- format-fields-for-response [resp]
(update resp :fields
(fn [fields]
@@ -232,18 +32,16 @@
(if include-editable-data-model?
(api/write-check table)
(api/read-check table))
- (let [db (t2/select-one :model/Database :id (:db_id table))]
- (-> table
- (t2/hydrate :db [:fields [:target :has_field_values] :has_field_values :dimensions :name_field] :segments :metrics)
- (m/dissoc-in [:db :details])
- (assoc-dimension-options db)
- format-fields-for-response
- present-table
- (update :fields (partial filter (fn [{visibility-type :visibility_type}]
- (case (keyword visibility-type)
- :hidden include-hidden-fields?
- :sensitive include-sensitive-fields?
- true)))))))
+ (-> table
+ (t2/hydrate :db [:fields [:target :has_field_values] :has_field_values :dimensions :name_field] :segments :metrics)
+ (m/dissoc-in [:db :details])
+ format-fields-for-response
+ present-table
+ (update :fields (partial filter (fn [{visibility-type :visibility_type}]
+ (case (keyword visibility-type)
+ :hidden include-hidden-fields?
+ :sensitive include-sensitive-fields?
+ true))))))
(defn batch-fetch-query-metadatas*
"Returns the query metadata used to power the Query Builder for the `table`s specified by `ids`."
@@ -279,7 +77,7 @@
"Return a sequence of 'virtual' fields metadata for the 'virtual' table for a Card in the Saved Questions 'virtual'
database.
`metadata-fields` can be nil."
- [card-id database metadata metadata-fields]
+ [card-id metadata metadata-fields]
(let [underlying (m/index-by :id (or metadata-fields
(when-let [ids (seq (keep :id metadata))]
(-> (t2/select :model/Field :id [:in ids])
@@ -297,8 +95,7 @@
;; Assoc semantic_type at least temprorarily. We need the correct semantic type in place to make
;; decisions about what kind of dimension options should be added. PK/FK values will be removed
;; after we've added the dimension options
- :semantic_type (keyword (:semantic_type col)))
- (assoc-field-dimension-options database)))]
+ :semantic_type (keyword (:semantic_type col)))))]
fields))
(defn root-collection-schema-name
@@ -335,7 +132,6 @@
include-fields?
(assoc :fields (card-result-metadata->virtual-fields (u/the-id card)
- database
(:result_metadata card)
(when card-id->metadata-fields
(card-id->metadata-fields (u/the-id card))))))))
@@ -401,5 +197,4 @@
:include-fields? true
:databases dbs
:card-id->metadata-fields card-id->metadata-fields)
- (assoc-dimension-options (-> card :database_id dbs))
(remove-nested-pk-fk-semantic-types {:trust-semantic-keys? trust-semantic-keys?})))))))
diff --git a/test/metabase/warehouse_schema/api/table_test.clj b/test/metabase/warehouse_schema/api/table_test.clj
index 26cb33eea85..ba93cb79458 100644
--- a/test/metabase/warehouse_schema/api/table_test.clj
+++ b/test/metabase/warehouse_schema/api/table_test.clj
@@ -1,26 +1,20 @@
(ns ^:mb/driver-tests metabase.warehouse-schema.api.table-test
"Tests for /api/table endpoints."
(:require
- #_[metabase.sync.core :as sync]
[clojure.set :as set]
[clojure.test :refer :all]
- [medley.core :as m]
[metabase.api.response :as api.response]
[metabase.api.test-util :as api.test-util]
- [metabase.driver :as driver]
[metabase.driver.util :as driver.u]
[metabase.events.core :as events]
- [metabase.lib.util.match :as lib.util.match]
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.permissions.models.permissions :as perms]
[metabase.permissions.models.permissions-group :as perms-group]
[metabase.test :as mt]
[metabase.test.http-client :as client]
- [metabase.timeseries-query-processor-test.util :as tqpt]
[metabase.upload.impl-test :as upload-test]
[metabase.util :as u]
[metabase.warehouse-schema.api.table :as api.table]
- [metabase.warehouse-schema.table :as schema.table]
[toucan2.core :as t2]))
(set! *warn-on-reflection* true)
@@ -75,10 +69,8 @@
(defn- field-defaults []
(merge
(mt/object-defaults :model/Field)
- {:default_dimension_option nil
- ;; Index sync is turned off across the application as it is not used ATM.
+ {;; Index sync is turned off across the application as it is not used ATM.
#_#_:database_indexed false
- :dimension_options []
:dimensions []
:position 0
:target nil
@@ -92,10 +84,6 @@
[:created_at :fingerprint :fingerprint_version :fk_target_field_id :id :last_analyzed :updated_at
:database_required :database_is_auto_increment :entity_id])))
-(defn- fk-field-details [field]
- (-> (field-details field)
- (dissoc :dimension_options :default_dimension_option)))
-
(deftest ^:parallel list-table-test
(testing "GET /api/table"
(testing "These should come back in alphabetical order and include relevant metadata"
@@ -242,22 +230,8 @@
(testing "returns 404 for tables that don't exist"
(mt/user-http-request :rasta :get 404 (format "table/%d/data" 133713371337)))))))
-(defn- default-dimension-options []
- (as-> @#'schema.table/dimension-options-for-response options
- (m/map-vals #(-> %
- (update :name str)
- (update :type
- (fn [t]
- (apply str
- ((juxt namespace (constantly "/") name) t)))))
- options)
- (m/map-keys parse-long options)
- ;; since we're comparing API responses, need to de-keywordize the `:field` clauses
- (lib.util.match/replace options :field (mt/obj->json->obj &match))))
-
(defn- query-metadata-defaults []
- (-> (table-defaults)
- (assoc :dimension_options (default-dimension-options))))
+ (table-defaults))
(deftest ^:parallel sensitive-fields-included-test
(testing "GET api/table/:id/query_metadata?include_sensitive_fields"
@@ -301,8 +275,6 @@
:base_type "type/Text"
:effective_type "type/Text"
:visibility_type "normal"
- :dimension_options []
- :default_dimension_option nil
:has_field_values "list"
:position 1
:database_position 1
@@ -317,8 +289,6 @@
:base_type "type/DateTime"
:effective_type "type/DateTime"
:visibility_type "normal"
- :dimension_options @#'schema.table/datetime-dimension-indexes
- :default_dimension_option @#'schema.table/datetime-default-index
:has_field_values "none"
:position 2
:database_position 2
@@ -397,8 +367,6 @@
:database_type "TIMESTAMP"
:base_type "type/DateTime"
:effective_type "type/DateTime"
- :dimension_options @#'schema.table/datetime-dimension-indexes
- :default_dimension_option @#'schema.table/datetime-default-index
:has_field_values "none"
:position 2
:database_position 2
@@ -609,7 +577,7 @@
(is (= [{:origin_id (:id checkins-user-field)
:destination_id (:id users-id-field)
:relationship "Mt1"
- :origin (-> (fk-field-details checkins-user-field)
+ :origin (-> (field-details checkins-user-field)
(dissoc :target :dimensions :values)
(assoc :table_id (mt/id :checkins)
:name "USER_ID"
@@ -632,7 +600,7 @@
:name "CHECKINS"
:display_name "Checkins"
:entity_type "entity/EventTable"})))
- :destination (-> (fk-field-details users-id-field)
+ :destination (-> (field-details users-id-field)
(dissoc :target :dimensions :values)
(assoc :table_id (mt/id :users)
:name "ID"
@@ -697,8 +665,6 @@
:database_type "CHARACTER VARYING"
:base_type "type/Text"
:effective_type "type/Text"
- :dimension_options []
- :default_dimension_option nil
:has_field_values "list"
:database_position 1
:position 1
@@ -734,20 +700,8 @@
(assoc field :id ["field" field-name {:base-type base-type}]))
(defn- default-card-field-for-venues [table-id]
- {:table_id table-id
- :semantic_type nil
- :default_dimension_option nil
- :dimension_options []})
-
-(defn- with-numeric-dimension-options [field]
- (assoc field
- :default_dimension_option @#'schema.table/numeric-default-index
- :dimension_options @#'schema.table/numeric-dimension-indexes))
-
-(defn- with-coordinate-dimension-options [field]
- (assoc field
- :default_dimension_option @#'schema.table/coordinate-default-index
- :dimension_options @#'schema.table/coordinate-dimension-indexes))
+ {:table_id table-id
+ :semantic_type nil})
;; Make sure metadata for 'virtual' tables comes back as expected
(deftest ^:parallel virtual-table-metadata-test
@@ -772,7 +726,6 @@
:moderated_status nil
:metrics nil
:description nil
- :dimension_options (default-dimension-options)
:fields (map (comp #(merge (default-card-field-for-venues card-virtual-table-id) %)
with-field-literal-id)
(let [id->fingerprint (t2/select-pk->fn :fingerprint :model/Field :table_id (mt/id :venues))
@@ -793,24 +746,22 @@
:semantic_type nil
:fingerprint (name->fingerprint :id)
:field_ref ["field" "ID" {:base-type "type/BigInteger"}]}
- (with-numeric-dimension-options
- {:name "PRICE"
- :display_name "PRICE"
- :base_type "type/Integer"
- :effective_type "type/Integer"
- :database_type "INTEGER"
- :semantic_type nil
- :fingerprint (name->fingerprint :price)
- :field_ref ["field" "PRICE" {:base-type "type/Integer"}]})
- (with-coordinate-dimension-options
- {:name "LATITUDE"
- :display_name "LATITUDE"
- :base_type "type/Float"
- :effective_type "type/Float"
- :database_type "DOUBLE PRECISION"
- :semantic_type "type/Latitude"
- :fingerprint (name->fingerprint :latitude)
- :field_ref ["field" "LATITUDE" {:base-type "type/Float"}]})]))})
+ {:name "PRICE"
+ :display_name "PRICE"
+ :base_type "type/Integer"
+ :effective_type "type/Integer"
+ :database_type "INTEGER"
+ :semantic_type nil
+ :fingerprint (name->fingerprint :price)
+ :field_ref ["field" "PRICE" {:base-type "type/Integer"}]}
+ {:name "LATITUDE"
+ :display_name "LATITUDE"
+ :base_type "type/Float"
+ :effective_type "type/Float"
+ :database_type "DOUBLE PRECISION"
+ :semantic_type "type/Latitude"
+ :fingerprint (name->fingerprint :latitude)
+ :field_ref ["field" "LATITUDE" {:base-type "type/Float"}]}]))})
(->> card
u/the-id
(format "table/card__%d/query_metadata")
@@ -885,7 +836,6 @@
:description nil
:moderated_status nil
:metrics nil
- :dimension_options (default-dimension-options)
:fields [{:name "NAME"
:display_name "NAME"
:base_type "type/Text"
@@ -894,8 +844,6 @@
:table_id card-virtual-table-id
:id ["field" "NAME" {:base-type "type/Text"}]
:semantic_type "type/Name"
- :default_dimension_option nil
- :dimension_options []
:fingerprint (:fingerprint name-metadata)
:field_ref ["field" "NAME" {:base-type "type/Text"}]}
{:name "LAST_LOGIN"
@@ -906,8 +854,6 @@
:table_id card-virtual-table-id
:id ["field" "LAST_LOGIN" {:base-type "type/DateTime"}]
:semantic_type nil
- :default_dimension_option @#'schema.table/datetime-default-index
- :dimension_options @#'schema.table/datetime-dimension-indexes
:fingerprint (:fingerprint last-login-metadata)
:field_ref ["field" "LAST_LOGIN" {:base-type "type/DateTime"}]}]}
(mt/user-http-request :crowberto :get 200
@@ -1033,143 +979,6 @@
(narrow-fields ["PRICE" "CATEGORY_ID"]
(mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :venues))))))))))))
-(defn field-from-response [response, ^String field-name]
- (->> response
- :fields
- (m/find-first #(.equalsIgnoreCase field-name, ^String (:name %)))))
-
-(defn- dimension-options-for-field [response, ^String field-name]
- (:dimension_options (field-from-response response field-name)))
-
-(defn- extract-dimension-options
- "For the given `field-name` find it's dimension_options following the indexes given in the field"
- [response field-name]
- (set
- (for [dim-index (dimension-options-for-field response field-name)
- :let [{clause :mbql} (get-in response [:dimension_options (Long/parseLong dim-index)])]]
- clause)))
-
-(deftest ^:parallel numeric-binning-options-test
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for numeric fields"
- (testing "Lat/Long fields should use bin-width rather than num-bins"
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :venues)))]
- (is (= #{nil
- ["field" nil {:binning {:strategy "bin-width", :bin-width 10.0}}]
- ["field" nil {:binning {:strategy "bin-width", :bin-width 0.1}}]
- ["field" nil {:binning {:strategy "bin-width", :bin-width 1.0}}]
- ["field" nil {:binning {:strategy "bin-width", :bin-width 20.0}}]
- ["field" nil {:binning {:strategy "default"}}]}
- (extract-dimension-options response "latitude"))))))))
-
-(deftest numeric-binning-options-test-2
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for numeric fields"
- (testing "Number columns without a semantic type should use \"num-bins\""
- (mt/with-temp-vals-in-db :model/Field (mt/id :venues :price) {:semantic_type nil}
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :venues)))]
- (is (= #{nil
- ["field" nil {:binning {:strategy "num-bins", :num-bins 50}}]
- ["field" nil {:binning {:strategy "default"}}]
- ["field" nil {:binning {:strategy "num-bins", :num-bins 100}}]
- ["field" nil {:binning {:strategy "num-bins", :num-bins 10}}]}
- (extract-dimension-options response "price")))))))))
-
-(deftest numeric-binning-options-test-3
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for numeric fields"
- (testing "Number columns with a relationship semantic type should not have binning options"
- (mt/with-temp-vals-in-db :model/Field (mt/id :venues :price) {:semantic_type "type/PK"}
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :venues)))]
- (is (= #{}
- (extract-dimension-options response "price")))))))))
-
-(deftest numeric-binning-options-test-4
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for numeric fields"
- (testing "Numeric fields without min/max values should not have binning options"
- (let [fingerprint (t2/select-one-fn :fingerprint :model/Field :id (mt/id :venues :latitude))
- temp-fingerprint (-> fingerprint
- (assoc-in [:type :type/Number :max] nil)
- (assoc-in [:type :type/Number :min] nil))]
- (mt/with-temp-vals-in-db :model/Field (mt/id :venues :latitude) {:fingerprint temp-fingerprint}
- (is (= []
- (-> (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :categories)))
- (get :fields)
- first
- :dimension_options)))))))))
-
-(deftest ^:parallel datetime-binning-options-test
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for datetime fields"
- (testing "should show up whether the backend supports binning of numeric values or not"
- (mt/test-drivers #{:druid}
- (tqpt/with-flattened-dbdef
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :checkins)))]
- (is (= @#'schema.table/datetime-dimension-indexes
- (dimension-options-for-field response "timestamp"))))))))))
-
-(deftest ^:parallel datetime-binning-options-test-2
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for datetime fields"
- (testing "dates"
- (mt/test-drivers (mt/normal-drivers)
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :checkins)))
- field (field-from-response response "date")]
- ;; some dbs don't have a date type and return a datetime
- (is (= (case (:effective_type field)
- ("type/DateTime" "type/Instant") @#'schema.table/datetime-dimension-indexes
- "type/Date" @#'schema.table/date-dimension-indexes
- (throw (ex-info "Invalid type for date field or field not found"
- {:expected-types #{"type/DateTime" "type/Date"}
- :found (:effective_type field)
- :field field
- :driver driver/*driver*})))
- (:dimension_options field)))))))))
-
-(deftest ^:parallel datetime-binning-options-test-3
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for datetime fields"
- (testing "unix timestamps"
- (mt/dataset sad-toucan-incidents
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :incidents)))]
- (is (= @#'schema.table/datetime-dimension-indexes
- (dimension-options-for-field response "timestamp")))))))))
-
-(deftest ^:parallel datetime-binning-options-test-4
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for datetime fields"
- (testing "time columns"
- (mt/test-drivers (mt/normal-drivers-with-feature :test/time-type)
- (mt/dataset time-test-data
- (let [response (mt/user-http-request :rasta :get 200 (format "table/%d/query_metadata" (mt/id :users)))]
- (is (= @#'schema.table/time-dimension-indexes
- (dimension-options-for-field response "last_login_time"))))))))))
-
-(deftest nested-queries-binning-options-test
- (testing "GET /api/table/:id/query_metadata"
- (testing "binning options for nested queries"
- (mt/test-drivers (mt/normal-drivers-with-feature :binning :nested-queries)
- (mt/with-temp [:model/Card card {:database_id (mt/id)
- :dataset_query {:database (mt/id)
- :type :query
- :query {:source-query {:source-table (mt/id :venues)}}}}]
- (letfn [(dimension-options []
- (let [response (mt/user-http-request :crowberto :get 200 (format "table/card__%d/query_metadata" (u/the-id card)))]
- (map #(dimension-options-for-field response %) ["latitude" "longitude"])))]
- (testing "Nested queries missing a fingerprint/results metadata should not show binning-options"
- (mt/with-temp-vals-in-db :model/Card (:id card) {:result_metadata nil}
- ;; By default result_metadata will be nil (and no fingerprint). Just asking for query_metadata after the
- ;; card was created but before it was ran should not allow binning
- (is (= [nil nil]
- (dimension-options)))))
- (testing "Nested queries with a fingerprint should have dimension options for binning"
- ;; run the Card which will populate its result_metadata column
- (mt/user-http-request :crowberto :post 202 (format "card/%d/query" (u/the-id card)))
- (mt/user-http-request :crowberto :get 200 (format "table/card__%d/query_metadata" (u/the-id card)))
- (is (= (repeat 2 @#'schema.table/coordinate-dimension-indexes)
- (dimension-options))))))))))
-
(deftest ^:parallel card-type-and-dataset-query-are-returned-with-metadata
(testing "GET /api/table/card__:id/query_metadata returns card type"
(let [dataset-query (mt/mbql-query venues
diff --git a/test/metabase/warehouse_schema/table_test.clj b/test/metabase/warehouse_schema/table_test.clj
deleted file mode 100644
index a9186f79e08..00000000000
--- a/test/metabase/warehouse_schema/table_test.clj
+++ /dev/null
@@ -1,13 +0,0 @@
-(ns metabase.warehouse-schema.table-test
- (:require
- [clojure.test :refer :all]
- [metabase.warehouse-schema.table :as schema.table]))
-
-(deftest ^:parallel dimension-options-sort-test
- (testing "Ensure dimensions options are sorted numerically, but returned as strings"
- (testing "datetime indexes"
- (is (= (map str (sort (map parse-long @#'schema.table/datetime-dimension-indexes)))
- @#'schema.table/datetime-dimension-indexes)))
- (testing "numeric indexes"
- (is (= (map str (sort (map parse-long @#'schema.table/numeric-dimension-indexes)))
- @#'schema.table/numeric-dimension-indexes)))))
diff --git a/test/metabase/warehouses/api_test.clj b/test/metabase/warehouses/api_test.clj
index b7ed2cf9397..bc6baa62d75 100644
--- a/test/metabase/warehouses/api_test.clj
+++ b/test/metabase/warehouses/api_test.clj
@@ -1192,9 +1192,7 @@
:table_id (str "card__" (u/the-id card))
:id ["field" "age_in_bird_years" {:base-type "type/Integer"}]
:semantic_type nil
- :base_type "type/Integer"
- :default_dimension_option nil
- :dimension_options []}]))))))
+ :base_type "type/Integer"}]))))))
(deftest db-metadata-saved-questions-db-test-2
(testing "GET /api/database/:id/metadata works for the Saved Questions 'virtual' database"