Ported from frontend/src/metabase-lib/types/utils/isa.js | (ns metabase.lib.types.isa (:refer-clojure :exclude [isa? any? boolean? number? string? integer?]) (:require [medley.core :as m] [metabase.lib.types.constants :as lib.types.constants] [metabase.lib.util :as lib.util] [metabase.types])) |
(comment metabase.types/keep-me) | |
Decide if | (defn ^:export isa? [{:keys [effective-type base-type semantic-type] :as _column} type-kw] (or (clojure.core/isa? (or effective-type base-type) type-kw) (clojure.core/isa? semantic-type type-kw))) |
Returns if | (defn ^:export field-type? [category column] (let [type-definition (lib.types.constants/type-hierarchies category) column (cond-> column (and (map? column) (not (:effective-type column))) (assoc :effective-type (:base-type column)))] (cond (nil? column) false ;; check field types (some (fn [[type-type types]] (and (#{:effective-type :semantic-type} type-type) (some #(clojure.core/isa? (type-type column) %) types))) type-definition) true ;; recursively check if it's not an excluded type (some #(field-type? % column) (:exclude type-definition)) false ;; recursively check if it's an included type (some #(field-type? % column) (:include type-definition)) true :else false))) |
Return the category | (defn ^:export field-type [column] (m/find-first #(field-type? % column) [::lib.types.constants/temporal ::lib.types.constants/location ::lib.types.constants/coordinate ::lib.types.constants/foreign_key ::lib.types.constants/primary_key ::lib.types.constants/boolean ::lib.types.constants/string ::lib.types.constants/string_like ::lib.types.constants/number])) |
Is | (defn ^:export temporal? [column] (field-type? ::lib.types.constants/temporal column)) |
Is | (defn ^:export numeric? [column] (field-type? ::lib.types.constants/number column)) |
Is | (defn ^:export boolean? [column] (field-type? ::lib.types.constants/boolean column)) |
Is | (defn ^:export string? [column] (field-type? ::lib.types.constants/string column)) |
Is | (defn ^:export string-like? [column] (field-type? ::lib.types.constants/string_like column)) |
Is | (defn ^:export string-or-string-like? [column] (or (string? column) (string-like? column))) |
Is | (defn ^:export summable? [column] (field-type? ::lib.types.constants/summable column)) |
Is | (defn ^:export scope? [column] (field-type? ::lib.types.constants/scope column)) |
Is | (defn ^:export category? [column] (field-type? ::lib.types.constants/category column)) |
Is | (defn ^:export location? [column] (field-type? ::lib.types.constants/location column)) |
Is | (defn ^:export description? [column] (clojure.core/isa? (:semantic-type column) :type/Description)) |
Is | (defn ^:export dimension? [column] (and column (not= (:lib/source column) :source/aggregations) (not (description? column)))) |
Is | (defn ^:export metric? [column] (and (not= (:lib/source column) :source/breakouts) (summable? column))) |
Is | (defn ^:export foreign-key? [column] (clojure.core/isa? (:semantic-type column) :type/FK)) |
Is | (defn ^:export primary-key? [column] (clojure.core/isa? (:semantic-type column) :type/PK)) |
Is | (defn ^:export entity-name? [column] (clojure.core/isa? (:semantic-type column) :type/Name)) |
Is | (defn ^:export title? [column] (clojure.core/isa? (:semantic-type column) :type/Title)) |
Is | (defn ^:export json? [column] (clojure.core/isa? (:semantic-type column) :type/SerializedJSON)) |
Is | (defn ^:export xml? [column] (clojure.core/isa? (:semantic-type column) :type/XML)) |
Is | (defn ^:export structured? [column] (clojure.core/isa? (:semantic-type column) :type/Structured)) |
Is this | (defn ^:export any? [_column] true) |
Is | (defn ^:export numeric-base-type? [column] (clojure.core/isa? (:effective-type column) :type/Number)) |
Is | (defn ^:export date-or-datetime? [column] (or (clojure.core/isa? (:effective-type column) :type/Date) (clojure.core/isa? (:effective-type column) :type/DateTime))) |
Is | (defn ^:export date-without-time? [column] (clojure.core/isa? (:effective-type column) :type/Date)) |
Is | (defn ^:export creation-timestamp? [column] (clojure.core/isa? (:semantic-type column) :type/CreationTimestamp)) |
Is | (defn ^:export creation-date? [column] (clojure.core/isa? (:semantic-type column) :type/CreationDate)) |
Is | (defn ^:export creation-time? [column] (clojure.core/isa? (:semantic-type column) :type/CreationTime)) |
Is ZipCode, ID, etc derive from Number but should not be formatted as numbers | (defn ^:export number? [column] (and (numeric-base-type? column) (let [semantic-type (:semantic-type column)] (or (nil? semantic-type) ;; this is a precaution, :type/Number is not a semantic type (clojure.core/isa? semantic-type :type/Number))))) |
Is | (defn ^:export integer? [column] (field-type? ::lib.types.constants/integer column)) |
Is | (defn ^:export time? [column] (clojure.core/isa? (:effective-type column) :type/Time)) |
Is | (defn ^:export address? [column] (clojure.core/isa? (:semantic-type column) :type/Address)) |
Is | (defn ^:export city? [column] (clojure.core/isa? (:semantic-type column) :type/City)) |
Is | (defn ^:export state? [column] (clojure.core/isa? (:semantic-type column) :type/State)) |
Is | (defn ^:export zip-code? [column] (clojure.core/isa? (:semantic-type column) :type/ZipCode)) |
Is | (defn ^:export country? [column] (clojure.core/isa? (:semantic-type column) :type/Country)) |
Is | (defn ^:export coordinate? [column] (clojure.core/isa? (:semantic-type column) :type/Coordinate)) |
Is | (defn ^:export latitude? [column] (clojure.core/isa? (:semantic-type column) :type/Latitude)) |
Is | (defn ^:export longitude? [column] (clojure.core/isa? (:semantic-type column) :type/Longitude)) |
Is | (defn ^:export currency? [column] (clojure.core/isa? (:semantic-type column) :type/Currency)) |
Is | (defn ^:export comment? [column] (clojure.core/isa? (:semantic-type column) :type/Comment)) |
Is | (defn ^:export id? [column] (or (clojure.core/isa? (:semantic-type column) :type/FK) (clojure.core/isa? (:semantic-type column) :type/PK))) |
Is | (defn ^:export URL? [column] (clojure.core/isa? (:semantic-type column) :type/URL)) |
Is | (defn ^:export email? [column] (clojure.core/isa? (:semantic-type column) :type/Email)) |
Is | (defn ^:export avatar-URL? [column] (clojure.core/isa? (:semantic-type column) :type/AvatarURL)) |
Is | (defn ^:export image-URL? [column] (clojure.core/isa? (:semantic-type column) :type/ImageURL)) |
Does the collection | (defn ^:export has-latitude-and-longitude? [columns] (every? #(some % columns) [latitude? longitude?])) |
Return a prdicate for checking if a column is a primary key. | (defn ^:export primary-key-pred [table-id] (fn primary-key-pred-for-table-id [column] (let [pk? (primary-key? column)] ;; comment from isa.js: ;; > FIXME: columns of nested questions at this moment miss table_id value ;; > which makes it impossible to match them with their tables that are nested cards (if (lib.util/legacy-string-table-id->card-id table-id) pk? (and pk? (= (:table-id column) table-id)))))) |
Is this column one that we should show a search widget for (to search its values) in the QB filter UI? If so, we can
give it a TODO -- This stuff should probably use the constants in [[metabase.lib.types.constants]], however this logic isn't
supposed to include things with semantic type = Category which the | (defn searchable? [{:keys [base-type effective-type]}] ;; For the time being we will consider something to be "searchable" if it's a text Field since the `starts-with` ;; filter that powers the search queries (see [[metabase.api.field/search-values]]) doesn't work on anything else (let [column-type (or effective-type base-type)] (or (clojure.core/isa? column-type :type/Text) (clojure.core/isa? column-type :type/TextLike)))) |
Given two CLJS That's the case if both are from the same family (strings, numbers, temporal) or if the | (defn valid-filter-for? [src-column dst-column] (or (and (string? src-column) (string? dst-column)) (and (number? src-column) (number? dst-column)) (and (temporal? src-column) (temporal? dst-column)) (clojure.core/isa? (:base-type src-column) (:base-type dst-column)))) |