Search in sources :

Example 16 with SimpleExternalTupleSet

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

the class PCJOptimizerTest method testSwitchTwoBoundVars.

@Test
public void testSwitchTwoBoundVars() throws Exception {
    final String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c " + // 
    "{" + // 
    "  ?a <uri:p0> ?c ." + // 
    "  ?c <uri:p5> <uri:o5> ." + " OPTIONAL{?c <uri:p4> <uri:o4>} ." + // 
    " ?b<uri:p1> ?c ." + // 
    " OPTIONAL{ ?a <uri:p1> ?b } ." + // 
    " ?a <uri:p2> <uri:o2>. " + // 
    " ?b <uri:p3> <uri:o3> " + // 
    "}";
    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 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 unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(1));
    unMatchedNodes.add(remainingNodes.get(2));
    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(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 17 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet 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 18 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet 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 19 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet 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 20 with SimpleExternalTupleSet

use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet 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)

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