mozilla / jx-sqlite

JSON query expressions using SQLite
Mozilla Public License 2.0
34 stars 19 forks source link

Isolate union aggregates in own subqueries #68

Open klahnakoski opened 7 years ago

klahnakoski commented 7 years ago

To properly isolate each union, they need their own subquery that performs the grouping:

SELECT 
    *,
    a.c2
FROM testing
LEFT JOIN (
    SELECT 
        __parent__,
        JSON_GROUP_ARRAY(DISTINCT (testing._c.$NUMBER)) c2
    FROM testing._c
    ) a ON a.__parent__ = testing.__id__

The subquery performs the grouping as required so it results in just one value per fact table. That subquery is then joined with the fact table.

klahnakoski commented 7 years ago

I attempted to fix this but it appears to be more difficult than I imagined. I believe the solution is to solve aggregation over nested tables first, then use it to perform union over a zero-dimensional edge.