Search in sources :

Example 6 with MultiProjection

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

the class SparqlFluoQueryBuilder method getConstructGraphVarOrder.

private static VariableOrder getConstructGraphVarOrder(final Reduced node) {
    // get child node
    final QueryModelNode child = node.getArg();
    Preconditions.checkArgument(child instanceof Projection || child instanceof MultiProjection);
    final UnaryTupleOperator unary = (UnaryTupleOperator) child;
    // get ProjectionElemList to build ConstructGraph
    final List<ProjectionElemList> projections = new ArrayList<>();
    if (unary instanceof Projection) {
        projections.add(((Projection) unary).getProjectionElemList());
    } else {
        projections.addAll(((MultiProjection) unary).getProjections());
    }
    return getConstructGraphVarOrder(projections);
}
Also used : ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) UnaryTupleOperator(org.openrdf.query.algebra.UnaryTupleOperator) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) MultiProjection(org.openrdf.query.algebra.MultiProjection) Projection(org.openrdf.query.algebra.Projection) ConstructProjection(org.apache.rya.indexing.pcj.fluo.app.ConstructProjection) MultiProjection(org.openrdf.query.algebra.MultiProjection)

Example 7 with MultiProjection

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

the class ConstructConsequentVisitorTest method testMultiProjection.

@Test
public void testMultiProjection() {
    Extension extension = new Extension(new SingletonSet(), new ExtensionElem(new ValueConstant(RDF.TYPE), "rdftype"), new ExtensionElem(new ValueConstant(OWL.OBJECTPROPERTY), "owlprop"), new ExtensionElem(new ValueConstant(OWL.EQUIVALENTCLASS), "owleqcls"), new ExtensionElem(new ValueConstant(OWL.CLASS), "owlclass"));
    MultiProjection projection = new MultiProjection(extension, Arrays.asList(new ProjectionElemList(new ProjectionElem("cls", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlclass", "object")), new ProjectionElemList(new ProjectionElem("prop", "subject"), new ProjectionElem("rdftype", "predicate"), new ProjectionElem("owlprop", "object")), new ProjectionElemList(new ProjectionElem("owleqcls", "predicate"), new ProjectionElem("cls", "object"))));
    ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
    projection.visit(visitor);
    Set<StatementPattern> expected = Sets.newHashSet(new StatementPattern(s(null), p(RDF.TYPE), o(OWL.CLASS)), new StatementPattern(s(null), p(RDF.TYPE), o(OWL.OBJECTPROPERTY)), new StatementPattern(s(null), p(OWL.EQUIVALENTCLASS), o(null)));
    Assert.assertEquals(expected, visitor.getConsequents());
}
Also used : Extension(org.openrdf.query.algebra.Extension) ProjectionElemList(org.openrdf.query.algebra.ProjectionElemList) StatementPattern(org.openrdf.query.algebra.StatementPattern) SingletonSet(org.openrdf.query.algebra.SingletonSet) ValueConstant(org.openrdf.query.algebra.ValueConstant) ExtensionElem(org.openrdf.query.algebra.ExtensionElem) MultiProjection(org.openrdf.query.algebra.MultiProjection) ProjectionElem(org.openrdf.query.algebra.ProjectionElem) Test(org.junit.Test)

Example 8 with MultiProjection

use of org.openrdf.query.algebra.MultiProjection 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

MultiProjection (org.openrdf.query.algebra.MultiProjection)8 Test (org.junit.Test)5 HashSet (java.util.HashSet)3 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)3 ValueFactory (org.openrdf.model.ValueFactory)3 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)3 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)3 MapBindingSet (org.openrdf.query.impl.MapBindingSet)3 Nullable (edu.umd.cs.findbugs.annotations.Nullable)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 BNode (org.openrdf.model.BNode)2 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)2 StatementPattern (org.openrdf.query.algebra.StatementPattern)2 ParsedQuery (org.openrdf.query.parser.ParsedQuery)2 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)1