Skip to content
Snippets Groups Projects
Commit 248d0f5e authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add a predicate function for testing if the metadata for a field is a valid combination.

parent a70671e7
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,19 @@
:info ; Non-numerical value that is not meant to be used
:sensitive}) ; A Fields that should *never* be shown *anywhere*
(defn valid-metadata?
"Predicate function that checks if the set of metadata types for a field are sensible."
[base-type field-type special-type]
(and (contains? base-types base-type)
(contains? field-types field-type)
(or (nil? special-type)
(contains? special-types special-type))
;; this verifies that we have a numeric base-type when trying to use the unix timestamp transform (#824)
(or (nil? special-type)
(not (contains? #{:timestamp_milliseconds :timestamp_seconds} special-type))
(contains? #{:BigIntegerField :DecimalField :FloatField :IntegerField} base-type))))
(i/defentity Field :metabase_field)
(defn- pre-insert [field]
......
......@@ -6,6 +6,18 @@
[metabase.test.data :refer :all]))
;; valid-metadata?
(expect false (valid-metadata? nil nil nil))
(expect false (valid-metadata? :IntegerField nil nil))
(expect true (valid-metadata? :IntegerField :metric nil))
(expect false (valid-metadata? :foo :metric nil))
(expect false (valid-metadata? :IntegerField :foo nil))
(expect true (valid-metadata? :IntegerField :metric :timestamp_seconds))
(expect true (valid-metadata? :IntegerField :metric :timestamp_milliseconds))
(expect false (valid-metadata? :DateTimeField :metric :timestamp_seconds))
(expect false (valid-metadata? :DateTimeField :metric :timestamp_milliseconds))
;; field-should-have-field-values?
;; sensitive fields should always be excluded
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment