use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet 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));
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexCrossProduct3.
@Test
public void testEvaluateTwoIndexCrossProduct3() 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(ais1);
index.add(ais2);
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.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexDiffVars3.
@Test
public void testEvaluateTwoIndexDiffVars3() throws Exception {
final String indexSparqlString = //
"" + //
"SELECT ?pig ?dog ?chicken " + //
"{" + //
" ?dog a ?chicken . " + //
" ?dog <http://www.w3.org/2000/01/rdf-schema#label> ?pig " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?fish ?ant ?turkey " + //
"{" + //
" ?fish <uri:talksTo> ?turkey . " + //
" ?turkey <http://www.w3.org/2000/01/rdf-schema#label> ?ant " + //
"}";
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(ais1);
index.add(ais2);
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.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder4.
@Test
public void testEvaluateTwoIndexTwoVarOrder4() throws Exception {
final String indexSparqlString = //
"" + //
"SELECT ?e ?c ?l " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?e ?o ?l " + //
"{" + //
" ?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(ais1);
index.add(ais2);
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(false, ipv.isValid(tup));
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class ThreshholdPlanSelectorTest method largeQueryFourtyIndexTest.
@Test
public void largeQueryFourtyIndexTest() {
String q1 = //
"" + //
"SELECT ?f ?m ?d ?e ?l ?c ?n ?o ?p ?a ?h ?r " + //
"{" + //
" ?f a ?m ." + //
" ?e a ?l ." + //
" ?n a ?o ." + //
" ?a a ?h ." + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ." + //
" ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ." + //
" ?d <uri:talksTo> ?f . " + //
" ?c <uri:talksTo> ?e . " + //
" ?p <uri:talksTo> ?n . " + //
" ?r <uri:talksTo> ?a . " + //
"}";
String q2 = //
"" + //
"SELECT ?s ?t ?u " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
"}";
String q3 = //
"" + //
"SELECT ?s ?t ?u ?d ?f ?g " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
" ?d a ?f ." + //
" ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ." + //
" ?g <uri:talksTo> ?d . " + //
"}";
String q4 = //
"" + //
"SELECT ?s ?t ?u ?d ?f ?g ?a ?b ?c" + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
" ?d a ?f ." + //
" ?f <http://www.w3.org/2000/01/rdf-schema#label> ?g ." + //
" ?g <uri:talksTo> ?d . " + //
" ?a a ?b ." + //
" ?b <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + //
" ?c <uri:talksTo> ?a . " + //
"}";
String q5 = //
"" + //
"SELECT ?f ?m ?d ?a ?h ?r " + //
"{" + //
" ?f a ?m ." + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?d <uri:talksTo> ?f . " + //
" ?a a ?h ." + //
" ?h <http://www.w3.org/2000/01/rdf-schema#label> ?r ." + //
" ?r <uri:talksTo> ?a . " + //
"}";
String q6 = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" ?e a ?l ." + //
" ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + //
" ?c <uri:talksTo> ?e . " + //
"}";
String q7 = //
"" + //
"SELECT ?n ?o ?p " + //
"{" + //
" ?n a ?o ." + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?p ." + //
" ?p <uri:talksTo> ?n . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = null;
ParsedQuery pq2 = null;
ParsedQuery pq3 = null;
ParsedQuery pq4 = null;
ParsedQuery pq5 = null;
ParsedQuery pq6 = null;
ParsedQuery pq7 = 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);
pq6 = parser.parseQuery(q6, null);
pq7 = parser.parseQuery(q7, null);
} catch (Exception e) {
e.printStackTrace();
}
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
SimpleExternalTupleSet extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr());
SimpleExternalTupleSet extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup2);
list.add(extTup1);
list.add(extTup3);
List<ExternalTupleSet> list2 = new ArrayList<ExternalTupleSet>();
list2.add(extTup4);
list2.add(extTup5);
list2.add(extTup6);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator().getPlans(iep.getIndexedTuples());
IndexPlanValidator ipv = new IndexPlanValidator(false);
Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans);
ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr());
TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .4, .8, .1, .1);
NodeCollector nc = new NodeCollector();
optimalTup.visit(nc);
}
Aggregations