Fork me on GitHub

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?


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


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


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


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


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


Thanks for the good discussion and I agree that this is a bug that needs fixing. It's in a similar vein to I've just opened a new issue:

👍 1