Skip to content
Snippets Groups Projects
Unverified Commit 1d5d9cb4 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Fix the operator list for `type/TextLike` PKs (#44569)


* Fix the operator list for `type/TextLike` PKs

* Fix the bug with using wrong operators

* Fix the bug with using wrong operators

* Update test/metabase/lib/filter_test.cljc

Co-authored-by: default avatarlbrdnk <lbrdnk@users.noreply.github.com>

* Test FKs too

* Update test/metabase/lib/filter_test.cljc

Co-authored-by: default avatarlbrdnk <lbrdnk@users.noreply.github.com>

---------

Co-authored-by: default avatarlbrdnk <lbrdnk@users.noreply.github.com>
parent 172c7cc3
No related branches found
No related tags found
No related merge requests found
......@@ -113,8 +113,10 @@
(operator-def :!=)])
(defn- key-operators-for [column]
(if (lib.types.isa/field-type? :metabase.lib.types.constants/string column)
text-operators
(condp lib.types.isa/field-type? column
:metabase.lib.types.constants/string text-operators
:metabase.lib.types.constants/string_like text-like-operators
;; default
numeric-key-operators))
(mu/defn filter-operators :- [:sequential ::lib.schema.filter/operator]
......
......@@ -372,16 +372,38 @@
:database-type "BOOLEAN",
:effective-type :type/Boolean,
:fk-target-field-id nil,
:operators [{:lib/type :operator/filter, :short :=, :display-name-variant :default}
{:lib/type :operator/filter, :short :is-null, :display-name-variant :is-empty}
{:lib/type :operator/filter, :short :not-null, :display-name-variant :not-empty}],
:id 14,
:parent-id nil,
:visibility-type :normal,
:lib/desired-column-alias "TRIAL_CONVERTED",
:display-name "Trial Converted",
:position 10,
:fingerprint {:global {:distinct-count 2, :nil% 0.0}}})))))
:fingerprint {:global {:distinct-count 2, :nil% 0.0}}}))))
(testing "should return text-like operators for text-like PKs and FKs"
(doseq [semantic-type [:type/PK :type/FK]
:let [column {:description nil,
:lib/type :metadata/column,
:base-type :type/MongoBSONID,
:semantic-type semantic-type
:table-id 7,
:name "ID",
:coercion-strategy nil,
:lib/source :source/table-defaults,
:lib/source-column-alias "ID",
:settings nil,
:lib/source-uuid "ad9a276f-3af8-4e5a-b17e-d8170273ec0a",
:nfc-path nil,
:database-type "STRING",
:effective-type :type/MongoBSONID,
:fk-target-field-id nil,
:id 14,
:parent-id nil,
:visibility-type :normal,
:lib/desired-column-alias "ID",
:display-name "ID",
:position 10}]]
(is (= [:= :!= :is-null :not-null :is-empty :not-empty]
(mapv :short (lib.filter.operator/filter-operators column)))))))
(deftest ^:parallel replace-filter-clause-test
(testing "Make sure we are able to replace a filter clause using the lib functions for manipulating filters."
......
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