Implement ordering by aggregates #221

Open
opened 2020-08-06 16:56:52 +00:00 by gburd · 0 comments
gburd commented 2020-08-06 16:56:52 +00:00 (Migrated from github.com)

Right now, it's not possible to order by aggregates, so that queries like

[:find
 (count ?x)
 :where
 [_ :mentions ?x]
 :order
 (count ?x)]

are not possible. (They don't parse, due to :order expecting bare variables.)

@rnewman suggests this is simply not implemented, and says: the obvious solution is to take each :order that’s a valid aggregate expression and push it into the projector, just as we do now with order-vars. It would perhaps be worthwhile to make sure that

[:find ?person (sum ?balance)
 :where …
 :order (desc (sum ?balance))]

generates

SELECT datoms00.e AS ?person, sum(datoms00.v) AS ?balance … ORDER BY ?balance DESC

rather than mentioning sum twice. Otherwise this should mostly be a matter of extending the parser and altering some type choices in the projector/ordering hookup, which already exists.

Right now, it's not possible to order by aggregates, so that queries like ``` [:find (count ?x) :where [_ :mentions ?x] :order (count ?x)] ``` are not possible. (They don't parse, due to `:order` expecting bare variables.) @rnewman suggests this is simply not implemented, and says: the obvious solution is to take each `:order` that’s a valid aggregate expression and push it into the projector, just as we do now with order-vars. It would perhaps be worthwhile to make sure that ``` [:find ?person (sum ?balance) :where … :order (desc (sum ?balance))] ``` generates ``` SELECT datoms00.e AS ?person, sum(datoms00.v) AS ?balance … ORDER BY ?balance DESC ``` rather than mentioning `sum` twice. Otherwise this should mostly be a matter of extending the parser and altering some type choices in the projector/ordering hookup, which already exists.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/mentat#221
No description provided.