Search in sources :

Example 21 with ExternalTupleSet

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

the class PCJOptionalTestIT method testSimpleOptionalTest1.

@Test
public void testSimpleOptionalTest1() throws Exception {
    final String query = // 
    "" + // 
    "SELECT ?u ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  OPTIONAL{?t <http://www.w3.org/2000/01/rdf-schema#label> ?u } ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq1.getTupleExpr().clone());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup1);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, new AccumuloIndexSetProvider(new Configuration(), list));
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    final List<QueryModelNode> qNodes = nc.getNodes();
    Assert.assertEquals(qNodes.size(), optTupNodes.size());
    for (final QueryModelNode node : qNodes) {
        Assert.assertTrue(optTupNodes.contains(node));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) 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) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) NodeCollector(org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector) Test(org.junit.Test)

Example 22 with ExternalTupleSet

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

the class IndexedExecutionPlanGeneratorTest method testThreeSingleNodeIndex.

@Test
public void testThreeSingleNodeIndex() throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q19, null);
    ParsedQuery pq2 = parser.parseQuery(q20, null);
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(3, indexSet.size());
    Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
    int size = 0;
    while (processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        processedTups.next();
        size++;
    }
    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(3, size);
}
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) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 23 with ExternalTupleSet

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

the class IndexedExecutionPlanGeneratorTest 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);
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(6, indexSet.size());
    Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
    int size = 0;
    while (processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        processedTups.next();
        size++;
    }
    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(9, size);
}
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) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 24 with ExternalTupleSet

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

the class IndexedExecutionPlanGeneratorTest method testThrowsException2.

@Test
public void testThrowsException2() throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q19, null);
    ParsedQuery pq2 = parser.parseQuery(q20, null);
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(3, indexSet.size());
    Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
    processedTups.next();
    processedTups.next();
    processedTups.next();
    boolean exceptionThrown = false;
    try {
        processedTups.next();
    } catch (NoSuchElementException e) {
        exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
}
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) NoSuchElementException(java.util.NoSuchElementException) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 25 with ExternalTupleSet

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

the class IndexedExecutionPlanGeneratorTest method testThreeIndexQueryFilter.

@Test
public void testThreeIndexQueryFilter() throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q22, null);
    ParsedQuery pq2 = parser.parseQuery(q7, null);
    ParsedQuery pq3 = parser.parseQuery(q21, null);
    ParsedQuery pq4 = parser.parseQuery(q23, null);
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    list.add(extTup3);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(5, indexSet.size());
    Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
    int size = 0;
    while (processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        TupleExpr te = processedTups.next();
        System.out.println(te);
        size++;
    }
    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(10, size);
}
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) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) 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