Search in sources :

Example 51 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser 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 52 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser 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)

Example 53 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class IndexedExecutionPlanGeneratorTest method testTwoIndexLargeQuery.

@Test
public void testTwoIndexLargeQuery() throws Exception {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q15, null);
    ParsedQuery pq2 = parser.parseQuery(q7, null);
    ParsedQuery pq3 = parser.parseQuery(q12, 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(4, 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(5, 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 54 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class TupleExecutionPlanGeneratorTest method testThreeNodeOrderFilter.

@Test
public void testThreeNodeOrderFilter() {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    ParsedQuery pq6 = null;
    ParsedQuery pq7 = null;
    try {
        pq1 = parser.parseQuery(q9, null);
        pq2 = parser.parseQuery(q10, null);
        pq3 = parser.parseQuery(q11, null);
        pq4 = parser.parseQuery(q12, null);
        pq5 = parser.parseQuery(q13, null);
        pq6 = parser.parseQuery(q14, null);
        pq7 = parser.parseQuery(q15, null);
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(pq1.getTupleExpr());
    Set<TupleExpr> tupSet = Sets.newHashSet();
    tupSet.add(pq7.getTupleExpr());
    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    Iterator<TupleExpr> processedTups = tep.getPlans(tupSet.iterator());
    List<TupleExpr> processedTupList = Lists.newArrayList();
    int size = 0;
    while (processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        TupleExpr te = processedTups.next();
        processedTupList.add(te);
        System.out.println("Processed tups are " + te);
        size++;
    }
    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(6, size);
    Assert.assertTrue(processedTupList.get(5).equals(pq1.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(0).equals(pq2.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(2).equals(pq3.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(4).equals(pq4.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(1).equals(pq5.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(3).equals(pq6.getTupleExpr()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) MalformedQueryException(org.openrdf.query.MalformedQueryException) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 55 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class TupleExecutionPlanGeneratorTest method testThreeNodeOrder.

@Test
public void testThreeNodeOrder() {
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = null;
    ParsedQuery pq2 = null;
    ParsedQuery pq3 = null;
    ParsedQuery pq4 = null;
    ParsedQuery pq5 = null;
    ParsedQuery pq6 = 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);
        pq6 = parser.parseQuery(q6, null);
    } catch (MalformedQueryException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Set<TupleExpr> tupSet = Sets.newHashSet();
    tupSet.add(pq1.getTupleExpr());
    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    Iterator<TupleExpr> processedTups = tep.getPlans(tupSet.iterator());
    List<TupleExpr> processedTupList = Lists.newArrayList();
    int size = 0;
    while (processedTups.hasNext()) {
        Assert.assertTrue(processedTups.hasNext());
        processedTupList.add(processedTups.next());
        size++;
    }
    Assert.assertTrue(!processedTups.hasNext());
    Assert.assertEquals(6, size);
    Assert.assertTrue(processedTupList.get(5).equals(pq1.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(0).equals(pq2.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(2).equals(pq3.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(4).equals(pq4.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(1).equals(pq5.getTupleExpr()));
    Assert.assertTrue(processedTupList.get(3).equals(pq6.getTupleExpr()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) MalformedQueryException(org.openrdf.query.MalformedQueryException) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Aggregations

SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)265 ParsedQuery (org.openrdf.query.parser.ParsedQuery)249 Test (org.junit.Test)212 TupleExpr (org.openrdf.query.algebra.TupleExpr)162 ArrayList (java.util.ArrayList)100 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)99 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 StatementPattern (org.openrdf.query.algebra.StatementPattern)82 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)62 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)45 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)43 RyaURI (org.apache.rya.api.domain.RyaURI)42 BindingSet (org.openrdf.query.BindingSet)41 RyaStatement (org.apache.rya.api.domain.RyaStatement)39 Projection (org.openrdf.query.algebra.Projection)37 RyaType (org.apache.rya.api.domain.RyaType)35 HashSet (java.util.HashSet)27 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)20 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19