There are 2 issues with Order and aggregates:
1. Aggregate functions are not registered to the GroupIterator if they do not reside in the Projection, so no aggregate is evaluated after receiving the multisets. So in this case we receive only the keys to the multisets, namely :barry2, :naso, :barry1.
2. ORDER BY throws exception when the comparator is set to an expression other than the built-in ones (Var, ValueConstant, BNodeGenerator, Bound, Str, Label, Lang, LangMatches, ..., IsURI, IsLiteral, ..., Like, And, Or, Not, ..., Exists, If). Here is the exception trace:
org.openrdf.query.QueryEvaluationException: Unsupported value expr type: class org.openrdf.query.algebra.Count
at org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl.evaluate(EvaluationStrategyImpl.java:1041)
at org.openrdf.query.algebra.evaluation.util.OrderComparator.evaluate(OrderComparator.java:70)
at org.openrdf.query.algebra.evaluation.util.OrderComparator.compare(OrderComparator.java:44)
at org.openrdf.query.algebra.evaluation.util.OrderComparator.compare(OrderComparator.java:1)
Looking at the Sesame source code, I'm not sure whether this query misbehaviour is due to real issues in Sesame or the query itself is not well formulated.
I have run into a similar issue before, I vaguely remember. will check out.
Problem found, had to do with ORDER by processing in the TupleExprBuilder. I've managed to fix the issue, added two testcases for it in the manifest set (aggregates/sparql11-order-02 and aggregates/sparql11-order-03), both greenline now.