Github user afs commented on a diff in the pull request:

    https://github.com/apache/jena/pull/332#discussion_r158299025
  
    --- Diff: 
jena-arq/src/main/java/org/apache/jena/sparql/graph/GraphUnionRead.java ---
    @@ -82,16 +94,29 @@ protected PrefixMapping createPrefixMapping() {
             if ( graphs == null ) {
                 // This produces unique quads with the same graph node,
                 // hence the triples are distinct. 
    -            Iterator<Quad> qIter = dataset.findNG(Quad.unionGraph, 
m.getSubject(), m.getPredicate(), m.getObject());
    -            Iterator<Triple> tIter = Iter.map(qIter, 
quad->quad.asTriple());
    -            return WrappedIterator.createNoRemove(tIter) ;
    +            return quadsToTriples(dataset, Quad.unionGraph, m);
    +        }
    +        if ( graphs.isEmpty() )
    +            return NullIterator.instance();
    +        if ( graphName != null ) {
    +            if ( ! dataset.containsGraph(graphName) )
    +                // Avoid auto-creation.
    +                return NullIterator.instance();
    +            // Avoid needing distinct.
    +            return dataset.getGraph(graphName).find(m);
             }
             // Only certain graphs.
             IteratorConcat<Triple> iter = new IteratorConcat<>() ;
             forEachGraph((g) -> iter.add(g.find(m))) ;
             return WrappedIterator.createNoRemove(Iter.distinct(iter)) ;
         }
         
    +    private static ExtendedIterator<Triple> quadsToTriples(DatasetGraph 
dsg, Node graphName, Triple m) {
    --- End diff --
    
    It avoids churning graph objects. Graphs will eventually have to call down 
to core dataset-centric operations. Also this avoids an infinite recursion risk.
    
    (This code fragment is out of sync.)


---

Reply via email to