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
Default to base-type when it differs from effective type (#67486)
Eric Normandc8c18494ace2
diff --git a/src/metabase/query_processor/middleware/wrap_value_literals.clj b/src/metabase/query_processor/middleware/wrap_value_literals.cljindex 2327b7060a1..5faf6a191b5 100644--- a/src/metabase/query_processor/middleware/wrap_value_literals.clj+++ b/src/metabase/query_processor/middleware/wrap_value_literals.clj@@ -44,8 +44,9 @@(merge(when (lib.util/clause-of-type? clause :field)(type-info-from-col (lib.walk/apply-f-for-stage-at-path lib/metadata query path clause)))- (let [expr-type (lib.walk/apply-f-for-stage-at-path lib/type-of query path clause)]- {:base-type expr-type+ (let [expr-type (lib.walk/apply-f-for-stage-at-path lib/type-of query path clause)+ [_ {:keys [base-type]}] clause]+ {:base-type (or base-type expr-type):effective-type expr-type})));; TODO -- parsing the temporal string literals should be moved into `auto-parse-filter-values`, it's really a@@ -228,6 +229,15 @@(defn- wrap-value-literals-in-clause[query path clause](lib.util.match/match-lite clause+ ;; two literals+ [(tag :guard #{:= :!= :< :> :<= :>=}) opts (x :guard raw-value?) (y :guard raw-value?)]+ (let [x-type (lib.schema.expression/type-of x)+ y-type (lib.schema.expression/type-of y)]+ [tag opts+ (add-type-info x {:base-type x-type :effective-type x-type})+ (add-type-info y {:base-type y-type :effective-type y-type})])++ ;; field and literal[(tag :guard #{:= :!= :< :> :<= :>=}) opts field (x :guard raw-value?)][tag opts field (add-type-info x (*type-info* query path field))]diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.cljindex 2014ec1cc5c..2280abe776d 100644--- a/test/metabase/driver/postgres_test.clj+++ b/test/metabase/driver/postgres_test.clj@@ -1049,6 +1049,25 @@(is (=? {:data {:rows [["Rasta" "good bird" "sad bird" "toucan"]]}}(qp/process-query query))))))))))))))+(deftest filtering-on-enum-from-source-bad-effective-type-test+ (mt/test-driver+ :postgres+ (do-with-enums-db!+ (fn [enums-db]+ (mt/with-db enums-db+ (testing "filtering on enum column should cast properly (#67440)"+ (let [mp (-> (mt/metadata-provider)+ (lib.tu/merged-mock-metadata-provider+ {:fields [{:id (mt/id :birds :status)+ :effective-type :type/Text}]}))+ query (as-> (lib/query mp (lib.metadata/table mp (mt/id :birds))) $q+ (lib/filter $q (lib/= (m/find-first (comp #{"status"} :name)+ (lib/filterable-columns $q))+ "good bird")))+ sql (:query (qp.compile/compile query))]+ (is (re-find #"CAST" sql))+ (is (some? (mt/rows (qp/process-query query)))))))))))+;; API tests are in [[metabase.actions-rest.api-test]](deftest ^:parallel actions-maybe-parse-sql-violate-not-null-constraint-test(testing "violate not null constraint"diff --git a/test/metabase/query_processor/filter_test.clj b/test/metabase/query_processor/filter_test.cljindex ff4e56e8594..f58a48b6f24 100644--- a/test/metabase/query_processor/filter_test.clj+++ b/test/metabase/query_processor/filter_test.clj@@ -148,6 +148,18 @@{:filter [:!= false false]:order-by [[:asc $id]]}))))))))+(deftest ^:parallel comparison-test-8+ (mt/test-drivers (mt/normal-drivers)+ (mt/dataset places-cam-likes+ (testing "Can we use != with literals on both sides, 0 != 0"+ (is (= []+ (mt/formatted-rows+ [int str ->bool]+ :format-nil-values+ (mt/run-mbql-query places+ {:filter [:!= 0 0]+ :order-by [[:asc $id]]}))))))))+(deftest ^:parallel between-test(mt/test-drivers (mt/normal-drivers)(testing ":between filter, single subclause (neither :and nor :or)"