Skip to content
Snippets Groups Projects
Unverified Commit 8c7d0bcd authored by metamben's avatar metamben Committed by GitHub
Browse files

Use the original string if humanization results in a blank string (#27161)

This is to enable _ as field name.
parent e432bb9c
No related branches found
No related tags found
No related merge requests found
......@@ -452,3 +452,20 @@
[:= $list_field "value_lf_a"]]
:aggregation [[:count]]
:breakout [$coll.metas.group_field]}))))))))
;; Make sure that simple `_` columns can be queried (#4647)
(tx/defdataset underscore-column
[["bird_species"
[{:field-name "name", :base-type :type/Text}
{:field-name "_", :base-type :type/Text}]
[["House Finch" "sunflower seeds, ants, nettle, dandelion"]
["Mourning Dove" "millet seeds, breadcrumbs, ice cream"]]]])
(deftest underscore-filter-test
(testing "Simple `_` columns should be possible to query (#4647)"
(mt/test-driver :mongo
(mt/dataset underscore-column
(is (= [[1 "House Finch" "sunflower seeds, ants, nettle, dandelion"]]
(mt/rows
(mt/run-mbql-query bird_species
{:filter [:contains $bird_species._ "nett"]}))))))))
......@@ -51,9 +51,12 @@
([_ ^String s]
;; explode on hyphens, underscores, and spaces
(when (seq s)
(str/join " " (for [part (str/split s #"[-_\s]+")
:when (not (str/blank? part))]
(capitalize-word part))))))
(let [humanized (str/join " " (for [part (str/split s #"[-_\s]+")
:when (not (str/blank? part))]
(capitalize-word part)))]
(if (str/blank? humanized)
s
humanized)))))
;; actual advanced method has been excised. this one just calls out to simple
(defmethod name->human-readable-name :advanced
......
......@@ -9,8 +9,8 @@
(deftest simple-humanization-test
(doseq [[input expected] {nil nil
"" nil
"_" ""
"-" ""
"_" "_"
"-" "-"
"_id" "ID"
"uid" "UID"
"uuid" "UUID"
......
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