diff --git a/src/metabase/lib/filter/operator.cljc b/src/metabase/lib/filter/operator.cljc index 51d56d8daeca2f1537bc84a27cc355f4cb370266..8b8ff176fca5a99890832750234ae5380ac319cd 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 7650e0bfd223a59f3714a486989d62ba7c807e25..91aff391697874e415e5ea1e9a7cf52ff5bb793d 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."