Search in sources :

Example 51 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testSegmentWithLeftJoinsAndFilters.

@Test
public void testSegmentWithLeftJoinsAndFilters() throws Exception {
    final String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " Filter(?e = <uri:s1>) " + // 
    " Filter(?c = <uri:s2>) " + " ?e <uri:p1> <uri:o1>. " + " OPTIONAL {?e <uri:p2> ?l}. " + // 
    " ?c <uri:p3> <uri:o3>  . " + // 
    "  ?c <uri:p4> ?e  . " + // 
    " OPTIONAL {?e <uri:p2> ?c } . " + // 
    "}";
    final String query2 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " Filter(?c = <uri:s2>) " + " ?e <uri:p1> <uri:o1>. " + " OPTIONAL {?e <uri:p2> ?l}. " + // 
    " ?c <uri:p3> <uri:o3>  . " + // 
    "}";
    final String query3 = // 
    "" + // 
    "SELECT ?e ?c" + // 
    "{" + // 
    " Filter(?e = <uri:s1>) " + // 
    "  ?c <uri:p4> ?e  . " + // 
    " OPTIONAL {?e <uri:p2> ?c } . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final ParsedQuery pq3 = parser.parseQuery(query3, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr te3 = pq3.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final SimpleExternalTupleSet pcj1 = new SimpleExternalTupleSet((Projection) te2);
    final SimpleExternalTupleSet pcj2 = new SimpleExternalTupleSet((Projection) te3);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj1);
    externalList.add(pcj2);
    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 52 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testJoinMatcherRejectsLeftJoinPcj.

@Test
public void testJoinMatcherRejectsLeftJoinPcj() throws Exception {
    final String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?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 . " + // 
    "  ?a <uri:talksTo> ?m . " + // 
    "  OPTIONAL {?a <http://www.w3.org/2000/01/rdf-schema#label> ?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 expected = 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(expected, te1);
}
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) Test(org.junit.Test)

Example 53 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testSegmentWithLargeUnion.

@Test
public void testSegmentWithLargeUnion() throws Exception {
    final String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " {?e <uri:p1> <uri:o1>. } UNION { " + // 
    "  ?e <uri:p0> ?l ." + // 
    "  ?l <uri:p5> <uri:o5> ." + " OPTIONAL{?l <uri:p4> <uri:o4>} ." + // 
    "  ?c<uri:p1> ?l ." + // 
    " OPTIONAL{ ?e <uri:p1> ?c } ." + // 
    " ?e <uri:p2> <uri:o2>. " + // 
    " ?c <uri:p3> <uri:o3> " + // 
    " }  . " + // 
    "  ?e <uri:p2> ?c . " + // 
    "  ?e <uri:p3> <uri:o2>  . " + // 
    "}";
    final 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 " + // 
    "}";
    final String query3 = // 
    "" + // 
    "SELECT ?h ?i" + // 
    "{" + // 
    "  ?h <uri:p2> ?i . " + // 
    "  ?h <uri:p3> <uri:o2>  . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final ParsedQuery pq3 = parser.parseQuery(query3, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr te3 = pq3.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(0));
    unMatchedNodes.add(remainingNodes.get(2));
    unMatchedNodes.add(remainingNodes.get(3));
    final SimpleExternalTupleSet pcj1 = new SimpleExternalTupleSet((Projection) te2);
    final SimpleExternalTupleSet pcj2 = new SimpleExternalTupleSet((Projection) te3);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj1);
    externalList.add(pcj2);
    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 54 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testSegmentWithUnion.

@Test
public void testSegmentWithUnion() throws Exception {
    final String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " {?e <uri:p1> <uri:o1>. } UNION { ?e a ?c. OPTIONAL {?e <uri:talksTo> ?l}. ?e <uri:p5> <uri:o4>. ?e <uri:p4> <uri:o3> }  . " + // 
    "  ?e <uri:p2> ?c . " + // 
    "  ?e <uri:p3> <uri:o2>  . " + // 
    "}";
    final String query2 = // 
    "" + // 
    "SELECT ?a ?b ?m" + // 
    "{" + // 
    " ?a <uri:p5> <uri:o4> ." + // 
    " ?a <uri:p4> <uri:o3> ." + // 
    "  OPTIONAL {?a <uri:talksTo> ?m} . " + // 
    "  ?a a ?b . " + // 
    "}";
    final String query3 = // 
    "" + // 
    "SELECT ?h ?i" + // 
    "{" + // 
    "  ?h <uri:p2> ?i . " + // 
    "  ?h <uri:p3> <uri:o2>  . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final ParsedQuery pq3 = parser.parseQuery(query3, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr te3 = pq3.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(0));
    final SimpleExternalTupleSet pcj1 = new SimpleExternalTupleSet((Projection) te2);
    final SimpleExternalTupleSet pcj2 = new SimpleExternalTupleSet((Projection) te3);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj1);
    externalList.add(pcj2);
    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 55 with SimpleExternalTupleSet

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

the class GeneralizedExternalProcessorTest method testThreeIndexQuery.

@Test
public void testThreeIndexQuery() throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q16, null);
    ParsedQuery pq2 = parser.parseQuery(q17, null);
    ParsedQuery pq3 = parser.parseQuery(q18, null);
    ParsedQuery pq4 = parser.parseQuery(q19, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
    SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup3);
    list.add(extTup1);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(6, indexSet.size());
    Set<TupleExpr> processedTups = Sets.newHashSet(iep.getIndexedTuples());
    Assert.assertEquals(17, processedTups.size());
    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    List<TupleExpr> plans = Lists.newArrayList(tep.getPlans(processedTups.iterator()));
    System.out.println("Size is " + plans.size());
    System.out.println("Possible indexed tuple plans are :");
    for (TupleExpr te : plans) {
        System.out.println(te);
    }
}
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) Projection(org.openrdf.query.algebra.Projection) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) 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