It looks more like the cartesian happens on the graphs - how many graph do you have matching the first and the second part?
On 24.11.20 14:27, Martynas Jusevičius wrote: > Hi, > > despite using SPARQL for years, cases where different implementations > return different results leave me scratching my head. Can someone help > me out with this? > > I have a rather simple query: > > PREFIX schema: <https://schema.org/> > PREFIX foaf: <http://xmlns.com/foaf/0.1/> > PREFIX sioc: <http://rdfs.org/sioc/ns#> > > SELECT * WHERE { > GRAPH ?docGraph { > ?doc sioc:has_container <https://localhost:4443/employees/>; > foaf:primaryTopic ?employee. > OPTIONAL { ?employee schema:sponsor ?reportsToEmployee. } > } > } > ORDER BY ?doc > > Dydra returns 9 results: > > employee,reportsToEmployee > https://localhost:4443/employees/1/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/2/#this, > https://localhost:4443/employees/3/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/4/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/5/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/6/#this,https://localhost:4443/employees/5/#this > https://localhost:4443/employees/7/#this,https://localhost:4443/employees/5/#this > https://localhost:4443/employees/8/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/9/#this,https://localhost:4443/employees/5/#this > > Fuseki 3.16.0 returns 9 results: > > employee,reportsToEmployee > https://localhost:4443/employees/1/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/2/#this, > https://localhost:4443/employees/3/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/4/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/5/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/6/#this,https://localhost:4443/employees/5/#this > https://localhost:4443/employees/7/#this,https://localhost:4443/employees/5/#this > https://localhost:4443/employees/8/#this,https://localhost:4443/employees/2/#this > https://localhost:4443/employees/9/#this,https://localhost:4443/employees/5/#this > > So far so good -- the results are identical. Now I append an OPTIONAL > to the end of the query: > > PREFIX schema: <https://schema.org/> > PREFIX foaf: <http://xmlns.com/foaf/0.1/> > PREFIX sioc: <http://rdfs.org/sioc/ns#> > > SELECT ?employee ?reportsToEmployee ?reportsToEmployeeLabel WHERE { > GRAPH ?docGraph { > ?doc sioc:has_container <https://localhost:4443/employees/>; > foaf:primaryTopic ?employee. > OPTIONAL { ?employee schema:sponsor ?reportsToEmployee. } > } > OPTIONAL { > GRAPH ?reportsToEmployeeLabelGraph { ?reportsToEmployee > <http://purl.org/dc/terms/title> ?reportsToEmployeeLabel. } > } > } > ORDER BY ?doc > > Dydra returns 9 results: > > employee,reportsToEmployee,reportsToEmployeeLabel > https://localhost:4443/employees/1/#this,https://localhost:4443/employees/2/#this,Fuller > https://localhost:4443/employees/2/#this,, > https://localhost:4443/employees/3/#this,https://localhost:4443/employees/2/#this,Fuller > https://localhost:4443/employees/4/#this,https://localhost:4443/employees/2/#this,Fuller > https://localhost:4443/employees/5/#this,https://localhost:4443/employees/2/#this,Fuller > https://localhost:4443/employees/6/#this,https://localhost:4443/employees/5/#this,Buchanan > https://localhost:4443/employees/7/#this,https://localhost:4443/employees/5/#this,Buchanan > https://localhost:4443/employees/8/#this,https://localhost:4443/employees/2/#this,Fuller > https://localhost:4443/employees/9/#this,https://localhost:4443/employees/5/#this,Buchanan > > Fuseki 3.16.0 returns 2400+ results: > > employee,reportsToEmployee,reportsToEmployeeLabel > https://localhost:4443/employees/1/#this,https://localhost:4443/employees/2/#this,Fuller > https://localhost:4443/employees/2/#this,https://localhost:4443/,Root > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/,Categories > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/1/,Beverages > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/1/#this,Beverages > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/2/,Condiments > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/2/#this,Condiments > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/3/,Confections > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/3/#this,Confections > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/4/,Dairy > Products > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/4/#this,Dairy > Products > https://localhost:4443/employees/2/#this,https://localhost:4443/categories/5/,Grains/Cereals > .... > > Dydra's result is the one I'm going after, and is based on my > understanding of OPTIONAL. But is it actually correct? > > And if Dydra is correct, what is Fuseki doing here? I would have > expected the ?reportsToEmployee bindings from the appended OPTIONAL to > be joined against the first result (without OPTIONAL), but that is not > the case? > > Thanks. > > Martynas