typhon-project / typhonql

Typhon Query Language
Eclipse Public License 2.0
4 stars 1 forks source link

[BUG] count(a.@id) returns error when entity is empty #120

Closed MarieSaphira closed 3 years ago

MarieSaphira commented 3 years ago

Describe the bug

Count() does not work if a table/collection has no entries. Tested for MariaDB and Mongo.

Query

from Entity a select count(a.@id) as cnt

Expected behavior Returning

contents(
  ["a.cnt"],
  [["0"]])

REST API

MariaDB:

(internal error)
    at $typhonql$(|main://$typhonql$|)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:659)
    at java.util.ArrayList.get(ArrayList.java:435)
    at nl.cwi.swat.typhonql.backend.rascal.AggregateIt.processStream(AggregateIt.java:24)
    at nl.cwi.swat.typhonql.backend.Runner.computeResultStream(Runner.java:58)

Mongo:

11:46:08.133 [qtp1816725203-890] ERROR engineering.swat.typhonql.server.QLRestServer - Failed to handle response
org.rascalmpl.interpreter.control_exceptions.Throw: |lib://typhonql/src/lang/typhonql/Query2Script.rsc|:67,45: CallFailed(
  |lib://typhonql/src/lang/typhonql/Query2Script.rsc|(2237,1,<67,45>,<67,46>),
tvdstorm commented 3 years ago

Confirmed that empty entities can also be aggregated upon via native SQL aggregation (c6d69562)