Search in sources :

Example 1 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest2 method testISNUMERIC.

@Test
public void testISNUMERIC() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q29, null);
    final ParsedQuery pq2 = parser2.parseQuery(q30, null);
    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();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(set.equals(qSet) && eTupSet.size() == 1);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) 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)

Example 2 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest2 method testFourIndexGeoFreeCompareFilterMix.

@Test
public void testFourIndexGeoFreeCompareFilterMix() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final SPARQLParser parser3 = new SPARQLParser();
    final SPARQLParser parser4 = new SPARQLParser();
    final SPARQLParser parser5 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q27, null);
    final ParsedQuery pq2 = parser2.parseQuery(q23, null);
    final ParsedQuery pq3 = parser3.parseQuery(q26, null);
    final ParsedQuery pq4 = parser4.parseQuery(q24, null);
    final ParsedQuery pq5 = parser5.parseQuery(q28, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Indexes are " + pq2.getTupleExpr() + " , " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr() + " and " + pq5.getTupleExpr());
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
    final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
    final SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet(new Projection(pq5.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup4);
    list.add(extTup1);
    list.add(extTup2);
    list.add(extTup3);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(set.equals(qSet));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) 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)

Example 3 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest2 method testVarRelableIndexSmaller.

@Test
public void testVarRelableIndexSmaller() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(queryString, null);
    final ParsedQuery pq2 = parser2.parseQuery(indexSparqlString, 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();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(qSet.containsAll(set) && set.size() != 0);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) 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)

Example 4 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest2 method testTwoIndexLargeQuery.

@Test
public void testTwoIndexLargeQuery() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final SPARQLParser parser3 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q11, null);
    final ParsedQuery pq2 = parser2.parseQuery(q7, null);
    final ParsedQuery pq3 = parser3.parseQuery(q12, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    list.add(extTup2);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(set.equals(qSet));
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) 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 5 with PCJOptimizer

use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.

the class PrecompJoinOptimizerTest2 method testGeoFilter.

@Test
public void testGeoFilter() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final String query1 = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  " + // 
    "SELECT ?a ?b ?c " + // 
    "{" + // 
    "  ?a a geo:Feature . " + // 
    "  ?b a geo:Point . " + // 
    "  ?b geo:asWKT ?c . " + // 
    "  FILTER(geof:sfWithin(?b, \"Polygon\")) " + // 
    "}";
    final String query2 = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "SELECT ?f ?g " + // 
    "{" + // 
    "  ?f a geo:Feature . " + // 
    "  ?g a geo:Point . " + // 
    "}";
    final ParsedQuery pq1 = parser1.parseQuery(query1, null);
    final ParsedQuery pq2 = parser2.parseQuery(query2, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final TupleExpr tup = pq1.getTupleExpr().clone();
    provider.setIndices(list);
    final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
    pcj.optimize(tup, null, null);
    final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
    final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
    final Set<StatementPattern> set = Sets.newHashSet();
    for (final QueryModelNode s : eTupSet) {
        set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
    }
    Assert.assertTrue(qSet.containsAll(set) && eTupSet.size() == 1);
}
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) 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

PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)48 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)46 TupleExpr (org.openrdf.query.algebra.TupleExpr)46 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)46 Test (org.junit.Test)44 ParsedQuery (org.openrdf.query.parser.ParsedQuery)44 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)42 ArrayList (java.util.ArrayList)33 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)22 Projection (org.openrdf.query.algebra.Projection)17 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)12 Configuration (org.apache.hadoop.conf.Configuration)10 IndexPlanValidator (org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator)4 URI (org.openrdf.model.URI)4 LiteralImpl (org.openrdf.model.impl.LiteralImpl)4 URIImpl (org.openrdf.model.impl.URIImpl)4 NodeCollector (org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector)2 AccumuloIndexSet (org.apache.rya.indexing.external.tupleSet.AccumuloIndexSet)2 MongoPcjIndexSetProvider (org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider)2