The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
[QP] Allow one-sided `:number/between` parameter values (#65987)
Braden Shepherdson19ba6a165a95
diff --git a/src/metabase/lib/schema/parameter.cljc b/src/metabase/lib/schema/parameter.cljcindex 65391cd9ac8..17574a60552 100644--- a/src/metabase/lib/schema/parameter.cljc+++ b/src/metabase/lib/schema/parameter.cljc@@ -130,10 +130,10 @@;; "operator" parameter types.:number/!= {:type :numeric, :operator :variadic, :allowed-for #{:number/!=}}- :number/<= {:type :numeric, :operator :unary, :allowed-for #{:number/<=}}+ :number/<= {:type :numeric, :operator :unary, :allowed-for #{:number/<= :number/between}}:number/= {:type :numeric, :operator :variadic, :allowed-for #{:number/= :number :id :category:location/zip_code}}- :number/>= {:type :numeric, :operator :unary, :allowed-for #{:number/>=}}+ :number/>= {:type :numeric, :operator :unary, :allowed-for #{:number/>= :number/between}}:number/between {:type :numeric, :operator :binary, :allowed-for #{:number/between}}:string/!= {:type :string, :operator :variadic, :allowed-for #{:string/!=}}:string/= {:type :string, :operator :variadic, :allowed-for #{:string/= :text :id :categorydiff --git a/test/metabase/query_processor/card_test.clj b/test/metabase/query_processor/card_test.cljindex e40db80d14f..f6f99979dd8 100644--- a/test/metabase/query_processor/card_test.clj+++ b/test/metabase/query_processor/card_test.clj@@ -52,6 +52,19 @@:widget-type :date/all-options}}:query "SELECT count(*)\nFROM CHECKINS\nWHERE {{date}}"}})+(defn field-filter-query-between+ "A query with a Field Filter 'between' parameter"+ []+ {:database (mt/id)+ :type :native+ :native {:template-tags {"quantities" {:id "_QUANTITIES_"+ :name "quantities"+ :display-name "Quantity Range"+ :type :dimension+ :dimension [:field (mt/id :orders :quantity) nil]+ :widget-type :number/between}}+ :query "SELECT count(*)\nFROM ORDERS\n[[WHERE {{quantities}}]]"}})+(defn non-field-filter-query"A query with a parameter that is not a Field Filter"[]@@ -170,6 +183,45 @@:type :date/single:value "2014-05-07"}]})))))))+(deftest ^:parallel validate-card-parameters-test-5+ (mt/with-temp [:model/Card {card-id :id} {:dataset_query (field-filter-query-between)}]+ (testing ":number/between filters should work (#65714)"+ (testing "if optional and the parameter is nil"+ (is (= [18760]+ (mt/first-row (mt/user-http-request :rasta :post (format "card/%d/query" card-id)+ {:parameters [{:id "_QUANTITIES_"+ :name "quantities"+ :type :number/between+ :value nil}]})))))+ (testing "if only the maximum is set"+ (is (= [15416]+ (mt/first-row (mt/user-http-request :rasta :post (format "card/%d/query" card-id)+ {:parameters [{:id "_QUANTITIES_"+ :name "quantities"+ :type :number/between+ :value [nil 5]}]})))))+ (testing "if only the minimum is set"+ (is (= [3344]+ (mt/first-row (mt/user-http-request :rasta :post (format "card/%d/query" card-id)+ {:parameters [{:id "_QUANTITIES_"+ :name "quantities"+ :type :number/between+ :value [6 nil]}]})))))+ (testing "if both ends are set"+ (is (= [7543]+ (mt/first-row (mt/user-http-request :rasta :post (format "card/%d/query" card-id)+ {:parameters [{:id "_QUANTITIES_"+ :name "quantities"+ :type :number/between+ :value [4 8]}]}))))+ (testing "to the same value"+ (is (= [2207]+ (mt/first-row (mt/user-http-request :rasta :post (format "card/%d/query" card-id)+ {:parameters [{:id "_QUANTITIES_"+ :name "quantities"+ :type :number/between+ :value [5 5]}]})))))))))+(deftest ^:parallel bad-viz-settings-should-still-work-test(testing "We should still be able to run a query that has Card bad viz settings referencing a column not in the query (#34950)"(mt/with-temp [:model/Card {card-id :id} {:dataset_query