Search in sources :

Example 11 with SimpleExternalTupleSet

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

the class OptionalJoinSegmentTest method testBasicOptional.

@Test
public void testBasicOptional() 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();
    Join join = (Join) ((Projection) te1).getArg();
    LeftJoin lj = (LeftJoin) ((Projection) te2).getArg();
    QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(join);
    QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(lj);
    Assert.assertEquals(true, seg1.containsQuerySegment(seg2));
    Assert.assertEquals(join, seg1.getQuery().getTupleExpr());
    SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    List<QueryModelNode> nodes = seg1.getOrderedNodes();
    QueryModelNode node = nodes.get(0);
    seg1.replaceWithExternalSet(seg2, pcj);
    Set<QueryModelNode> nodeSet = new HashSet<>();
    nodeSet.add(node);
    nodeSet.add(pcj);
    Assert.assertEquals(nodeSet, seg1.getUnOrderedNodes());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) 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) LeftJoin(org.openrdf.query.algebra.LeftJoin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with SimpleExternalTupleSet

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

the class OptionalJoinSegmentTest method testBasicOptionalWithFilter.

@Test
public void testBasicOptionalWithFilter() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " Filter(?e = <uri:Bob>)" + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
    "  ?e a ?c . " + // 
    "  OPTIONAL{?e <uri:talksTo> ?l } . " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " Filter(?e = <uri:Bob>)" + // 
    "  ?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();
    TopOfQueryFilterRelocator.moveFiltersToTop(te1);
    Filter filter1 = (Filter) ((Projection) te1).getArg();
    Filter filter2 = (Filter) ((Projection) te2).getArg();
    QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(filter1);
    QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(filter2);
    Assert.assertEquals(filter1, seg1.getQuery().getTupleExpr());
    Assert.assertEquals(true, seg1.containsQuerySegment(seg2));
    SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    List<QueryModelNode> nodes = seg1.getOrderedNodes();
    QueryModelNode node = nodes.get(3);
    seg1.replaceWithExternalSet(seg2, pcj);
    Set<QueryModelNode> nodeSet = new HashSet<>();
    nodeSet.add(node);
    nodeSet.add(pcj);
    Assert.assertEquals(nodeSet, seg1.getUnOrderedNodes());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Filter(org.openrdf.query.algebra.Filter) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testBasicSegment.

@Test
public void testBasicSegment() throws Exception {
    final 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 " + // 
    "}";
    final String query2 = // 
    "" + // 
    "SELECT ?a ?b ?m" + // 
    "{" + // 
    "  ?a a ?b . " + // 
    "  OPTIONAL {?a <uri:talksTo> ?m}  . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(2));
    final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj);
    provider.setIndices(externalList);
    final PCJOptimizer optimizer = new PCJOptimizer(externalList, false, provider);
    optimizer.optimize(te1, null, null);
    Assert.assertEquals(true, validatePcj(te1, unOpt, externalList, unMatchedNodes));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) 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 14 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testExactMatchLargeReOrdered.

@Test
public void testExactMatchLargeReOrdered() throws Exception {
    final 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} . " + // 
    "}";
    final 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} . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj);
    provider.setIndices(externalList);
    final PCJOptimizer optimizer = new PCJOptimizer(externalList, false, provider);
    optimizer.optimize(te1, null, null);
    Assert.assertEquals(true, validatePcj(te1, unOpt, externalList, new HashSet<QueryModelNode>()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testSubsetMatchLargeReOrdered.

@Test
public void testSubsetMatchLargeReOrdered() throws Exception {
    final 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:p5> ?i. ?i <uri:p6> ?j} . " + // 
    "  OPTIONAL{?b <uri:p5> ?k. ?k <uri:p6> ?l} . " + // 
    "  OPTIONAL{?b <uri:p5> ?m. ?m <uri:p6> ?n} . " + // 
    "  OPTIONAL{?b <uri:p4> ?o. ?o <uri:p1> ?p} . " + // 
    "}";
    final 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:p3> ?e. ?e <uri:p1> ?f} . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(8));
    unMatchedNodes.add(remainingNodes.get(9));
    unMatchedNodes.add(remainingNodes.get(10));
    unMatchedNodes.add(remainingNodes.get(11));
    unMatchedNodes.add(remainingNodes.get(12));
    unMatchedNodes.add(remainingNodes.get(7));
    final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj);
    provider.setIndices(externalList);
    final PCJOptimizer optimizer = new PCJOptimizer(externalList, false, provider);
    optimizer.optimize(te1, null, null);
    Assert.assertEquals(true, validatePcj(te1, unOpt, externalList, unMatchedNodes));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) 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)

Aggregations

SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)84 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)84 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)83 Test (org.junit.Test)82 ParsedQuery (org.openrdf.query.parser.ParsedQuery)82 TupleExpr (org.openrdf.query.algebra.TupleExpr)74 ArrayList (java.util.ArrayList)60 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)47 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)42 Projection (org.openrdf.query.algebra.Projection)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)23 HashSet (java.util.HashSet)18 Configuration (org.apache.hadoop.conf.Configuration)10 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)10 Join (org.openrdf.query.algebra.Join)6 List (java.util.List)5 MalformedQueryException (org.openrdf.query.MalformedQueryException)5 LeftJoin (org.openrdf.query.algebra.LeftJoin)5 Filter (org.openrdf.query.algebra.Filter)4 NodeCollector (org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector)2