Search in sources :

Example 26 with QueryRoot

use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPipelineTransformVisitorTest method testEmptyProjection.

@Test
public void testEmptyProjection() throws Exception {
    StatementPattern isClass = new StatementPattern(constant(UNDERGRAD), constant(RDF.TYPE), constant(OWL.CLASS));
    QueryRoot queryTree = new QueryRoot(new Projection(isClass, new ProjectionElemList()));
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof Projection);
    Projection projectNode = (Projection) queryTree.getArg();
    Assert.assertTrue(projectNode.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projectNode.getArg();
    Assert.assertEquals(Sets.newHashSet(), pipelineNode.getAssuredBindingNames());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryRoot(org.openrdf.query.algebra.QueryRoot) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) Test(org.junit.Test)

Example 27 with QueryRoot

use of org.openrdf.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPipelineTransformVisitorTest method testMultiProjection.

@Test
public void testMultiProjection() throws Exception {
    StatementPattern isUndergrad = new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD));
    StatementPattern isCourse = new StatementPattern(new Var("course"), constant(RDF.TYPE), constant(COURSE));
    StatementPattern hasEdge = new StatementPattern(new Var("x"), new Var("p"), new Var("course"));
    ProjectionElemList courseHasRelation = new ProjectionElemList(new ProjectionElem("p", "relation"), new ProjectionElem("course"));
    ProjectionElemList studentHasRelation = new ProjectionElemList(new ProjectionElem("p", "relation"), new ProjectionElem("x", "student"));
    QueryRoot queryTree = new QueryRoot(new MultiProjection(new Join(new Join(isCourse, hasEdge), isUndergrad), Arrays.asList(courseHasRelation, studentHasRelation)));
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
    Assert.assertEquals(Sets.newHashSet("relation"), pipelineNode.getAssuredBindingNames());
    Assert.assertEquals(Sets.newHashSet("relation", "course", "student"), pipelineNode.getBindingNames());
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryRoot(org.openrdf.query.algebra.QueryRoot) Var(org.openrdf.query.algebra.Var) Join(org.openrdf.query.algebra.Join) MultiProjection(org.openrdf.query.algebra.MultiProjection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Aggregations

QueryRoot (org.openrdf.query.algebra.QueryRoot)27 Test (org.junit.Test)13 ParsedQuery (org.openrdf.query.parser.ParsedQuery)11 QueryParser (org.openrdf.query.parser.QueryParser)11 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)11 StatementPattern (org.openrdf.query.algebra.StatementPattern)9 Var (org.openrdf.query.algebra.Var)8 BindingSet (org.openrdf.query.BindingSet)5 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)5 Join (org.openrdf.query.algebra.Join)5 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)5 EmptyBindingSet (org.openrdf.query.impl.EmptyBindingSet)5 TupleExpr (org.openrdf.query.algebra.TupleExpr)4 URI (org.openrdf.model.URI)3 Projection (org.openrdf.query.algebra.Projection)3 ListBindingSet (org.openrdf.query.impl.ListBindingSet)3 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)2 QueryJoinOptimizer (org.apache.rya.rdftriplestore.evaluation.QueryJoinOptimizer)2 InverseOfVisitor (org.apache.rya.rdftriplestore.inference.InverseOfVisitor)2 Extension (org.openrdf.query.algebra.Extension)2