fluree / db

Fluree database library
https://fluree.github.io/db/
Other
330 stars 21 forks source link

Feature/subquery #794

Open bplatz opened 1 month ago

bplatz commented 1 month ago

Adds new subquery capability. Supports multiple parallel subqueries, or nested subqueries.

A new solution-value interface is for select statements to pass formatted solutions for :select clauses instead of final projections as a normal select clause does.

e.g. in EDN - this has a subquery that calculates the average of all favNums, then in the parent query filters to only include users who have a favNum > than the average:

{:context  {:ex "http://example.org/ns/"}
 :select   '[?iri ?favNums]
 :where    ['{:id         ?iri
              :ex/favNums ?favNums}
            [:filter "(> ?favNums ?avgFavNum)"]
            [:query {:where  '{:ex/favNums ?favN}
                     :select '[(as (avg ?favN) ?avgFavNum)]}]]
 :order-by '[?iri ?favNums]}

Tests/examples in: fluree.db.query.subquery-test