From 1d5d9cb4303d19435f5c17b4407dd10a8b71b67f Mon Sep 17 00:00:00 2001 From: Alexander Polyankin <alexander.polyankin@metabase.com> Date: Mon, 24 Jun 2024 12:00:09 -0400 Subject: [PATCH] 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: lbrdnk <lbrdnk@users.noreply.github.com> * Test FKs too * Update test/metabase/lib/filter_test.cljc Co-authored-by: lbrdnk <lbrdnk@users.noreply.github.com> --------- Co-authored-by: lbrdnk <lbrdnk@users.noreply.github.com> --- src/metabase/lib/filter/operator.cljc | 6 ++++-- test/metabase/lib/filter_test.cljc | 30 +++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/metabase/lib/filter/operator.cljc b/src/metabase/lib/filter/operator.cljc index 51d56d8daec..8b8ff176fca 100644 --- a/src/metabase/lib/filter/operator.cljc +++ b/src/metabase/lib/filter/operator.cljc @@ -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] diff --git a/test/metabase/lib/filter_test.cljc b/test/metabase/lib/filter_test.cljc index 7650e0bfd22..91aff391697 100644 --- a/test/metabase/lib/filter_test.cljc +++ b/test/metabase/lib/filter_test.cljc @@ -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." -- GitLab