We initialize the database with entities that have :age attributes whose values are a mix of strings, number and keywords. Then we query entities based on the :age attribute being the string "37". This produces an exception, because the comparator used when running the query cannot compare strings and numbers.
What is the expected behaviour?
The provided unit test should successfully pass, that is the result of the query should be #{[2 "Petr"]}.
All we need is a comparator that compares different types in a well-defined way. How it orders them is not so important.
How can the behaviour be reproduced?
The following unit test (added to the source of datahike.test.query-test) produces an exception:
What version of Datahike are you using?
0.6.1566
What version of Java are you using?
openjdk 20.0.1 2023-04-18
What operating system are you using?
Ubuntu 22
What database EDN configuration are you using?
Describe the bug
The Clojure
compare
function cannot compare values of very different types, such as strings and numbers. Here is a small unit test to illustrate that:We initialize the database with entities that have
:age
attributes whose values are a mix of strings, number and keywords. Then we query entities based on the:age
attribute being the string"37"
. This produces an exception, because the comparator used when running the query cannot compare strings and numbers.What is the expected behaviour?
The provided unit test should successfully pass, that is the result of the query should be
#{[2 "Petr"]}
.All we need is a comparator that compares different types in a well-defined way. How it orders them is not so important.
How can the behaviour be reproduced?
The following unit test (added to the source of
datahike.test.query-test
) produces an exception:The exception and stacktrace is: