Search in sources :

Example 11 with LeftJoin

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

the class PCJNodeConsolidatorTest method testExactMatchReOrdered.

@Test
public void testExactMatchReOrdered() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d ?e ?f ?g ?h" + // 
    "{" + // 
    "  ?a <uri:p0> ?b ." + // 
    "  OPTIONAL{?b <uri:p2> ?c. ?c <uri:p1> ?d} . " + // 
    "  OPTIONAL{?b <uri:p3> ?e. ?e <uri:p1> ?f} . " + // 
    "  OPTIONAL{?b <uri:p4> ?g. ?g <uri:p1> ?h} . " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d ?e ?f ?g ?h" + // 
    "{" + // 
    "  ?a <uri:p0> ?b ." + // 
    "  OPTIONAL{?b <uri:p2> ?c. ?c <uri:p1> ?d} . " + // 
    "  OPTIONAL{?b <uri:p4> ?g. ?g <uri:p1> ?h} . " + // 
    "  OPTIONAL{?b <uri:p3> ?e. ?e <uri:p1> ?f} . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    LeftJoin join1 = (LeftJoin) ((Projection) te1).getArg();
    LeftJoin join2 = (LeftJoin) ((Projection) te2).getArg();
    QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(join1);
    QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(join2);
    QueryNodeConsolidator consolidator = new QueryNodeConsolidator(seg1.getOrderedNodes(), seg2.getOrderedNodes());
    List<QueryModelNode> queryNodes = new ArrayList<>(seg2.getOrderedNodes());
    Assert.assertTrue(consolidator.consolidateNodes());
    Assert.assertEquals(consolidator.getQueryNodes(), queryNodes);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) LeftJoin(org.openrdf.query.algebra.LeftJoin) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) QueryNodeConsolidator(org.apache.rya.indexing.external.matching.QueryNodeConsolidator) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Example 12 with LeftJoin

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

the class PCJNodeConsolidatorTest method testExactMatchLargeReOrdered.

@Test
public void testExactMatchLargeReOrdered() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d ?e ?f ?g ?h" + // 
    "{" + // 
    "  ?a <uri:p0> ?b ." + // 
    "  OPTIONAL{?b <uri:p2> ?c. ?c <uri:p1> ?d} . " + // 
    "  OPTIONAL{?b <uri:p3> ?e. ?e <uri:p1> ?f} . " + // 
    "  OPTIONAL{?b <uri:p4> ?g. ?g <uri:p1> ?h} . " + // 
    "  OPTIONAL{?b <uri:p4> ?i. ?i <uri:p1> ?j} . " + // 
    "  OPTIONAL{?b <uri:p4> ?k. ?k <uri:p1> ?l} . " + // 
    "  OPTIONAL{?b <uri:p4> ?m. ?m <uri:p1> ?n} . " + // 
    "  OPTIONAL{?b <uri:p4> ?o. ?o <uri:p1> ?p} . " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d ?e ?f ?g ?h" + // 
    "{" + // 
    "  ?a <uri:p0> ?b ." + // 
    "  OPTIONAL{?b <uri:p4> ?o. ?o <uri:p1> ?p} . " + // 
    "  OPTIONAL{?b <uri:p4> ?g. ?g <uri:p1> ?h} . " + // 
    "  OPTIONAL{?b <uri:p2> ?c. ?c <uri:p1> ?d} . " + // 
    "  OPTIONAL{?b <uri:p4> ?i. ?i <uri:p1> ?j} . " + // 
    "  OPTIONAL{?b <uri:p4> ?m. ?m <uri:p1> ?n} . " + // 
    "  OPTIONAL{?b <uri:p4> ?k. ?k <uri:p1> ?l} . " + // 
    "  OPTIONAL{?b <uri:p3> ?e. ?e <uri:p1> ?f} . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    LeftJoin join1 = (LeftJoin) ((Projection) te1).getArg();
    LeftJoin join2 = (LeftJoin) ((Projection) te2).getArg();
    QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(join1);
    QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(join2);
    QueryNodeConsolidator consolidator = new QueryNodeConsolidator(seg1.getOrderedNodes(), seg2.getOrderedNodes());
    List<QueryModelNode> queryNodes = new ArrayList<>(seg2.getOrderedNodes());
    Assert.assertTrue(consolidator.consolidateNodes());
    Assert.assertEquals(consolidator.getQueryNodes(), queryNodes);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) LeftJoin(org.openrdf.query.algebra.LeftJoin) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) QueryNodeConsolidator(org.apache.rya.indexing.external.matching.QueryNodeConsolidator) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Aggregations

LeftJoin (org.openrdf.query.algebra.LeftJoin)12 Join (org.openrdf.query.algebra.Join)10 TupleExpr (org.openrdf.query.algebra.TupleExpr)6 ParsedQuery (org.openrdf.query.parser.ParsedQuery)6 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)6 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)5 Test (org.junit.Test)5 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)4 Filter (org.openrdf.query.algebra.Filter)4 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)4 ArrayList (java.util.ArrayList)3 DoNotExpandSP (org.apache.rya.rdftriplestore.inference.DoNotExpandSP)2 FixedStatementPattern (org.apache.rya.rdftriplestore.utils.FixedStatementPattern)2 HashSet (java.util.HashSet)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 StateStoreSupplier (org.apache.kafka.streams.processor.StateStoreSupplier)1 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)1 IterativeJoin (org.apache.rya.api.function.join.IterativeJoin)1 LeftOuterJoin (org.apache.rya.api.function.join.LeftOuterJoin)1 NaturalJoin (org.apache.rya.api.function.join.NaturalJoin)1