I removed the graph name projection from the OPTIONAL:

PREFIX  schema: <https://schema.org/>
PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
PREFIX  sioc: <http://rdfs.org/sioc/ns#>

SELECT  DISTINCT ?employee ?reportsToEmployee ?reportsToEmployeeLabel
WHERE
  { GRAPH ?docGraph
      { ?doc  sioc:has_container  <https://localhost:4443/employees/> ;
              foaf:primaryTopic   ?employee
        OPTIONAL
          { ?employee  schema:sponsor  ?reportsToEmployee }
      }
    OPTIONAL
      { { SELECT  ?reportsToEmployee ?reportsToEmployeeLabel
          WHERE
            {   { ?reportsToEmployee <http://purl.org/dc/terms/title>
?reportsToEmployeeLabel }
              UNION
                { GRAPH ?reportsToEmployeeLabelGraph
                    { ?reportsToEmployee
<http://purl.org/dc/terms/title> ?reportsToEmployeeLabel }
                }
            }
        }
      }
  }
ORDER BY ?doc

RDF4J now produces 9 results (same as Dydra), but Fuseki returns 2417 rows.

On Tue, Nov 24, 2020 at 3:33 PM Martynas Jusevičius
<marty...@atomgraph.com> wrote:
>
> Yes, it looks like this is due to the different treatment of the named graphs.
>
> PREFIX schema: <https://schema.org/>
> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
> PREFIX sioc: <http://rdfs.org/sioc/ns#>
>
> SELECT (COUNT(?docGraph) AS ?docGraphCount) WHERE {
>   GRAPH ?docGraph {
>     ?doc sioc:has_container <https://localhost:4443/employees/>;
>       foaf:primaryTopic ?employee.
>     OPTIONAL { ?employee schema:sponsor ?reportsToEmployee. }
>   }
> }
>
> Dydra: ?docGraphCount = 9
> Fuseki: ?docGraphCount = 9
> RDF4J: ?docGraphCount = 9
>
>
> PREFIX schema: <https://schema.org/>
> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
> PREFIX sioc: <http://rdfs.org/sioc/ns#>
>
> SELECT (COUNT(?reportsToEmployeeLabelGraph) AS
> ?reportsToEmployeeLabelGraphCount) WHERE {
>   GRAPH ?reportsToEmployeeLabelGraph { ?reportsToEmployee
> <http://purl.org/dc/terms/title> ?reportsToEmployeeLabel. }
> }
>
> Dydra: ?reportsToEmployeeLabelGraphCount = 2409
> Fuseki: ?reportsToEmployeeLabelGraphCount = 2409
> RDF4J: ?reportsToEmployeeLabelGraphCount = 2409
>
> On Tue, Nov 24, 2020 at 3:14 PM Lorenz Buehmann
> <buehm...@informatik.uni-leipzig.de> wrote:
> >
> > 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

Reply via email to