Search in sources :

Example 71 with ExternalTupleSet

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

the class IndexedExecutionPlanGeneratorTest method testThrowsException1.

@Test
public void testThrowsException1() 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();
    boolean exceptionThrown = false;
    try {
        processedTups.remove();
    } catch (UnsupportedOperationException 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) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) Test(org.junit.Test)

Example 72 with ExternalTupleSet

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

the class ValidIndexCombinationGeneratorTest method overlappingFilterIndex.

@Test
public void overlappingFilterIndex() {
    String q5 = // 
    "" + // 
    "SELECT ?s ?t " + // 
    "{" + // 
    "  ?s a \"Person\" ." + // 
    "  ?t a \"Student\" ." + // 
    "}";
    String q4 = // 
    "" + // 
    "SELECT ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?s <uri:talksTo> ?t . " + // 
    "}";
    String q3 = // 
    "" + // 
    "SELECT ?s ?t  " + // 
    "{" + // 
    "  Filter(?s > 5). " + // 
    "  ?s a ?t ." + // 
    "  ?s <uri:talksTo> ?t . " + // 
    "}";
    String q2 = // 
    "" + // 
    "SELECT ?s ?t  " + // 
    "{" + // 
    "  Filter(?s > 5). " + // 
    "  ?s a \"Person\" ." + // 
    "  ?t a \"Student\" ." + // 
    "}";
    String q1 = // 
    "" + // 
    "SELECT  ?s ?t  " + // 
    "{" + // 
    "  Filter(?s > 5). " + // 
    "  ?s a ?t ." + // 
    "  ?s <uri:talksTo> ?t . " + // 
    "  ?s a \"Person\" ." + // 
    "  ?t a \"Student\" ." + // 
    "}";
    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.add(extTup3);
    list.add(extTup4);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(4, indexSet.size());
    ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
    Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet));
    int size = 0;
    while (eSet.hasNext()) {
        size++;
        Assert.assertTrue(eSet.hasNext());
        List<ExternalTupleSet> eList = eSet.next();
    }
    Assert.assertTrue(!eSet.hasNext());
    Assert.assertEquals(7, size);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) MalformedQueryException(org.openrdf.query.MalformedQueryException) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 73 with ExternalTupleSet

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

the class ValidIndexCombinationGeneratorTest method largeQuerySixteenIndexTest.

@Test
public void largeQuerySixteenIndexTest() {
    String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?e a ?l ." + // 
    "  ?n a ?o ." + // 
    "  ?a a ?h ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ." + // 
    "  ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "  ?p <uri:talksTo> ?n . " + // 
    "  ?r <uri:talksTo> ?a . " + // 
    "}";
    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 ?d ?f ?g " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "  ?d a ?f ." + // 
    "  ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ." + // 
    "  ?g <uri:talksTo> ?d . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    try {
        pq1 = parser.parseQuery(q1, null);
        pq2 = parser.parseQuery(q2, null);
        pq3 = parser.parseQuery(q3, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    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(16, indexSet.size());
    ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
    Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet));
    int size = 0;
    while (eSet.hasNext()) {
        size++;
        Assert.assertTrue(eSet.hasNext());
        eSet.next();
    }
    Assert.assertTrue(!eSet.hasNext());
    Assert.assertEquals(75, size);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) MalformedQueryException(org.openrdf.query.MalformedQueryException) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 74 with ExternalTupleSet

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

the class ValidIndexCombinationGeneratorTest method largeQueryFourtyIndexTest.

@Test
public void largeQueryFourtyIndexTest() {
    String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?e a ?l ." + // 
    "  ?n a ?o ." + // 
    "  ?a a ?h ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ." + // 
    "  ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "  ?p <uri:talksTo> ?n . " + // 
    "  ?r <uri:talksTo> ?a . " + // 
    "}";
    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 ?d ?f ?g " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "  ?d a ?f ." + // 
    "  ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ." + // 
    "  ?g <uri:talksTo> ?d . " + // 
    "}";
    String q4 = // 
    "" + // 
    "SELECT  ?s ?t ?u ?d ?f ?g ?a ?b ?c" + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "  ?d a ?f ." + // 
    "  ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ." + // 
    "  ?g <uri:talksTo> ?d . " + // 
    "  ?a a ?b ." + // 
    "  ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?c <uri:talksTo> ?a . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    try {
        pq1 = parser.parseQuery(q1, null);
        pq2 = parser.parseQuery(q2, null);
        pq3 = parser.parseQuery(q3, null);
        pq4 = parser.parseQuery(q4, 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());
    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(40, indexSet.size());
    ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
    Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet));
    int size = 0;
    while (eSet.hasNext()) {
        size++;
        Assert.assertTrue(eSet.hasNext());
        eSet.next();
    }
    Assert.assertTrue(!eSet.hasNext());
    Assert.assertEquals(123, size);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) MalformedQueryException(org.openrdf.query.MalformedQueryException) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 75 with ExternalTupleSet

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

the class ValidIndexCombinationGeneratorTest method singleIndex.

@Test
public void singleIndex() {
    String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?f <uri:hangOutWith> ?m ." + // 
    "  ?m <uri:hangOutWith> ?d ." + // 
    "  ?f <uri:associatesWith> ?m ." + // 
    "  ?m <uri:associatesWith> ?d ." + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    SimpleExternalTupleSet extTup1 = null;
    try {
        pq1 = parser.parseQuery(q1, null);
        extTup1 = new SimpleExternalTupleSet((Projection) pq1.getTupleExpr());
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    List<ExternalTupleSet> indexList = Lists.newArrayList();
    indexList.add(extTup1);
    ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
    Iterator<List<ExternalTupleSet>> combos = vic.getValidIndexCombos(indexList);
    int size = 0;
    while (combos.hasNext()) {
        combos.hasNext();
        size++;
        combos.next();
        combos.hasNext();
    }
    Assert.assertTrue(!combos.hasNext());
    Assert.assertEquals(1, size);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) MalformedQueryException(org.openrdf.query.MalformedQueryException) List(java.util.List) ArrayList(java.util.ArrayList) 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