diff --git a/modules/drivers/druid/src/metabase/driver/druid/execute.clj b/modules/drivers/druid/src/metabase/driver/druid/execute.clj index d5350e9cf74dd7498cb05c491068cbfa16a9b277..8f23c4b52108543a9b45d0f7de485ee9788c1928 100644 --- a/modules/drivers/druid/src/metabase/driver/druid/execute.clj +++ b/modules/drivers/druid/src/metabase/driver/druid/execute.clj @@ -2,6 +2,7 @@ (:require [cheshire.core :as json] [clojure.math.numeric-tower :as math] [java-time :as t] + [medley.core :as m] [metabase.driver.druid.query-processor :as druid.qp] [metabase.query-processor [error-type :as qp.error-type] @@ -58,14 +59,14 @@ :results (let [results (-> results first :result)] (if (:format-rows? middleware true) results - (map #(u/update-when % :timestamp u.date/parse) results)))}) + (map #(m/update-existing % :timestamp u.date/parse) results)))}) (defmethod post-process ::druid.qp/groupBy [_ projections {:keys [middleware]} results] {:projections projections :results (if (:format-rows? middleware true) (map :event results) - (map (comp #(u/update-when % :timestamp u.date/parse) + (map (comp #(m/update-existing % :timestamp u.date/parse) :event) results))}) diff --git a/project.clj b/project.clj index 838a434a3d6e5807e3c84b671998cf3da296a3ec..2d3bba99d088d3018da61614ac770156e1edcf8f 100644 --- a/project.clj +++ b/project.clj @@ -107,7 +107,7 @@ com.sun.jdmk/jmxtools com.sun.jmx/jmxri]] [me.raynes/fs "1.4.6"] ; Filesystem tools - [medley "1.2.0"] ; lightweight lib of useful functions + [medley "1.3.0"] ; lightweight lib of useful functions [metabase/connection-pool "1.1.1"] ; simple wrapper around C3P0. JDBC connection pools [metabase/throttle "1.0.2"] ; Tools for throttling access to API endpoints and other code pathways [net.sf.cssbox/cssbox "4.12" :exclusions [org.slf4j/slf4j-api]] ; HTML / CSS rendering diff --git a/src/metabase/automagic_dashboards/core.clj b/src/metabase/automagic_dashboards/core.clj index 09095e525fd8c8a8a11735c254e202733cfaa2d3..43568f2f5d00900b22a46cc558362bf4bb1c5c92 100644 --- a/src/metabase/automagic_dashboards/core.clj +++ b/src/metabase/automagic_dashboards/core.clj @@ -562,10 +562,10 @@ (let [dimension->name (comp vector :name dimensions) metric->name (comp vector first :metric metrics)] [k (-> v - (u/update-when :map.latitude_column dimension->name) - (u/update-when :map.longitude_column dimension->name) - (u/update-when :graph.metrics metric->name) - (u/update-when :graph.dimensions dimension->name))])) + (m/update-existing :map.latitude_column dimension->name) + (m/update-existing :map.longitude_column dimension->name) + (m/update-existing :graph.metrics metric->name) + (m/update-existing :graph.dimensions dimension->name))])) (defn capitalize-first "Capitalize only the first letter in a given string." @@ -585,7 +585,7 @@ s)) form)) x) - (u/update-when :visualization #(instantate-visualization % bindings (:metrics context))))) + (m/update-existing :visualization #(instantate-visualization % bindings (:metrics context))))) (defn- valid-breakout-dimension? [{:keys [base_type engine fingerprint aggregation]}] diff --git a/src/metabase/automagic_dashboards/populate.clj b/src/metabase/automagic_dashboards/populate.clj index d87f8b08be2a384725d586f7902dfd5c81944cf1..486da3f990617b688d4edacff572bb99e940ec3a 100644 --- a/src/metabase/automagic_dashboards/populate.clj +++ b/src/metabase/automagic_dashboards/populate.clj @@ -2,13 +2,13 @@ "Create and save models that make up automagic dashboards." (:require [clojure.string :as str] [clojure.tools.logging :as log] + [medley.core :as m] [metabase.api.common :as api] [metabase.automagic-dashboards.filters :as filters] [metabase.models [card :as card] [collection :as collection]] [metabase.query-processor.util :as qp.util] - [metabase.util :as u] [metabase.util.i18n :refer [trs]] [toucan.db :as db])) @@ -323,8 +323,8 @@ (update :row + offset (if skip-titles? 0 group-heading-height)) - (u/update-in-when [:visualization_settings :text] - downsize-titles) + (m/update-existing-in [:visualization_settings :text] + downsize-titles) (assoc :parameter_mappings (when-let [card-id (:card_id %)] (for [mapping parameter-mappings] diff --git a/src/metabase/models/field.clj b/src/metabase/models/field.clj index 88bc80867fa14067e0d5e7d552306fef1fbf23da..73218e1095a9fb4e240dbac10150f6c692cb3100 100644 --- a/src/metabase/models/field.clj +++ b/src/metabase/models/field.clj @@ -129,8 +129,8 @@ "When fingerprinting decimal columns, NaN and Infinity values are possible. Serializing these values to JSON just yields a string, not a value double. This function will attempt to coerce any of those values to double objects" [fingerprint] - (u/update-in-when fingerprint [:type :type/Number] - (partial m/map-vals maybe-parse-special-numeric-values))) + (m/update-existing-in fingerprint [:type :type/Number] + (partial m/map-vals maybe-parse-special-numeric-values))) (models/add-type! :json-for-fingerprints :in i/json-in diff --git a/src/metabase/query_processor/middleware/desugar.clj b/src/metabase/query_processor/middleware/desugar.clj index 81eca22e2aa0b1dda667d0819befd69ae8dde4ba..456189cbe412650755e8abf15e8a98325251d3b6 100644 --- a/src/metabase/query_processor/middleware/desugar.clj +++ b/src/metabase/query_processor/middleware/desugar.clj @@ -1,17 +1,17 @@ (ns metabase.query-processor.middleware.desugar - (:require [metabase.mbql + (:require [medley.core :as m] + [metabase.mbql [predicates :as mbql.preds] [schema :as mbql.s] [util :as mbql.u]] - [metabase.util :as u] [schema.core :as s])) (s/defn ^:private desugar* :- mbql.s/Query [query] - (u/update-when query :query (fn [query] - (mbql.u/replace query - (filter-clause :guard mbql.preds/Filter?) - (mbql.u/desugar-filter-clause filter-clause))))) + (m/update-existing query :query (fn [query] + (mbql.u/replace query + (filter-clause :guard mbql.preds/Filter?) + (mbql.u/desugar-filter-clause filter-clause))))) (defn desugar "Middleware that uses MBQL lib functions to replace high-level 'syntactic sugar' clauses like `time-interval` and diff --git a/src/metabase/util.clj b/src/metabase/util.clj index 35079a730d0e6f74fb2164b0777d90f03c2a6f45..666e8c7d620fc107f3c5e6228189077aa33b9d47 100644 --- a/src/metabase/util.clj +++ b/src/metabase/util.clj @@ -596,22 +596,6 @@ (long (math/floor (/ (Math/log (math/abs x)) (Math/log 10)))))) -(defn update-when - "Like `clojure.core/update` but does not create a new key if it does not exist. Useful when you don't want to create - cruft." - [m k f & args] - (if (contains? m k) - (apply update m k f args) - m)) - -(defn update-in-when - "Like `clojure.core/update-in` but does not create new keys if they do not exist. Useful when you don't want to create - cruft." - [m k f & args] - (if (not= ::not-found (get-in m k ::not-found)) - (apply update-in m k f args) - m)) - (defn index-of "Return index of the first element in `coll` for which `pred` reutrns true." [pred coll] diff --git a/test/metabase/util_test.clj b/test/metabase/util_test.clj index ee0d8224347f21e8000bdf7391e4cde5276f5cf3..7e1cd4127cf20c02cb45c8e5de13c585dd98f286 100644 --- a/test/metabase/util_test.clj +++ b/test/metabase/util_test.clj @@ -192,18 +192,6 @@ 0 0 -1444 3)) -(deftest update-when-test - (testing "update-when" - (are [m expected] (= expected - (u/update-when m :bar inc)) - {:foo 2} {:foo 2} - {:foo 2 :bar 2} {:foo 2 :bar 3})) - (testing "update-in-when" - (are [m expected] (= expected - (u/update-in-when m [:foo :bar] inc)) - {:foo 2} {:foo 2} - {:foo {:bar 2}} {:foo {:bar 3}}))) - (deftest index-of-test (are [input expected] (= expected (u/index-of pos? input))