use of org.apache.rya.indexing.pcj.matching.PCJOptimizer 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));
}
}
use of org.apache.rya.indexing.pcj.matching.PCJOptimizer 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));
}
use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.
the class PrecompJoinOptimizerVarToConstTest method testContextFilterFourIndex.
@Test
public void testContextFilterFourIndex() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser3 = new SPARQLParser();
final SPARQLParser parser4 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q19, null);
final ParsedQuery pq3 = parser3.parseQuery(q17, null);
final ParsedQuery pq4 = parser4.parseQuery(q18, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Indexes are " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr());
final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup3);
list.add(extTup2);
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);
Assert.assertEquals(2, eTupSet.size());
final Set<StatementPattern> set = Sets.newHashSet();
for (final QueryModelNode s : eTupSet) {
final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
set.addAll(tempSet);
}
Assert.assertTrue(qSet.containsAll(set));
}
use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder6.
@Test
public void testEvaluateTwoIndexTwoVarOrder6() throws Exception {
final String indexSparqlString = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?l ?e ?o " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String queryString = //
"" + //
"SELECT ?e ?c ?l ?o " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final SPARQLParser sp = new SPARQLParser();
final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null);
final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
final List<ExternalTupleSet> index = Lists.newArrayList();
final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection) index1.getTupleExpr());
final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection) index2.getTupleExpr());
index.add(ais2);
index.add(ais1);
final ParsedQuery pq = sp.parseQuery(queryString, null);
final TupleExpr tup = pq.getTupleExpr().clone();
provider.setIndices(index);
final PCJOptimizer pcj = new PCJOptimizer(index, false, provider);
pcj.optimize(tup, null, null);
final IndexPlanValidator ipv = new IndexPlanValidator(false);
Assert.assertEquals(true, ipv.isValid(tup));
}
use of org.apache.rya.indexing.pcj.matching.PCJOptimizer in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexCrossProduct1.
@Test
public void testEvaluateTwoIndexCrossProduct1() throws Exception {
final String indexSparqlString = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?e ?l ?o " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String queryString = //
"" + //
"SELECT ?e ?c ?l ?o ?f ?g " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?f <uri:talksTo> ?g . " + //
"}";
final SPARQLParser sp = new SPARQLParser();
final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null);
final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
final List<ExternalTupleSet> index = Lists.newArrayList();
final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection) index1.getTupleExpr());
final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection) index2.getTupleExpr());
index.add(ais2);
index.add(ais1);
final ParsedQuery pq = sp.parseQuery(queryString, null);
final TupleExpr tup = pq.getTupleExpr().clone();
provider.setIndices(index);
final PCJOptimizer pcj = new PCJOptimizer(index, false, provider);
pcj.optimize(tup, null, null);
final IndexPlanValidator ipv = new IndexPlanValidator(true);
Assert.assertEquals(false, ipv.isValid(tup));
}
Aggregations