Search in sources :

Example 86 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class OptionalJoinSegmentPCJMatcherTest method testBasicSegment.

@Test
public void testBasicSegment() throws MalformedQueryException {
    String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  OPTIONAL {?e <uri:talksTo> ?l}  . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  OPTIONAL {?e <uri:talksTo> ?l}  . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    Projection proj = (Projection) te1;
    Join join = (Join) proj.getArg();
    ExternalSetMatcher<ExternalTupleSet> jsm = pcjFactory.getMatcher(qFactory.getQuerySegment(join));
    SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    Assert.assertEquals(true, jsm.match(pcj));
    TupleExpr te = jsm.getQuery();
    Assert.assertEquals(new HashSet<QueryModelNode>(), jsm.getUnmatchedArgNodes());
    Set<QueryModelNode> qNodes = LeftJoinQueryNodeGatherer.getNodes(te);
    List<QueryModelNode> nodes = jsm.getOrderedNodes();
    Set<QueryModelNode> nodeSet = new HashSet<>();
    nodeSet.add(nodes.get(0));
    nodeSet.add(pcj);
    Assert.assertEquals(nodeSet, new HashSet<QueryModelNode>(nodes));
    Assert.assertEquals(nodeSet, qNodes);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet 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 88 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet 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)

Example 89 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.

the class PCJNodeConsolidatorTest method testInvalidOrder.

@Test
public void testInvalidOrder() 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 . " + "  ?c <uri:p1> ?d " + // 
    "  OPTIONAL{<uri:const2> <uri:p4> ?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();
    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());
    Assert.assertTrue(!consolidator.consolidateNodes());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) LeftJoin(org.openrdf.query.algebra.LeftJoin) ParsedQuery(org.openrdf.query.parser.ParsedQuery) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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 90 with ExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet 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)

Aggregations

ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)107 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)99 Test (org.junit.Test)97 ParsedQuery (org.openrdf.query.parser.ParsedQuery)97 TupleExpr (org.openrdf.query.algebra.TupleExpr)92 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 ArrayList (java.util.ArrayList)73 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)56 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 Projection (org.openrdf.query.algebra.Projection)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)23 HashSet (java.util.HashSet)19 Join (org.openrdf.query.algebra.Join)14 LeftJoin (org.openrdf.query.algebra.LeftJoin)14 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)12 Configuration (org.apache.hadoop.conf.Configuration)10 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)10 List (java.util.List)9 MalformedQueryException (org.openrdf.query.MalformedQueryException)7 Filter (org.openrdf.query.algebra.Filter)6