Search in sources :

Example 56 with Projection

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

the class GeneralizedExternalProcessorTest 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);
    ParsedQuery pq4 = parser.parseQuery(q19, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
    SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup3);
    list.add(extTup1);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
    Assert.assertEquals(6, indexSet.size());
    Set<TupleExpr> processedTups = Sets.newHashSet(iep.getIndexedTuples());
    Assert.assertEquals(17, processedTups.size());
    TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
    List<TupleExpr> plans = Lists.newArrayList(tep.getPlans(processedTups.iterator()));
    System.out.println("Size is " + plans.size());
    System.out.println("Possible indexed tuple plans are :");
    for (TupleExpr te : plans) {
        System.out.println(te);
    }
}
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) Projection(org.openrdf.query.algebra.Projection) 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 57 with Projection

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

the class GeneralizedExternalProcessorTest 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);
    System.out.println("Query is " + pq1.getTupleExpr());
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new 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());
    Set<TupleExpr> processedTups = Sets.newHashSet(iep.getIndexedTuples());
    Assert.assertEquals(5, processedTups.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) Projection(org.openrdf.query.algebra.Projection) 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 58 with Projection

use of org.openrdf.query.algebra.Projection 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)

Example 59 with Projection

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

the class TupleExecutionPlanGenerator method getPlans.

private List<TupleExpr> getPlans(final TupleExpr te) {
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    final Set<QueryModelNode> nodeSet = nc.getNodeSet();
    final List<Filter> filterList = nc.getFilterSet();
    final Projection projection = nc.getProjection().clone();
    final List<TupleExpr> queryPlans = Lists.newArrayList();
    final Collection<List<QueryModelNode>> plans = Collections2.permutations(nodeSet);
    for (final List<QueryModelNode> p : plans) {
        if (p.size() == 0) {
            throw new IllegalArgumentException("Tuple must contain at least one node!");
        } else if (p.size() == 1) {
            queryPlans.add(te);
        } else {
            queryPlans.add(buildTuple(p, filterList, projection));
        }
    }
    return queryPlans;
}
Also used : Filter(org.openrdf.query.algebra.Filter) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) Projection(org.openrdf.query.algebra.Projection) List(java.util.List) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Example 60 with Projection

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

the class TupleExecutionPlanGenerator method buildTuple.

private TupleExpr buildTuple(final List<QueryModelNode> nodes, final List<Filter> filters, final Projection projection) {
    final Projection proj = projection.clone();
    Join join = null;
    join = new Join((TupleExpr) nodes.get(0).clone(), (TupleExpr) nodes.get(1).clone());
    for (int i = 2; i < nodes.size(); i++) {
        join = new Join(join, (TupleExpr) nodes.get(i).clone());
    }
    if (filters.size() == 0) {
        proj.setArg(join);
        return proj;
    } else {
        TupleExpr queryPlan = join;
        for (final Filter f : filters) {
            final Filter filt = f.clone();
            filt.setArg(queryPlan);
            queryPlan = filt;
        }
        proj.setArg(queryPlan);
        return proj;
    }
}
Also used : Filter(org.openrdf.query.algebra.Filter) Projection(org.openrdf.query.algebra.Projection) Join(org.openrdf.query.algebra.Join) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Aggregations

Projection (org.openrdf.query.algebra.Projection)76 Test (org.junit.Test)64 StatementPattern (org.openrdf.query.algebra.StatementPattern)41 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)37 ParsedQuery (org.openrdf.query.parser.ParsedQuery)34 TupleExpr (org.openrdf.query.algebra.TupleExpr)33 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)27 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)27 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)24 Var (org.openrdf.query.algebra.Var)24 ArrayList (java.util.ArrayList)23 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)23 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)22 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)17 Join (org.openrdf.query.algebra.Join)15 HashSet (java.util.HashSet)14 Union (org.openrdf.query.algebra.Union)10 Resource (org.openrdf.model.Resource)9 MultiProjection (org.openrdf.query.algebra.MultiProjection)9 HashMap (java.util.HashMap)8