You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by afs <gi...@git.apache.org> on 2017/12/20 23:26:32 UTC

[GitHub] jena pull request #332: JENA-1452: GraphUnionRead; Union of one.

GitHub user afs opened a pull request:

    https://github.com/apache/jena/pull/332

    JENA-1452: GraphUnionRead; Union of one.

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/afs/jena union-of-one

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/jena/pull/332.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #332
    
----
commit 2966021bace073649e210ca7d64f9c38e3a02210
Author: Andy Seaborne <an...@...>
Date:   2017-12-20T22:43:32Z

    Optimize the one graph case for GraphUnionRead

commit c3c50fd8948b87d15607774d62c943f31308923b
Author: Andy Seaborne <an...@...>
Date:   2017-12-20T23:22:55Z

    Get one from a collection

----


---

[GitHub] jena pull request #332: JENA-1452: GraphUnionRead; Union of one.

Posted by ajs6f <gi...@git.apache.org>.
Github user ajs6f commented on a diff in the pull request:

    https://github.com/apache/jena/pull/332#discussion_r158302470
  
    --- 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 --
    
    Ah, that makes more sense, thanks!


---

[GitHub] jena pull request #332: JENA-1452: GraphUnionRead; Union of one.

Posted by afs <gi...@git.apache.org>.
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.)


---

[GitHub] jena pull request #332: JENA-1452: GraphUnionRead; Union of one.

Posted by ajs6f <gi...@git.apache.org>.
Github user ajs6f commented on a diff in the pull request:

    https://github.com/apache/jena/pull/332#discussion_r158292354
  
    --- 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 --
    
    Is this different from `dsg.getGraph(graphName).find(m)`?


---

[GitHub] jena pull request #332: JENA-1452: GraphUnionRead; Union of one.

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/jena/pull/332


---