Fork me on GitHub
#xtdb
<
2022-06-23
>
tatut07:06:10

user> (xt/submit-tx node [[::xt/put {:xt/id "test1" :foo 1}]
                          [::xt/put {:xt/id "test2" :foo nil}]
                          [::xt/put {:xt/id "test3" :foo {:bar 42}}]])

;; order by will crash if result has maps
user> (xt/q (xt/db node) '{:find [e v] :where [[e :foo v]] :order-by [[v :asc]]})
Execution error (ClassCastException) at xtdb.query$order_by_comparator$reify__56976/compare (query.clj:1682).
class clojure.lang.PersistentArrayMap cannot be cast to class java.lang.Comparable (clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.lang.Comparable is in module java.base of loader 'bootstrap')

;; nil order works
user> (xt/q (xt/db node) '{:find [e v] :where [[e :foo v]] :order-by [[v :asc]] :in [[e ...]]} ["test1" "test2"])
[["test2" nil] ["test1" 1]]
I know clojure maps aren’t sortable, but should the query throw or return something?

tatut07:06:35

I guess in most application purposes you can know (if not guarantee) that the result will not have maps

tatut07:06:10

but just noticed that in my XTDB inspector use case which doesn’t know anything about the values, the attr values page will crash… I need to move the sorting to after the query and do it by string representations

Hukka09:06:10

Hm, but it can cause nasty bugs when there is no schema and nothing can prevent another place from putting a new document that breaks old code

Hukka09:06:48

That is, I think that if the query is valid, it should never throw (unless the engine is in a broken state or something), and an invalid query should always fail

tatut09:06:20

indeed, without a schema you need to be very careful with this

refset10:06:52

Thanks for the good discussion and I agree that this is a bug that needs fixing. It's in a similar vein to https://github.com/xtdb/xtdb/issues/1710. I've just opened a new issue: https://github.com/xtdb/xtdb/issues/1775

👍 1