Search in sources :

Example 1 with QueryNodeConsolidator

use of org.apache.rya.indexing.external.matching.QueryNodeConsolidator in project incubator-rya by apache.

the class PCJNodeConsolidatorTest method testAlreadyInOrder.

@Test
public void testAlreadyInOrder() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d" + // 
    "{" + // 
    "  ?a <uri:p5> <uri:const3>" + // 
    "  OPTIONAL{?a <uri:p3> ?c} . " + // 
    "  ?a <uri:p4> ?b . " + // 
    "  OPTIONAL{<uri:const2> <uri:p4> ?d } . " + "  ?c <uri:p1> ?d " + // 
    "  OPTIONAL{<uri:const1> <uri:p2> ?b} . " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d" + // 
    "{" + // 
    "  ?a <uri:p4> ?b . " + // 
    "  OPTIONAL{<uri:const2> <uri:p4> ?d } . " + "  ?c <uri:p1> ?d " + // 
    "}";
    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();
    Join join2 = (Join) ((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<>(seg1.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) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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 2 with QueryNodeConsolidator

use of org.apache.rya.indexing.external.matching.QueryNodeConsolidator in project incubator-rya by apache.

the class PCJNodeConsolidatorTest method testSwitchBoundVars.

@Test
public void testSwitchBoundVars() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b " + // 
    "{" + // 
    "  ?a <uri:p0> ?b ." + // 
    " OPTIONAL{ ?a <uri:p1> <uri:o1> } ." + // 
    " ?a <uri:p2> <uri:o2> " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?a ?b " + // 
    "{" + // 
    " ?a <uri:p2> <uri:o2> " + // 
    " OPTIONAL{ ?a <uri:p1> <uri:o1> } ." + // 
    "  ?a <uri:p0> ?b ." + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    Join join1 = (Join) ((Projection) te1).getArg();
    Join join2 = (Join) ((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) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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 3 with QueryNodeConsolidator

use of org.apache.rya.indexing.external.matching.QueryNodeConsolidator in project incubator-rya by apache.

the class PCJNodeConsolidatorTest method testUpperLowerBoundOptional.

@Test
public void testUpperLowerBoundOptional() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d" + // 
    "{" + // 
    "  ?a <uri:p5> <uri:const3>" + // 
    "  OPTIONAL{<uri:const2> <uri:p4> ?d } . " + // 
    "  ?a <uri:p4> ?b . " + // 
    "  OPTIONAL{?a <uri:p3> ?c} . " + // 
    "  OPTIONAL{<uri:const1> <uri:p2> ?b} . " + "  ?c <uri:p1> ?d " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?a ?b ?c ?d" + // 
    "{" + // 
    "  ?a <uri:p4> ?b . " + // 
    "  OPTIONAL{<uri:const2> <uri:p4> ?d } . " + "  ?c <uri:p1> ?d " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    Join join1 = (Join) ((Projection) te1).getArg();
    Join join2 = (Join) ((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<>(seg1.getOrderedNodes());
    QueryModelNode node = queryNodes.remove(0);
    queryNodes.add(1, node);
    node = queryNodes.remove(3);
    queryNodes.add(2, node);
    node = queryNodes.remove(4);
    queryNodes.add(2, node);
    Assert.assertTrue(consolidator.consolidateNodes());
    Assert.assertEquals(consolidator.getQueryNodes(), queryNodes);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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 4 with QueryNodeConsolidator

use of org.apache.rya.indexing.external.matching.QueryNodeConsolidator in project incubator-rya by apache.

the class PCJNodeConsolidatorTest method testSwitchTwoBoundVars.

@Test
public void testSwitchTwoBoundVars() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c " + // 
    "{" + // 
    "  ?a <uri:p0> ?c ." + // 
    "  ?b<uri:p1> ?c ." + // 
    " OPTIONAL{ ?a <uri:p1> ?b } ." + // 
    " ?a <uri:p2> <uri:o2>. " + // 
    " ?b <uri:p3> <uri:o3> " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?a ?b ?c" + // 
    "{" + // 
    " ?a <uri:p2> <uri:o2>. " + // 
    " ?b <uri:p3> <uri:o3>. " + // 
    " OPTIONAL{ ?a <uri:p1> ?b } ." + // 
    "  ?a <uri:p0> ?c ." + // 
    "  ?b<uri:p1> ?c " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    Join join1 = (Join) ((Projection) te1).getArg();
    Join join2 = (Join) ((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) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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 5 with QueryNodeConsolidator

use of org.apache.rya.indexing.external.matching.QueryNodeConsolidator in project incubator-rya by apache.

the class PCJNodeConsolidatorTest method testMoveAcrossMultipleLeftJoins.

@Test
public void testMoveAcrossMultipleLeftJoins() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c ?e ?f" + // 
    "{" + // 
    "  ?c <uri:p5> <uri:o2> ." + // 
    "  ?a <uri:p4> <uri:o1> . " + // 
    "  OPTIONAL{?a <uri:p3> ?b} . " + // 
    "  OPTIONAL{<uri:s2> <uri:p2> ?e} . " + // 
    "  OPTIONAL{<uri:s2> <uri:p2> ?f} . " + "  <uri:s1> <uri:p1> ?f " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?f ?c" + // 
    "{" + // 
    "  ?c <uri:p5> <uri:o2> . " + "  <uri:s1> <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();
    Join join1 = (Join) ((Projection) te1).getArg();
    Join join2 = (Join) ((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<>(seg1.getOrderedNodes());
    QueryModelNode node = queryNodes.remove(5);
    queryNodes.add(1, node);
    Assert.assertTrue(consolidator.consolidateNodes());
    Assert.assertEquals(consolidator.getQueryNodes(), queryNodes);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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

QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)10 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)10 Test (org.junit.Test)10 TupleExpr (org.openrdf.query.algebra.TupleExpr)10 ParsedQuery (org.openrdf.query.parser.ParsedQuery)10 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)10 LeftJoin (org.openrdf.query.algebra.LeftJoin)9 ArrayList (java.util.ArrayList)8 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)8 Join (org.openrdf.query.algebra.Join)7 Filter (org.openrdf.query.algebra.Filter)1