fluree / db

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

allow ordering by `as` select bindings #793

Closed dpetran closed 1 month ago

dpetran commented 1 month ago

This fixes a bug whereby trying to order-by a variable that is bound in the select clause doesn't work.

When we execute a query, we process it in this order:

The problem is that the aggregate vars only appear in the select clause, but by the time we add that binding to the solution, the solutions are already sorted - the binding just isn't available to sort by.

Fortunately, we already had all the necessary code written, I just needed to rearrange it. select/format first filters out any SolutionModifier Selectors, and then applies them in a transducer, which is then piped into the formatting pipeline.

All I had to do was factor out the modification xformer into a new function and then call that before order/arrange. So now it looks like this: