vaticle / typedb

TypeDB: the polymorphic database powered by types
https://typedb.com
Mozilla Public License 2.0
3.72k stars 338 forks source link

Fix fetch sub-query aggregation null pointer #6961

Closed flyingsilverfin closed 6 months ago

flyingsilverfin commented 6 months ago

Usage and product changes

We fix a bug where a Fetch query with a Get-Aggregate subquery that returned an empty (ie. undefined) answer throw a null pointer exception.

For example this used to error if 'Alice' doesn't have any salaries in the database, since a 'sum' is undefined for 0 entries.

match
$x isa person, has name $n; $n == "Alice";
fetch
$n as "name";
total-salary: {
  match $x has salary $s;
  get $s; 
  sum $s;
};

We now return the following JSON structure

[
  {
    "name": {"value": "Alice",  "type":  {"label": "name", "root": "attribute", "value_type": "string"}},
    "total-salary": null
  }
]

Implementation

vaticle-bot commented 6 months ago

PR Review Checklist

Do not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed.


Trivial Change

Code

Architecture