I was writing a query with an aggretate function wher I wanted to provide an optional parameter to further limit the query results by.
The query did not return the expected results and I'm lead to believe that this might be a bug in Asami.
Steps to reproduce:
- Create an in-memory database.
- Add the following data:
(d/transact conn
[{:name "Carl" :city "Berlin"}
{:name "Tom" :city "Bern"}
{:name "Claire" :city "Paris"}
{:name "Sofia" :city "Berlin"}])
- Query how many people live in each city
(d/q '[:find ?city (count ?name)
:where (and
[?a :city ?city]
[?a :name ?name])]
db)
- Result is as expected: `=> (("Berlin" 2) ("Bern" 1) ("Paris" 1))``
- Query but with an optional parameter to limit by city:
(d/q '[:find ?city (count ?name)
:in $ ?only-city
:where (and
[?a :city ?city]
(or [(empty? ?only-city)]
[?a :city ?only-city])
[?a :name ?name])]
db
"Berlin")
- Instead of
=> (("Berlin" 2)), the result is an error:
Execution error (ExceptionInfo) at asami.query/eval6873$filter-join$fn (query.cljc:240).
Unknown variable in filter: ?only-city
Using nil? instead of empty? in the filter just results in the same result as the first query.
Even if I make the parameter mandatory by removing the filter, the result is not the expected 2 for "Berlin":
(d/q '[:find (count ?name) .
:in $ ?only-city
:where (and
[?a :city ?only-city]
[?a :name ?name])]
db
"Berlin")
=> 4
Do I not understand how the aggregate queries are supposed to work, or is this actually a bug in Asami?
I was writing a query with an aggretate function wher I wanted to provide an optional parameter to further limit the query results by.
The query did not return the expected results and I'm lead to believe that this might be a bug in Asami.
Steps to reproduce:
=> (("Berlin" 2)), the result is an error:Using
nil?instead ofempty?in the filter just results in the same result as the first query.Even if I make the parameter mandatory by removing the filter, the result is not the expected
2for"Berlin":Do I not understand how the aggregate queries are supposed to work, or is this actually a bug in Asami?