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

    https://github.com/apache/incubator-rya/pull/255#discussion_r160549312
  
    --- Diff: 
dao/mongodb.rya/src/test/java/org/apache/rya/mongodb/aggregation/SparqlToPipelineTransformVisitorTest.java
 ---
    @@ -0,0 +1,221 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.rya.mongodb.aggregation;
    +
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.bson.Document;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.mockito.Mockito;
    +import org.openrdf.model.URI;
    +import org.openrdf.model.ValueFactory;
    +import org.openrdf.model.impl.ValueFactoryImpl;
    +import org.openrdf.model.vocabulary.OWL;
    +import org.openrdf.model.vocabulary.RDF;
    +import org.openrdf.query.algebra.Extension;
    +import org.openrdf.query.algebra.ExtensionElem;
    +import org.openrdf.query.algebra.Join;
    +import org.openrdf.query.algebra.MultiProjection;
    +import org.openrdf.query.algebra.Not;
    +import org.openrdf.query.algebra.Projection;
    +import org.openrdf.query.algebra.ProjectionElem;
    +import org.openrdf.query.algebra.ProjectionElemList;
    +import org.openrdf.query.algebra.QueryRoot;
    +import org.openrdf.query.algebra.StatementPattern;
    +import org.openrdf.query.algebra.TupleExpr;
    +import org.openrdf.query.algebra.ValueConstant;
    +import org.openrdf.query.algebra.Var;
    +
    +import com.google.common.collect.Sets;
    +import com.mongodb.MongoNamespace;
    +import com.mongodb.client.MongoCollection;
    +
    +public class SparqlToPipelineTransformVisitorTest {
    +
    +    private static final ValueFactory VF = ValueFactoryImpl.getInstance();
    +
    +    private static final String LUBM = "urn:lubm";
    +    private static final URI UNDERGRAD = VF.createURI(LUBM, 
"UndergraduateStudent");
    +    private static final URI PROFESSOR = VF.createURI(LUBM, "Professor");
    +    private static final URI COURSE = VF.createURI(LUBM, "Course");
    +    private static final URI TAKES = VF.createURI(LUBM, "takesCourse");
    +    private static final URI TEACHES = VF.createURI(LUBM, "teachesCourse");
    +
    +    private static Var constant(URI value) {
    +        return new Var(value.stringValue(), value);
    +    }
    +
    +    MongoCollection<Document> collection;
    +
    +    @Before
    +    @SuppressWarnings("unchecked")
    +    public void setUp() {
    +        collection = Mockito.mock(MongoCollection.class);
    +        Mockito.when(collection.getNamespace()).thenReturn(new 
MongoNamespace("db", "collection"));
    +    }
    +
    +    @Test
    +    public void testStatementPattern() throws Exception {
    +        QueryRoot query = new QueryRoot(new StatementPattern(
    +                new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD)));
    +        SparqlToPipelineTransformVisitor visitor = new 
SparqlToPipelineTransformVisitor(collection);
    +        query.visit(visitor);
    +        Assert.assertTrue(query.getArg() instanceof 
AggregationPipelineQueryNode);
    +        AggregationPipelineQueryNode pipelineNode = 
(AggregationPipelineQueryNode) query.getArg();
    +        Assert.assertEquals(Sets.newHashSet("x"), 
pipelineNode.getAssuredBindingNames());
    +    }
    +
    +    @Test
    +    public void testJoin() throws Exception {
    +        QueryRoot query = new QueryRoot(new Join(
    +                new StatementPattern(new Var("x"), constant(RDF.TYPE), 
constant(UNDERGRAD)),
    +                new StatementPattern(new Var("x"), constant(TAKES), new 
Var("course"))));
    +        SparqlToPipelineTransformVisitor visitor = new 
SparqlToPipelineTransformVisitor(collection);
    +        query.visit(visitor);
    +        Assert.assertTrue(query.getArg() instanceof 
AggregationPipelineQueryNode);
    +        AggregationPipelineQueryNode pipelineNode = 
(AggregationPipelineQueryNode) query.getArg();
    +        Assert.assertEquals(Sets.newHashSet("x", "course"), 
pipelineNode.getAssuredBindingNames());
    +    }
    +
    +    @Test
    +    public void testNestedJoins() throws Exception {
    +        StatementPattern isUndergrad = new StatementPattern(new Var("x"), 
constant(RDF.TYPE), constant(UNDERGRAD));
    --- End diff --
    
    True, but the behavior here depends on the specific structure of the query 
tree: something like `Join(Join(Join(SP1, SP2), SP3), SP4)` will yield 
different results from `Join(Join(SP1, SP2), Join(SP3, SP4))` even if both are 
valid representations of `SELECT * WHERE { SP1 . SP2 . SP3 . SP4 . }` These 
tests verify that certain query trees will be processed correctly; I didn't 
want them to additionally depend on the behavior of the parser to produce the 
expected trees from the queries. (We'd rather get the former parse, but getting 
the second wouldn't indicate an error in this class.) That means at least the 
highest levels of the query tree need to be constructed directly, so it seemed 
cleaner to just compose the entire tree. The integration tests, in contrast, 
start with SPARQL and go through the entire process of 
parse->transform->execute.


---

Reply via email to