The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
[BOT-1840] Drop visualizer bespoke search index cols (#77684)
Tyler Plude1f0d8d6b34d4
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 957f4dbf12c..4f1b8b31c52 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -3564,6 +3564,7 @@configconnection-poolevents+ lib-bellmmetabotmodelsdiff --git a/enterprise/backend/src/metabase_enterprise/semantic_search/task/index_repair.clj b/enterprise/backend/src/metabase_enterprise/semantic_search/task/index_repair.cljindex 4553bcfe39f..e2618064baf 100644--- a/enterprise/backend/src/metabase_enterprise/semantic_search/task/index_repair.clj+++ b/enterprise/backend/src/metabase_enterprise/semantic_search/task/index_repair.clj@@ -6,6 +6,7 @@[clojurewerkz.quartzite.triggers :as triggers][metabase-enterprise.semantic-search.core :as semantic-search.core][metabase-enterprise.semantic-search.util :as semantic.u]+ [metabase.lib-be.core :as lib-be][metabase.search.ingestion :as search.ingestion][metabase.task.core :as task][metabase.util.log :as log])@@ -24,7 +25,10 @@(log/with-context {:quartz-job-type 'SemanticIndexRepair}(try(log/info "Starting semantic search index repair")- (semantic-search.core/repair-index! (search.ingestion/searchable-documents))+ ;; The document eduction is realized inside repair-index!, so the metadata-provider cache must be+ ;; bound around the whole call for spec :fn attrs that touch metadata to benefit from it.+ (lib-be/with-metadata-provider-cache+ (semantic-search.core/repair-index! (search.ingestion/searchable-documents)))(log/info "Completed semantic search index repair")(catch Exception e(log/error e "Failed to complete semantic search index repair"))))))diff --git a/frontend/src/metabase-types/api/search.ts b/frontend/src/metabase-types/api/search.tsindex ced1926fa2a..cf1e486cccc 100644--- a/frontend/src/metabase-types/api/search.ts+++ b/frontend/src/metabase-types/api/search.ts@@ -161,8 +161,6 @@ export type SearchRequest = {model_ancestors?: boolean | null;include_dashboard_questions?: boolean | null;include_metadata?: boolean | null;- non_temporal_dim_ids?: string | null;- has_temporal_dim?: boolean | null;search_engine?: "appdb" | "in-place" | "semantic" | null;display_type?: string[] | null;diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsxindex 1433c072446..686182239a6 100644--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx@@ -40,6 +40,7 @@ export const SearchInputContainer = styled.div<{}return css`background-color: var(--mb-color-background_page-primary);+&:hover {background-color: var(--mb-color-background_page-secondary);}diff --git a/frontend/src/metabase/visualizer/components/DataImporter/DatasetsList/DatasetsList.tsx b/frontend/src/metabase/visualizer/components/DataImporter/DatasetsList/DatasetsList.tsxindex 8991ddfb703..714495770d5 100644--- a/frontend/src/metabase/visualizer/components/DataImporter/DatasetsList/DatasetsList.tsx+++ b/frontend/src/metabase/visualizer/components/DataImporter/DatasetsList/DatasetsList.tsx@@ -5,21 +5,15 @@ import { useListRecentsQuery, useSearchQuery } from "metabase/api";import { useDebouncedValue } from "metabase/common/hooks/use-debounced-value";import { useDispatch, useSelector } from "metabase/redux";import { Box, Flex, Skeleton } from "metabase/ui";-import { isNotNull } from "metabase/utils/types";-import { isCartesianChart } from "metabase/visualizations";import {getDataSources,getDatasets,- getVisualizationColumns,getVisualizationType,getVisualizerComputedSettings,getVisualizerComputedSettingsForFlatSeries,getVisualizerDatasetColumns,} from "metabase/visualizer/selectors";-import {- createDataSource,- partitionTimeDimensions,-} from "metabase/visualizer/utils";+import { createDataSource } from "metabase/visualizer/utils";import {addDataSource,removeDataSource,@@ -36,6 +30,12 @@ import { trackVisualizerDataChanged } from "../../analytics";import { DatasetsListItem, type Item } from "./DatasetsListItem";import { getIsCompatible } from "./getIsCompatible";+const SEARCH_LIMIT = 50;+// Without a text query, incompatible results are filtered out client-side+// rather than marked as not recommended, so fetch a wider window to avoid+// showing an empty list when compatible datasets rank below the limit.+const NO_QUERY_SEARCH_LIMIT = 200;+function shouldIncludeDashboardQuestion(searchItem: SearchResult,dashboardId: DashboardId | undefined,@@ -79,7 +79,6 @@ export function DatasetsList({// Get current visualization contextconst visualizationType = useSelector(getVisualizationType);- const visualizationColumns = useSelector(getVisualizationColumns);// Get data needed for compatibility checkingconst columns = useSelector(getVisualizerDatasetColumns);@@ -117,32 +116,15 @@ export function DatasetsList({},);- const { timeDimensions, otherDimensions } = useMemo(() => {- return partitionTimeDimensions(visualizationColumns || []);- }, [visualizationColumns]);-- const nonTemporalDimIds = useMemo(() => {- return otherDimensions- .map((dim) => dim.id)- .filter(isNotNull)- .sort();- }, [otherDimensions]);-const { data: visualizationSearchResult, isFetching: isSearchFetching } =useSearchQuery({q: search.length > 0 ? search : undefined,- limit: 50,+ limit: search.length > 0 ? SEARCH_LIMIT : NO_QUERY_SEARCH_LIMIT,models: ["card", "dataset", "metric"],include_dashboard_questions: true,include_metadata: true,context: "data-picker",- ...(visualizationType &&- isCartesianChart(visualizationType) &&- search.length === 0 && {- has_temporal_dim: timeDimensions.length > 0,- non_temporal_dim_ids: JSON.stringify(nonTemporalDimIds),- }),},{skip: muted,diff --git a/frontend/src/metabase/visualizer/utils/column.ts b/frontend/src/metabase/visualizer/utils/column.tsindex e5280f7ca58..12e7d5f1548 100644--- a/frontend/src/metabase/visualizer/utils/column.ts+++ b/frontend/src/metabase/visualizer/utils/column.ts@@ -1,7 +1,3 @@-import _ from "underscore";--import { isPivotGroupColumn } from "metabase/visualizations/lib/data_grid";-import { isDate, isDimension, isMetric } from "metabase-lib/v1/types/utils/isa";import type {DatasetColumn,VisualizerColumnReference,@@ -133,21 +129,3 @@ export function extractReferencedColumns(export function isArtificialColumn(column: DatasetColumn) {return column.source === "artificial";}--export function partitionTimeDimensions(columns: DatasetColumn[]): {- dimensions: DatasetColumn[];- timeDimensions: DatasetColumn[];- otherDimensions: DatasetColumn[];-} {- // Extract only dimension columns (exclude metrics and pivot group columns)- const dimensions = columns.filter(- (col) => isDimension(col) && !isMetric(col) && !isPivotGroupColumn(col),- );-- // Partition temporal & non-temporal dimensions- const [timeDimensions, otherDimensions] = _.partition(dimensions, (col) =>- isDate(col),- );-- return { dimensions, timeDimensions, otherDimensions };-}diff --git a/src/metabase/queries/models/card.clj b/src/metabase/queries/models/card.cljindex 1e45c13dbd9..5294810344c 100644--- a/src/metabase/queries/models/card.clj+++ b/src/metabase/queries/models/card.clj@@ -25,7 +25,6 @@[metabase.lib.schema.id :as lib.schema.id][metabase.lib.schema.metadata :as lib.schema.metadata][metabase.lib.schema.template-tag :as lib.schema.template-tag]- [metabase.lib.types.isa :as lib.types][metabase.metrics.core :as metrics][metabase.models.interface :as mi][metabase.models.serialization :as serdes]@@ -48,7 +47,6 @@[metabase.util.embed :refer [maybe-populate-initially-published-at]][metabase.util.honey-sql-2 :as h2x][metabase.util.i18n :refer [tru]]- [metabase.util.json :as json][metabase.util.log :as log][metabase.util.malli :as mu][methodical.core :as methodical]@@ -1486,34 +1484,6 @@;;;; ------------------------------------------------- Search -----------------------------------------------------------(mu/defn- dataset-query->dimensions :- [:maybe [:sequential ::lib.schema.metadata/column]]- "Extract dimensions (non-aggregation columns) from a dataset query."- [dataset-query-str :- [:maybe :string]]- (when dataset-query-str- ;; In production the :database should be always present and correct. That is not the case for some test mocks.- ;; As e.g. in [[metabase-enterprise.semantic-search.test-util/do-with-indexable-documents!]]. Hence the thorough- ;; checking.- (when-some [query (not-empty ((:out lib-be/transform-query) dataset-query-str))]- (let [columns (lib/returned-columns query)]- ;; Dimensions are columns that are not aggregations- (remove (comp #{:source/aggregations} :lib/source) columns)))))--(defn- extract-temporal-info- "Compute has-temporal-dim and non-temporal-dim-ids in a single dataset-query->dimensions call.- Returns a map with snake_case keys so the ingestion layer can merge them directly into the document,- avoiding the cost of calling dataset-query->dimensions twice per card. See PR 60912.- Short-circuits for native queries: they have no returnable column metadata so temporal dims are always absent."- [{:keys [dataset_query query_type]}]- (if (= query_type "native")- {:has_temporal_dim false :non_temporal_dim_ids "[]"}- (let [dimensions (dataset-query->dimensions dataset_query)- non-temp-ids (->> dimensions- (remove lib.types/temporal?)- (keep :id)- sort)]- {:has_temporal_dim (boolean (some lib.types/temporal? dimensions))- :non_temporal_dim_ids (json/encode (or (seq non-temp-ids) []))})))-(defn- maybe-extract-native-query"Return the native SQL text (truncated to `max-searchable-value-length`) if `dataset_query` is native; else nil.Uses `query_type` to short-circuit without parsing JSON for non-native cards."@@ -1549,10 +1519,7 @@:display-type :this.display:collection-type :collection.type:collection-location :collection.location- :root-collection-type {:fn collection/root-collection-type}- :temporal-info {:fn extract-temporal-info- :fields [:dataset_query :query_type]- :provides [:has-temporal-dim :non-temporal-dim-ids]}}+ :root-collection-type {:fn collection/root-collection-type}}:search-terms [:name :description]:render-terms {:archived-directly true:collection-authority_level :collection.authority_leveldiff --git a/src/metabase/search/api.clj b/src/metabase/search/api.cljindex f7d21b50c92..1dab528d962 100644--- a/src/metabase/search/api.clj+++ b/src/metabase/search/api.clj@@ -18,8 +18,6 @@[metabase.task.core :as task][metabase.util :as u][metabase.util.i18n :refer [tru]]- [metabase.util.json :as json]- [metabase.util.log :as log][metabase.util.malli :as mu][metabase.util.malli.schema :as ms][ring.util.response :as response]@@ -54,21 +52,6 @@:path "/":max-age 0}))))-(defn- process-non-temporal-dim-ids- "Parse and process non-temporal dimension IDs JSON string.- Filters out null values and sorts ascending, returning as JSON string."- [non-temporal-dim-ids]- (when non-temporal-dim-ids- (try- (->> (json/decode non-temporal-dim-ids)- (remove nil?)- sort- vec- json/encode)- (catch Exception e- (log/warn "Failed to parse non-temporal dimension IDs:" (ex-message e))- nil))))-(defn- param->engine"Parse a search_engine param or cookie value into an engine keyword, nil when blank.Malformed non-blank values parse to an unknown engine rather than nil, so explicit requests 400."@@ -251,9 +234,7 @@[:ids {:optional true} [:maybe (ms/QueryVectorOf ms/PositiveInt)]][:calculate_available_models {:optional true} [:maybe true?]][:include_dashboard_questions {:default false} [:maybe :boolean]]- [:include_metadata {:default false} [:maybe :boolean]]- [:non_temporal_dim_ids {:optional true} [:maybe ms/NonBlankString]]- [:has_temporal_dim {:optional true} [:maybe :boolean]]])+ [:include_metadata {:default false} [:maybe :boolean]]])(def ^:private search-debug-request-schema(conj search-request-schema@@ -281,9 +262,7 @@vector-search-explain :vector_search_explainsearch-native-query :search_native_querytable-db-id :table_db_id- include-metadata :include_metadata- non-temporal-dim-ids :non_temporal_dim_ids- has-temporal-dim :has_temporal_dim}]+ include-metadata :include_metadata}](search/search-context{:archived archived:collection collection@@ -315,8 +294,6 @@:calculate-available-models? calculate-available-models:include-dashboard-questions? include-dashboard-questions:include-metadata? include-metadata- :non-temporal-dim-ids (process-non-temporal-dim-ids non-temporal-dim-ids)- :has-temporal-dim has-temporal-dim:display-type (set display-type)}))#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case@@ -347,8 +324,6 @@- `verified`: set to true to search for verified items only (requires Content Management or Official Collections premium feature)- `ids`: search for items with those ids, works iff single value passed to `models`- `display_type`: search for cards/models with specific display types- - `non_temporal_dim_ids`: search for cards/metrics/datasets with this exact set of non temporal dimension field IDs (requires appdb engine)- - `has_temporal_dim`: set to true for cards/metrics/datasets with 1 or more temporal dimensions (requires appdb engine)Note that not all item types support all filters, and the results will include only models that support the providedfilters. For example:diff --git a/src/metabase/search/config.clj b/src/metabase/search/config.cljindex 8d03d7db28c..476cc5b6bc8 100644--- a/src/metabase/search/config.clj+++ b/src/metabase/search/config.clj@@ -224,8 +224,6 @@;; so the filter is a single indexed boolean. No :required-feature: a signal can only be set while;; its feature is present, so the precomputed flag is already feature-correct.:curated {:type :single-value, :context-key :curated?, :supported-value? #{true}}- :non-temporal-dim-ids {:type :single-value :engine :appdb}- :has-temporal-dim {:type :single-value :engine :appdb}:display-type {:type :list, :field "display_type"}}))(def ^:private filter-defaults-by-context@@ -464,8 +462,6 @@[:ids {:optional true} [:set {:min 1} ms/PositiveInt]][:include-dashboard-questions? {:optional true} :boolean][:include-metadata? {:optional true} :boolean]- [:non-temporal-dim-ids {:optional true} ms/NonBlankString]- [:has-temporal-dim {:optional true} :boolean][:enabled-transform-source-types [:set ms/NonBlankString]]])(defmulti column->stringdiff --git a/src/metabase/search/filter.clj b/src/metabase/search/filter.cljindex 3c23b77410f..35012dafa68 100644--- a/src/metabase/search/filter.clj+++ b/src/metabase/search/filter.clj@@ -33,15 +33,11 @@(dissoc search.config/filters :id)))(defn- spec-supported-attr-keys- "All attr keys a spec supports, including those provided by function attrs.+ "All attr keys a spec supports.Keys with value false are excluded — false means 'not present' in the spec DSL."[spec](into #{}- (mapcat (fn [[k v]]- (cond- (search.spec/function-attr? v) (conj (search.spec/function-attr-provides v) k)- v [k]- :else [])))+ (keep (fn [[k v]] (when v k)))(:attrs spec)))(defn search-context->applicable-modelsdiff --git a/src/metabase/search/impl.clj b/src/metabase/search/impl.cljindex 35b2bc21516..e7dded35b82 100644--- a/src/metabase/search/impl.clj+++ b/src/metabase/search/impl.clj@@ -285,8 +285,6 @@[:calculate-available-models? {:optional true} [:maybe :boolean]][:include-dashboard-questions? {:optional true} [:maybe boolean?]][:include-metadata? {:optional true} [:maybe boolean?]]- [:non-temporal-dim-ids {:optional true} [:maybe ms/NonBlankString]]- [:has-temporal-dim {:optional true} [:maybe :boolean]][:display-type {:optional true} [:maybe [:set ms/NonBlankString]]][:weights {:optional true} [:maybe [:map-of :keyword number?]]]])@@ -326,8 +324,6 @@table-db-idverifiedcurated- non-temporal-dim-ids- has-temporal-dimweights]} :- ::search-context.input];; for prod where Malli is disabled{:pre [(pos-int? current-user-id) (set? current-user-perms)]}@@ -376,8 +372,6 @@(some? include-dashboard-questions?) (assoc :include-dashboard-questions? include-dashboard-questions?)(some? include-metadata?) (assoc :include-metadata? include-metadata?)(seq ids) (assoc :ids ids)- (some? non-temporal-dim-ids) (assoc :non-temporal-dim-ids non-temporal-dim-ids)- (some? has-temporal-dim) (assoc :has-temporal-dim has-temporal-dim)(seq display-type) (assoc :display-type display-type))](when (and (seq ids)(not= (count models) 1))diff --git a/src/metabase/search/in_place/filter.clj b/src/metabase/search/in_place/filter.cljindex b73a71499ab..85a7ffe4391 100644--- a/src/metabase/search/in_place/filter.clj+++ b/src/metabase/search/in_place/filter.clj@@ -299,19 +299,6 @@;; to be consistent we use revision.timestamp to do the filtering(sql.helpers/where (date-range-filter-clause :revision.timestamp last-edited-at)))))-;; These filters are really only supported by the :appdb engine as they require a search index.-;; By building this no-op filter definition for the in-place engine we can at least appropriately-;; reduce the intended supported models that are searched. See PR 60912-(doseq [model ["card" "dataset" "metric"]]- (defmethod build-optional-filter-query [:non-temporal-dim-ids model]- [_filter _model query _non-temporal-dim-ids]- query))--(doseq [model ["card" "dataset" "metric"]]- (defmethod build-optional-filter-query [:has-temporal-dim model]- [_filter _model query _has-temporal-dim]- query))-;; TODO: once we record revision for actions, we should update this to use the same approach with dashboard/card(defmethod build-optional-filter-query [:last-edited-at "action"][_filter model query last-edited-at]@@ -405,8 +392,6 @@search-native-queryverifiedcurated?- non-temporal-dim-ids- has-temporal-dimdisplay-typeis-superuser?]} search-contextenabled-types (:enabled-transform-source-types search-context)@@ -422,8 +407,6 @@(true? search-native-query) (set/intersection (:search-native-query feature->supported-models))(true? verified) (set/intersection (:verified feature->supported-models))(true? curated?) (set/intersection (:curated feature->supported-models))- (some? non-temporal-dim-ids) (set/intersection (:non-temporal-dim-ids feature->supported-models))- (some? has-temporal-dim) (set/intersection (:has-temporal-dim feature->supported-models))(seq display-type) (set/intersection (:display-type feature->supported-models)))))(mu/defn build-filters :- :map@@ -443,8 +426,6 @@verifiedcurated?ids- non-temporal-dim-ids- has-temporal-dimdisplay-type]} search-context](cond-> honeysql-query(= model "transform")@@ -481,12 +462,6 @@(contains? models model))(#(build-optional-filter-query :id model % ids))- (some? non-temporal-dim-ids)- (#(build-optional-filter-query :non-temporal-dim-ids model % non-temporal-dim-ids))-- (some? has-temporal-dim)- (#(build-optional-filter-query :has-temporal-dim model % has-temporal-dim))-(seq display-type)(#(build-optional-filter-query :display-type model % display-type))diff --git a/src/metabase/search/ingestion.clj b/src/metabase/search/ingestion.cljindex e5a112ab9ca..7cc67acf552 100644--- a/src/metabase/search/ingestion.clj+++ b/src/metabase/search/ingestion.clj@@ -102,7 +102,8 @@(perf/select-keys m [:name :display_name :description :collection_name]))(defn- execute-function-attr- "Execute a single function attribute and return the result"+ "Execute a single function attribute and return the result, or nil if the function throws.+ nil is valid for every column type, so a failure can never poison the document's insert batch."[attr-key attr-def record](try(let [f (:fn attr-def)@@ -113,27 +114,18 @@(f input))(catch Exception e(log/warn e "Function execution failed for attribute" attr-key)- false)))+ nil)))(defn- execute-all-function-attrs"Execute all function attributes for a given spec and return computed values.- If a function returns a map, its entries are merged directly into the result —- this allows a single function to populate multiple document keys (e.g. :temporal-info- returns both :has_temporal_dim and :non_temporal_dim_ids in one call).-- When a function attr declares `:provides`, the attr-key itself is not a column in- the index — it's a logical grouping whose `:provides` keys are the real columns.- In that case, on non-map results (e.g. when the function threw and `false` was- returned), skip writing instead of poisoning the document with an unknown column."+ Each function's result is written under the attr key (snake_case) — the attr's index column."[spec record](reduce-kv(fn [acc attr-key attr-def](if (search.spec/function-attr? attr-def)- (let [result (execute-function-attr attr-key attr-def record)]- (cond- (map? result) (merge acc result)- (seq (search.spec/function-attr-provides attr-def)) acc- :else (assoc acc (keyword (u/->snake_case_en (name attr-key))) result)))+ (assoc acc+ (keyword (u/->snake_case_en (name attr-key)))+ (execute-function-attr attr-key attr-def record))acc)){}(:attrs spec)))diff --git a/src/metabase/search/spec.clj b/src/metabase/search/spec.cljindex 80948ffc007..5acd74ace4f 100644--- a/src/metabase/search/spec.clj+++ b/src/metabase/search/spec.clj@@ -27,7 +27,7 @@"transform";; The following come last as they can be slow to index due to:;; - cardinality (table, indexed-entity),- ;; - cost (e.g. computing has_temporal_dim for cards)+ ;; - cost (e.g. large text payloads and native-query parsing for cards)"table""metric""card"@@ -60,20 +60,13 @@[:union :boolean :keyword vector? :map[:map[:fn fn?]- [:fields {:optional true} [:vector :keyword]]- [:provides {:optional true} [:vector :keyword]]]])+ [:fields {:optional true} [:vector :keyword]]]])(defn function-attr?"Attributes populate by clojure functions"[attr-def](and (map? attr-def) (:fn attr-def)))-(defn function-attr-provides- "Returns the attr keys that a function attr provides when it returns a map.- Used to determine which filters a function attr satisfies."- [attr-def]- (:provides attr-def []))-(defn collect-fn-attr-req-fields"Return set of required appdb fields declared in a spec's function attrs"[spec]@@ -117,9 +110,6 @@:updated-at :timestamp:verified :boolean:view-count :int- :non-temporal-dim-ids :text- :has-temporal-dim :boolean- :temporal-info nil:display-type :text:is-published :boolean:source-type :text@@ -152,7 +142,6 @@:verified ;; in addition to being a filter, this is also a ranker:view-count:updated-at- :temporal-info:is-published:source-type:collection-type ;; surfaced for downstream consumers (metabase.search.impl/serialize)@@ -421,7 +410,8 @@Attribute value formats:- `true` - Use column with same name (snake_case)- `:column_name` - Use specified database column- - `{:fn function :fields [:field1 :field2]}` - Execute a clojure function at index time with the given fields"+ - `{:fn function :fields [:field1 :field2]}` - Execute a clojure function at index time; its scalar+ return value is written to the column named after the attr key (snake_case)."[search-model spec]`(do;; Capture raw form before evaluation (symbols stay as symbols, not function objects)diff --git a/test/metabase/queries/models/card_test.clj b/test/metabase/queries/models/card_test.cljindex adf42aac8f6..8a48761a20c 100644--- a/test/metabase/queries/models/card_test.clj+++ b/test/metabase/queries/models/card_test.clj@@ -1229,18 +1229,6 @@(is (= "Orders, Metric A"(:query_description (t2/select-one :model/Card :id b-id))))))))-(deftest extract-temporal-info-metric-reference-cycle-test- (testing "extract-temporal-info on a query aggregating a cycle-involved metric throws a cycle error (#74954)"- (do-with-metric-cycle- (fn [a-id _b-id]- (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Metric cycle detected"- (#'card/extract-temporal-info- {:dataset_query (json/encode {:database (mt/id)- :type :query- :query {:source-table (mt/id :orders)- :aggregation [["metric" a-id]]}})- :query_type "query"})))))))-(deftest before-update-card-schema-test(testing "card_schema gets set to current-schema-version on update"(mt/with-temp [:model/Card {card-id :id} {:card_schema 20}]diff --git a/test/metabase/search/api_test.clj b/test/metabase/search/api_test.cljindex ca0d2fc64df..46ead3f5aab 100644--- a/test/metabase/search/api_test.clj+++ b/test/metabase/search/api_test.clj@@ -336,6 +336,22 @@(is (=? {:engine string?}(mt/user-http-request :crowberto :get 200 "search" :q "x" :context "search-app"))))))+(deftest removed-temporal-params-ignored-test+ (testing "the removed has_temporal_dim / non_temporal_dim_ids params are silently ignored"+ ;; Stale FE bundles may still send these during rolling deploys; the request schema is an open map,+ ;; so they pass validation and never reach the search context.+ (let [captured (atom nil)]+ (mt/with-dynamic-fn-redefs [search/search (fn [search-ctx]+ (reset! captured search-ctx)+ {:data [] :total 0 :engine "test"})]+ (is (=? {:engine string?}+ (mt/user-http-request :crowberto :get 200 "search"+ :q "x"+ :has_temporal_dim "true"+ :non_temporal_dim_ids "[1,2]"))))+ (is (not (contains? @captured :has-temporal-dim)))+ (is (not (contains? @captured :non-temporal-dim-ids))))))+(deftest explicit-engine-validation-test(testing "an explicit search_engine that cannot serve returns a 400 naming the reason"(testing "unknown engine"diff --git a/test/metabase/search/filter_test.clj b/test/metabase/search/filter_test.cljindex 87e4ccd8adf..7ef0f1ec82c 100644--- a/test/metabase/search/filter_test.clj+++ b/test/metabase/search/filter_test.clj@@ -94,8 +94,6 @@:verified true:curated? true:ids [1 2 3 4]- :non-temporal-dim-ids "[1]"- :has-temporal-dim true:display-type ["line"]:models (disj search.config/all-models "dataset"):enabled-transform-source-types #{"mbql"}})@@ -151,8 +149,6 @@[:in :search_index.model_id ["1" "2" "3" "4"]][:< [:cast :search_index.last_edited_at :date] #t "2024-10-03"][:>= [:cast :search_index.model_created_at :date] #t "2024-10-01"]- [:= :search_index.non_temporal_dim_ids "[1]"]- [:= :search_index.has_temporal_dim true]:and[:= :search_index.database_id 231][:in :search_index.display_type ["line"]]diff --git a/test/metabase/search/ingestion_test.clj b/test/metabase/search/ingestion_test.cljindex f5c0b00ecd5..29139c24a2a 100644--- a/test/metabase/search/ingestion_test.clj+++ b/test/metabase/search/ingestion_test.clj@@ -105,19 +105,21 @@"Excluded fields remain in full-text searchable-text")))))(deftest execute-all-function-attrs-test- (testing "function-attr returning a map merges its keys into the document"- (let [spec {:attrs {:temporal-info {:fn (constantly {:has_temporal_dim true :non_temporal_dim_ids "[1 2]"})- :provides [:has-temporal-dim :non-temporal-dim-ids]}}}]- (is (= {:has_temporal_dim true :non_temporal_dim_ids "[1 2]"}- (#'search.ingestion/execute-all-function-attrs spec {})))))- (testing "function-attr without :provides falls back to writing snake_case attr-key on non-map results"+ (testing "function-attr result is written under the snake_case attr-key"(let [spec {:attrs {:native-query {:fn (constantly "SELECT 1")}}}](is (= {:native_query "SELECT 1"}(#'search.ingestion/execute-all-function-attrs spec {})))))- (testing "function-attr with :provides skips writing when result is not a map"- (let [spec {:attrs {:temporal-info {:fn (fn [_] (throw (ex-info "boom" {})))- :provides [:has-temporal-dim :non-temporal-dim-ids]}}}]- (is (= {} (#'search.ingestion/execute-all-function-attrs spec {}))))))+ (testing "function-attr receives only the record keys declared in :fields"+ (let [spec {:attrs {:native-query {:fn #(vec (sort (keys %)))+ :fields [:dataset_query :query_type]}}}]+ (is (= {:native_query [:dataset_query :query_type]}+ (#'search.ingestion/execute-all-function-attrs+ spec+ {:dataset_query "{}" :query_type "native" :name "ignored"})))))+ (testing "a throwing function-attr leaves its column nil"+ (let [spec {:attrs {:native-query {:fn (fn [_] (throw (ex-info "boom" {})))}}}]+ (is (= {:native_query nil}+ (#'search.ingestion/execute-all-function-attrs spec {}))))))(deftest execute-all-function-attrs-metric-reference-cycle-test(testing "a card whose metric references form a cycle yields a document without temporal keys, instead of throwing (#74954)"