Search in sources :

Example 46 with ExternalTupleSet

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

the class ThreshholdPlanSelectorTest method twoIndexFilterTest.

@Test
public void twoIndexFilterTest() {
    String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c " + // 
    "{" + // 
    "  Filter(?f > \"5\")." + // 
    "  Filter(?e > \"5\")." + // 
    "  ?f a ?m ." + // 
    "  ?e a ?l ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "}";
    String q2 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    String q3 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    " Filter(?s > \"5\") ." + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    String q4 = // 
    "" + // 
    "SELECT ?f ?m ?d " + // 
    "{" + // 
    " Filter(?f > \"5\") ." + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    String q5 = // 
    "" + // 
    "SELECT ?e ?l ?c " + // 
    "{" + // 
    " Filter(?e > \"5\") ." + // 
    "  ?e a ?l ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    try {
        pq1 = parser.parseQuery(q1, null);
        pq2 = parser.parseQuery(q2, null);
        pq3 = parser.parseQuery(q3, null);
        pq4 = parser.parseQuery(q4, null);
        pq5 = parser.parseQuery(q5, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    List<ExternalTupleSet> list2 = new ArrayList<ExternalTupleSet>();
    list2.add(extTup3);
    list2.add(extTup4);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator().getPlans(iep.getIndexedTuples());
    IndexPlanValidator ipv = new IndexPlanValidator(false);
    Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans);
    ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr());
    TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .4, .8, .1, .1);
    NodeCollector nc = new NodeCollector();
    optimalTup.visit(nc);
    Assert.assertEquals(nc.getNodes().size(), list2.size());
    for (QueryModelNode e : nc.getNodes()) {
        Assert.assertTrue(list2.contains(e));
    }
}
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) Test(org.junit.Test)

Example 47 with ExternalTupleSet

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

the class VarConstantIndexListPrunerTest method testTwoIndexFilter2.

@Test
public void testTwoIndexFilter2() throws Exception {
    String q18 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  Filter(?s > 1 && ?t > 8)." + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    String q19 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  Filter(?s > 1)." + // 
    "  Filter(?t > 8)." + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q18, null);
    ParsedQuery pq2 = parser.parseQuery(q19, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    VarConstantIndexListPruner vci = new VarConstantIndexListPruner(pq1.getTupleExpr());
    List<ExternalTupleSet> processedIndexSet = vci.getRelevantIndices(list);
    Assert.assertTrue(processedIndexSet.isEmpty());
}
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) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 48 with ExternalTupleSet

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

the class ValidIndexCombinationGenerator method getValidCombos.

private Iterator<List<Integer>> getValidCombos(List<ExternalTupleSet> indexList) {
    final List<ExternalTupleSet> list = indexList;
    final int indexSize = list.size();
    final Iterator<List<Integer>> iter = getCombos(indexSize);
    return new Iterator<List<Integer>>() {

        private List<Integer> next = null;

        private boolean hasNextCalled = false;

        private boolean isEmpty = false;

        @Override
        public boolean hasNext() {
            if (!hasNextCalled && !isEmpty) {
                while (iter.hasNext()) {
                    List<Integer> tempNext = iter.next();
                    if (isValid(tempNext, list)) {
                        next = tempNext;
                        hasNextCalled = true;
                        return true;
                    }
                }
                isEmpty = true;
                return false;
            } else if (isEmpty) {
                return false;
            } else {
                return true;
            }
        }

        @Override
        public List<Integer> next() {
            if (hasNextCalled) {
                hasNextCalled = false;
                return next;
            } else if (isEmpty) {
                throw new NoSuchElementException();
            } else {
                if (this.hasNext()) {
                    hasNextCalled = false;
                    return next;
                } else {
                    throw new NoSuchElementException();
                }
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Cannot delete from iterator!");
        }
    };
}
Also used : Iterator(java.util.Iterator) List(java.util.List) NoSuchElementException(java.util.NoSuchElementException) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)

Example 49 with ExternalTupleSet

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

the class PCJOptimizerBenchmark method makeChainedPCJOptimizer.

private static PCJOptimizer makeChainedPCJOptimizer(final BenchmarkParams params) throws Exception {
    final Queue<String> varQueue = Lists.newLinkedList(variables);
    final SPARQLParser parser = new SPARQLParser();
    final List<ExternalTupleSet> indices = new ArrayList<>();
    // Create the first PCJ.
    final List<String> pcjVars = new ArrayList<>();
    pcjVars.add(varQueue.remove());
    pcjVars.add(varQueue.remove());
    for (int spI = 1; spI < params.getPCJSPCount(); spI++) {
        pcjVars.add(varQueue.remove());
    }
    String pcjSparql = buildChainedSPARQL(pcjVars);
    Projection projection = (Projection) parser.parseQuery(pcjSparql, null).getTupleExpr();
    indices.add(new SimpleExternalTupleSet(projection));
    // Add the rest of the PCJs.
    for (int pcjI = 1; pcjI < params.getNumPCJS(); pcjI++) {
        // Remove the previous PCJs first variable.
        pcjVars.remove(0);
        // And add a new one to the end of it.
        pcjVars.add(varQueue.remove());
        // Build the index.
        pcjSparql = buildChainedSPARQL(pcjVars);
        projection = (Projection) parser.parseQuery(pcjSparql, null).getTupleExpr();
        indices.add(new SimpleExternalTupleSet(projection));
    }
    // Create the optimizer.
    return new PCJOptimizer(indices, false, new AccumuloIndexSetProvider(new Configuration()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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)

Example 50 with ExternalTupleSet

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

the class PCJOptimizerBenchmark method makeUnchainedPCJOptimizer.

private static PCJOptimizer makeUnchainedPCJOptimizer(final BenchmarkParams params) throws Exception {
    final Queue<String> varQueue = Lists.newLinkedList(variables);
    final SPARQLParser parser = new SPARQLParser();
    final List<ExternalTupleSet> indices = new ArrayList<>();
    // Create the first PCJ.
    final List<String> pcjVars = new ArrayList<>();
    pcjVars.add(varQueue.remove());
    pcjVars.add(varQueue.remove());
    for (int spI = 1; spI < params.getPCJSPCount(); spI++) {
        pcjVars.add(varQueue.remove());
        pcjVars.add(varQueue.remove());
    }
    String pcjSparql = buildUnchainedSPARQL(pcjVars);
    Projection projection = (Projection) parser.parseQuery(pcjSparql, null).getTupleExpr();
    indices.add(new SimpleExternalTupleSet(projection));
    // Add the rest of the PCJs.
    for (int pcjI = 1; pcjI < params.getNumPCJS(); pcjI++) {
        // Remove the previous PCJs first variable.
        pcjVars.remove(0);
        pcjVars.remove(0);
        // And add a new one to the end of it.
        pcjVars.add(varQueue.remove());
        pcjVars.add(varQueue.remove());
        // Build the index.
        pcjSparql = buildUnchainedSPARQL(pcjVars);
        projection = (Projection) parser.parseQuery(pcjSparql, null).getTupleExpr();
        indices.add(new SimpleExternalTupleSet(projection));
    }
    // Create the optimizer.
    return new PCJOptimizer(indices, false, new AccumuloIndexSetProvider(new Configuration()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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)

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