We're updating the issue view to help you get more done. 

expressions in projection used for ordering are incorrect in the algebra

Description

With this SPARQL query:

1 ?

We get the following algebra:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 Projection ProjectionElemList ProjectionElem "usrname" ProjectionElem "rating" Extension ExtensionElem (rating) MathExpr (/) Var (name=-const-4, anonymous) Var (name=-const-5, anonymous) Extension ExtensionElem (-const-5) Count Var (name=rv) Extension ExtensionElem (-const-4) Sum Var (name=rv) Order OrderElem (DESC) Var (name=rating) Group (usrname) Join Join StatementPattern Var (name=f) Var (name=-const-1, value=urn:name, anonymous) Var (name=usrname) StatementPattern Var (name=f) Var (name=-const-2, value=urn:hasRating, anonymous) Var (name=r) StatementPattern Var (name=r) Var (name=-const-3, value=urn:rating, anonymous) Var (name=rv) GroupElem Sum Var (name=rv) GroupElem Count Var (name=rv)

The issue is that the order is on rating, however rating is not bound until later in the algebra, just prior to the projection. This yields un-ordered results.

Checking this with ARQ, we get the algebra:

1 2 3 4 5 6 7 8 9 (project (?usrname ?rating) (order ((desc ?rating)) (extend ((?rating (/ ?.0 ?.1))) (group (?usrname) ((?.0 (sum ?rv)) (?.1 (count ?rv))) (bgp (triple ?f urn:name ?usrname) (triple ?f urn:hasRating ?r) (triple ?r urn:rating ?rv) )))))))

There the bind for the expression is prior to the ordering, which I believe is the correct interpretation.

I've attached a sample input file that can be used for execution which, if you execute the query with that data, you should get data that looks something like

1 2 3 4 5 6 7 8 9 10 [usrname="4";rating="0.6897018127672744"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="9";rating="0.613244415076483"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="2";rating="0.34247382698061674"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="5";rating="0.5359722243081952"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="0";rating="0.5683035031772565"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="7";rating="0.555387106698032"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="8";rating="0.49497000983573936"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="6";rating="0.43988543279588227"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="1";rating="0.3722432951694533"^^<http://www.w3.org/2001/XMLSchema#double>] [usrname="3";rating="0.5071630749782212"^^<http://www.w3.org/2001/XMLSchema#double>]

You'll notice the ratings are not correctly ordered.

Environment

Java 6

Status

Assignee

JeenB

Reporter

Michael Grove

Labels

Components

Fix versions

Affects versions

2.7.0
2.6.9

Priority

Major