Search in sources :

Example 26 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class JoinSegment method clone.

@Override
public JoinSegment<T> clone() {
    List<QueryModelNode> order = new ArrayList<>();
    for (QueryModelNode node : orderedNodes) {
        order.add(node.clone());
    }
    Set<QueryModelNode> unorder = Sets.newHashSet(order);
    Map<ValueExpr, Filter> map = new HashMap<>();
    for (ValueExpr expr : conditionMap.keySet()) {
        map.put(expr.clone(), conditionMap.get(expr).clone());
    }
    return new JoinSegment<T>(unorder, order, map);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) Filter(org.openrdf.query.algebra.Filter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode)

Example 27 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class AbstractQuerySegment method getQuery.

/**
 * @return - a TupleExpr representing this JoinSegment
 */
@Override
public TupleExprAndNodes getQuery() {
    List<QueryModelNode> nodeCopy = new ArrayList<>();
    for (QueryModelNode q : orderedNodes) {
        if (!(q instanceof ValueExpr)) {
            nodeCopy.add(q.clone());
        }
    }
    QueryNodesToTupleExpr qnt = new QueryNodesToTupleExpr(nodeCopy, getFilters());
    return qnt.getTupleAndNodes();
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode)

Example 28 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class PrecompJoinOptimizerTest method testThreeIndex.

@Test
public void testThreeIndex() throws Exception {
    final String q7 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final String q8 = // 
    "" + // 
    "SELECT ?e ?l ?c " + // 
    "{" + // 
    "  ?e a ?l ." + // 
    "  ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + // 
    "  ?c <uri:talksTo> ?e . " + // 
    "}";
    final String q9 = // 
    "" + // 
    "SELECT ?f ?m ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    final String q15 = // 
    "" + // 
    "SELECT ?f ?m ?d ?e ?l ?c " + // 
    "{" + // 
    "  ?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 ." + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(q15, null);
    final ParsedQuery pq2 = parser.parseQuery(q7, null);
    final ParsedQuery pq3 = parser.parseQuery(q8, null);
    final ParsedQuery pq4 = parser.parseQuery(q9, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup2);
    optTupNodes.add(extTup3);
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    Assert.assertEquals(nc.qNodes.size(), optTupNodes.size());
    for (final QueryModelNode node : nc.qNodes) {
        Assert.assertTrue(optTupNodes.contains(node));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) 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) Test(org.junit.Test)

Example 29 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class PrecompJoinOptimizerTest method twoFourIndexWithFilterTest.

@Test
public void twoFourIndexWithFilterTest() throws Exception {
    final 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 ." + // 
    "}";
    final String q2 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final 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 . " + // 
    "}";
    final 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 . " + // 
    "}";
    final 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 . " + // 
    "}";
    final 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 (final Exception e) {
        e.printStackTrace();
    }
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    final SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    final List<ExternalTupleSet> list2 = new ArrayList<ExternalTupleSet>();
    list2.add(extTup3);
    list2.add(extTup4);
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    System.out.println(te);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    Assert.assertEquals(nc.qNodes.size(), list2.size());
    for (final QueryModelNode e : nc.qNodes) {
        Assert.assertTrue(list2.contains(e));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) 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) Test(org.junit.Test)

Example 30 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class PrecompJoinOptimizerVarToConstTest method testFreeTestIndexFunction.

@Test
public void testFreeTestIndexFunction() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q22, null);
    final ParsedQuery pq2 = parser2.parseQuery(q24, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Index is " + pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
    pcj.optimize(tup, null, null);
    System.out.println("Processed query is " + tup);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    Assert.assertEquals(2, eTupSet.size());
    for (final QueryModelNode s : eTupSet) {
        final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
        set.addAll(tempSet);
    }
    Assert.assertTrue(qSet.containsAll(set));
}
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) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Aggregations

QueryModelNode (org.openrdf.query.algebra.QueryModelNode)98 TupleExpr (org.openrdf.query.algebra.TupleExpr)74 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)63 ParsedQuery (org.openrdf.query.parser.ParsedQuery)63 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)62 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)56 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)48 StatementPattern (org.openrdf.query.algebra.StatementPattern)33 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)27 HashSet (java.util.HashSet)26 Projection (org.openrdf.query.algebra.Projection)23 Filter (org.openrdf.query.algebra.Filter)15 LeftJoin (org.openrdf.query.algebra.LeftJoin)12 Join (org.openrdf.query.algebra.Join)11 ValueExpr (org.openrdf.query.algebra.ValueExpr)11 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)8 Configuration (org.apache.hadoop.conf.Configuration)7 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)7 BatchWriter (org.apache.accumulo.core.client.BatchWriter)6