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
Remove test-only hierarchy from production code (#82394)
Chris Truterc829aa7c295c
diff --git a/src/metabase/lib/equality.cljc b/src/metabase/lib/equality.cljcindex 6ad0854f5e4..9bef6dc5eb1 100644--- a/src/metabase/lib/equality.cljc+++ b/src/metabase/lib/equality.cljc@@ -29,7 +29,7 @@are [[clojure.core/=]] if you ignore all qualified keyword keys besides `:lib/type`."{:arglists '([x y])};; two things with different dispatch values (for maps, the `:lib/type` key; for MBQL clauses, the tag, and for- ;; everything else, the `:dispatch-type/*` key) can't be equal.+ ;; everything else, a `:dispatch-type/...` keyword) can't be equal.(fn [x y](let [x-dispatch-value (lib.dispatch/dispatch-value x)y-dispatch-value (lib.dispatch/dispatch-value y)]diff --git a/src/metabase/lib/schema/expression.cljc b/src/metabase/lib/schema/expression.cljcindex b6e26235033..4841126feac 100644--- a/src/metabase/lib/schema/expression.cljc+++ b/src/metabase/lib/schema/expression.cljc@@ -24,11 +24,11 @@always have type info!"{:arglists '([expr])}(fn [x]- ;; For the fallback case: use the actual type/class name as the dispatch type rather than `:type/*`. This is so we+ ;; Dispatch on the concrete class when [[lib.dispatch/dispatch-value]] can't classify `x`. This is so we;; can implement support for some platform-specific classes like `BigDecimal` or `java.time.OffsetDateTime`, for;; use inside QP code or whatever. In the future maybe we can add support for JS-specific stuff too.(let [dispatch-value (lib.dispatch/dispatch-value x)]- (if (= dispatch-value :dispatch-type/*)+ (if (= dispatch-value :dispatch-type/unknown)(type x)dispatch-value))):hierarchy lib.hierarchy/hierarchy)diff --git a/src/metabase/util.cljc b/src/metabase/util.cljcindex b8f40ad248f..cb84a081233 100644--- a/src/metabase/util.cljc+++ b/src/metabase/util.cljc@@ -915,24 +915,6 @@#?(:clj (defn- regexp? [x](instance? java.util.regex.Pattern x)))-(def dispatch-type-hierarchy- "Hierarchy relating the keywords returned by [[dispatch-type-keyword]]. A multimethod dispatching- on [[dispatch-type-keyword]] must pass `:hierarchy #'dispatch-type-hierarchy` for `:dispatch-type/*` to work as a- fallback method; Clojure's global hierarchy does not relate these keywords."- (-> (make-hierarchy)- (derive :dispatch-type/nil :dispatch-type/*)- (derive :dispatch-type/boolean :dispatch-type/*)- (derive :dispatch-type/string :dispatch-type/*)- (derive :dispatch-type/keyword :dispatch-type/*)- (derive :dispatch-type/number :dispatch-type/*)- (derive :dispatch-type/integer :dispatch-type/number)- (derive :dispatch-type/map :dispatch-type/*)- (derive :dispatch-type/sequential :dispatch-type/*)- (derive :dispatch-type/set :dispatch-type/*)- (derive :dispatch-type/symbol :dispatch-type/*)- (derive :dispatch-type/fn :dispatch-type/*)- (derive :dispatch-type/regex :dispatch-type/*)))-(defn dispatch-type-keyword"In Cljs `(type 1) is `js/Number`, but `(isa? 1 js/Number)` isn't truthy, so dispatching off of [[clojure.core/type]]doesn't really work the way we'd want. Also, type names are different between Clojure and ClojureScript.@@ -940,13 +922,9 @@This function exists as a workaround: use it as a multimethod dispatch function for Cljc multimethods that wouldhave dispatched on `type` if they were written in pure Clojure.- Returns `:dispatch-type/*` if there is no mapping for the current type, but you can add more as needed if- appropriate. All type keywords returned by this method derive from `:dispatch-type/*`- in [[dispatch-type-hierarchy]], meaning you can write an implementation for `:dispatch-type/*` and use it as a- fallback method.+ Returns `:dispatch-type/unknown` for a type it does not classify.- Think of `:dispatch-type/*` as similar to how you would use `Object` if you were dispatching- off of `type` in pure Clojure."+ There is no hierarchy relating these keywords, so a catch-all method has to be `:default`."[x](cond(nil? x) :dispatch-type/nil@@ -962,7 +940,7 @@(fn? x) :dispatch-type/fn(regexp? x) :dispatch-type/regex;; we should add more mappings here as needed- :else :dispatch-type/*))+ :else :dispatch-type/unknown))(defn assoc-dissoc"Called like `(assoc m k v)`, this does [[assoc]] if `(some? v)`, and [[dissoc]] if not.diff --git a/test/metabase/test_runner/assert_exprs/approximately_equal.cljs b/test/metabase/test_runner/assert_exprs/approximately_equal.cljsindex 7fdb92c7b92..b491f31df9a 100644--- a/test/metabase/test_runner/assert_exprs/approximately_equal.cljs+++ b/test/metabase/test_runner/assert_exprs/approximately_equal.cljs@@ -7,15 +7,17 @@"Multimethod to use to diff two things with `=?`."{:arglists '([expected actual])}(fn [expected actual]- [(u/dispatch-type-keyword expected) (u/dispatch-type-keyword actual)])- :hierarchy #'u/dispatch-type-hierarchy)+ [(u/dispatch-type-keyword expected) (u/dispatch-type-keyword actual)]));;;; Default method impls(defmethod =?-diff :default[expected actual]- (when-not (= expected actual)- (list 'not= expected actual)))+ (if (fn? expected)+ (when-not (expected actual)+ (list 'not (list expected actual)))+ (when-not (= expected actual)+ (list 'not= expected actual))))(defmethod =?-diff [:dispatch-type/regex :dispatch-type/string][expected-regex s]@@ -28,11 +30,6 @@(when-not (= (str expected) (str actual))(list 'not= (list 'str expected) (list 'str actual))))-(defmethod =?-diff [:dispatch-type/fn :dispatch-type/*]- [pred actual]- (when-not (pred actual)- (list 'not (list pred actual))))-(defmethod =?-diff [:dispatch-type/sequential :dispatch-type/sequential][expected actual](let [same-size? (= (count expected)diff --git a/test/metabase/util_test.cljc b/test/metabase/util_test.cljcindex 66bed2898dc..e79eb3b8a77 100644--- a/test/metabase/util_test.cljc+++ b/test/metabase/util_test.cljc@@ -444,21 +444,7 @@'str :dispatch-type/symbol#"\d+" :dispatch-type/regexstr :dispatch-type/fn- #?(:clj (Object.) :cljs (js/Object.)) :dispatch-type/*)- (testing "All type keywords should derive from :dispatch-type/*"- (are [x] (isa? u/dispatch-type-hierarchy (u/dispatch-type-keyword x) :dispatch-type/*)- :dispatch-type/nil- :dispatch-type/string- :dispatch-type/keyword- :dispatch-type/integer- :dispatch-type/number- :dispatch-type/map- :dispatch-type/sequential- :dispatch-type/set- :dispatch-type/symbol- :dispatch-type/regex- :dispatch-type/fn- :dispatch-type/*)))+ #?(:clj (Object.) :cljs (js/Object.)) :dispatch-type/unknown))(deftest ^:parallel assoc-dissoc-test(testing `lib.options/with-option-value