Skip to content
Snippets Groups Projects
Unverified Commit 86f405a0 authored by Braden Shepherdson's avatar Braden Shepherdson Committed by GitHub
Browse files

[MLv2] Allow any type of arguments to :concat expressions (#34157)

The QP supports this - it appears that every type can be `concat`-ed and
it will coerce the values to some kind of string - numbers, dates,
booleans, etc.
parent bca9d35f
No related branches found
No related tags found
No related merge requests found
......@@ -27,4 +27,4 @@
[:length [:? [:schema [:ref ::expression/integer]]]])
(mbql-clause/define-catn-mbql-clause :concat :- :type/Text
[:args [:repeat {:min 2} [:schema [:ref ::expression/string]]]])
[:args [:repeat {:min 2} [:schema [:ref ::expression/expression]]]])
......@@ -298,3 +298,32 @@
(is (= ["ID" "Subtotal" "Total" "Tax" "Discount" "Quantity" "Created At" "Product ID" "User ID" "Unit price"]
(map (partial lib/display-name query)
(lib/returned-columns query)))))))
(deftest ^:parallel mixed-type-concat-expression-test
(testing "#34150"
(testing "various pemutations on venues"
(let [query (reduce (fn [query [label expr]]
(lib/expression query -1 label expr))
lib.tu/venues-query
[["name+price" (lib/concat (meta/field-metadata :venues :name)
(meta/field-metadata :venues :price))]
["$price" (lib/concat "$" (meta/field-metadata :venues :price))]
["latXlong" (lib/concat (meta/field-metadata :venues :latitude)
" X "
(meta/field-metadata :venues :longitude))]])]
(is (=? [{:name "name+price"}
{:name "$price"}
{:name "latXlong"}]
(->> (lib/visible-columns query)
(filter (comp #{:source/expressions} :lib/source)))))))
(testing "dates"
(let [query (-> (lib/query meta/metadata-provider (meta/table-metadata :orders))
(lib/expression "description"
(lib/concat (meta/field-metadata :orders :total)
" on "
(meta/field-metadata :orders :quantity)
" as of "
(meta/field-metadata :orders :created-at))))]
(is (=? [{:name "description"}]
(->> (lib/visible-columns query)
(filter (comp #{:source/expressions} :lib/source)))))))))
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