use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class ThreshholdPlanSelectorTest method testSingleIndex2.
@Test
public void testSingleIndex2() throws Exception {
String q1 = //
"" + //
"SELECT ?f ?m ?d ?e ?l ?c " + //
"{" + //
" ?f a ?m ." + //
" ?c a ?l ." + //
" ?d <uri:talksTo> ?f . " + //
" ?e <uri:talksTo> ?c . " + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ." + //
" ?m <uri:talksTo> ?e . " + //
"}";
String q2 = //
"" + //
"SELECT ?u ?s ?t " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
"}";
String q3 = //
"" + //
"SELECT ?e ?c ?l " + //
"{" + //
" ?c a ?l ." + //
" ?l <http://www.w3.org/2000/01/rdf-schema#label> ?e ." + //
" ?e <uri:talksTo> ?c . " + //
"}";
String q4 = //
"" + //
"SELECT ?d ?f ?m " + //
"{" + //
" ?f a ?m ." + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?d <uri:talksTo> ?f . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q1, null);
ParsedQuery pq2 = parser.parseQuery(q2, null);
ParsedQuery pq3 = parser.parseQuery(q3, null);
ParsedQuery pq4 = parser.parseQuery(q4, null);
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
List<StatementPattern> spList = StatementPatternCollector.process(pq1.getTupleExpr());
List<QueryModelNode> optTupNodes = Lists.newArrayList();
optTupNodes.add(extTup3);
optTupNodes.add(spList.get(6));
optTupNodes.add(extTup2);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator().getPlans(iep.getIndexedTuples());
IndexPlanValidator ipv = new IndexPlanValidator(true);
Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans);
ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr());
TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .4, .7, .1, .2);
NodeCollector nc = new NodeCollector();
optimalTup.visit(nc);
List<QueryModelNode> qNodes = nc.getNodes();
Assert.assertTrue(qNodes.equals(optTupNodes));
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class ThreshholdPlanSelectorTest method testTwoIndex.
@Test
public void testTwoIndex() throws Exception {
String q1 = //
"" + //
"SELECT ?f ?m ?d ?h ?i " + //
"{" + //
" ?f a ?m ." + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?d <uri:talksTo> ?f . " + //
" ?d <uri:hangOutWith> ?f ." + //
" ?f <uri:hangOutWith> ?h ." + //
" ?f <uri:associatesWith> ?i ." + //
" ?i <uri:associatesWith> ?h ." + //
"}";
String q2 = //
"" + //
"SELECT ?t ?s ?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 " + //
"{" + //
" ?s <uri:hangOutWith> ?t ." + //
" ?t <uri:hangOutWith> ?u ." + //
"}";
String q4 = //
"" + //
"SELECT ?s ?t ?u " + //
"{" + //
" ?s <uri:associatesWith> ?t ." + //
" ?t <uri:associatesWith> ?u ." + //
"}";
String q5 = //
"" + //
"SELECT ?m ?f ?d " + //
"{" + //
" ?f a ?m ." + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?d <uri:talksTo> ?f . " + //
"}";
String q6 = //
"" + //
"SELECT ?d ?f ?h " + //
"{" + //
" ?d <uri:hangOutWith> ?f ." + //
" ?f <uri:hangOutWith> ?h ." + //
"}";
String q7 = //
"" + //
"SELECT ?f ?i ?h " + //
"{" + //
" ?f <uri:associatesWith> ?i ." + //
" ?i <uri:associatesWith> ?h ." + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q1, null);
ParsedQuery pq2 = parser.parseQuery(q2, null);
ParsedQuery pq3 = parser.parseQuery(q3, null);
ParsedQuery pq4 = parser.parseQuery(q4, null);
ParsedQuery pq5 = parser.parseQuery(q5, null);
ParsedQuery pq6 = parser.parseQuery(q6, null);
ParsedQuery pq7 = parser.parseQuery(q7, null);
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<QueryModelNode> optTupNodes = Lists.newArrayList();
optTupNodes.add(extTup4);
optTupNodes.add(extTup6);
optTupNodes.add(extTup5);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator().getPlans(iep.getIndexedTuples());
IndexPlanValidator ipv = new IndexPlanValidator(true);
Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans);
ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr());
TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .2, .6, .4, 0);
NodeCollector nc = new NodeCollector();
optimalTup.visit(nc);
List<QueryModelNode> qNodes = nc.getNodes();
Assert.assertTrue(qNodes.equals(optTupNodes));
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class VarConstantIndexListPrunerTest method testTwoIndexFilter1.
@Test
public void testTwoIndexFilter1() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q15, null);
ParsedQuery pq2 = parser.parseQuery(q16, null);
ParsedQuery pq3 = parser.parseQuery(q17, null);
System.out.println("Query is " + pq1.getTupleExpr());
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
list.add(extTup2);
VarConstantIndexListPruner vci = new VarConstantIndexListPruner(pq1.getTupleExpr());
List<ExternalTupleSet> processedIndexSet = vci.getRelevantIndices(list);
System.out.println("Relevant indexes are: ");
for (ExternalTupleSet e : processedIndexSet) {
System.out.println(e);
}
Set<ExternalTupleSet> indexSet = Sets.newHashSet();
indexSet.add(extTup2);
Assert.assertTrue(Sets.intersection(indexSet, Sets.<ExternalTupleSet>newHashSet(processedIndexSet)).equals(Sets.<ExternalTupleSet>newHashSet(processedIndexSet)));
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class VarConstantIndexListPrunerTest method testTwoIndexLargeQuery.
@Test
public void testTwoIndexLargeQuery() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q11, null);
ParsedQuery pq2 = parser.parseQuery(q7, null);
ParsedQuery pq3 = parser.parseQuery(q12, null);
ParsedQuery pq4 = parser.parseQuery(q13, null);
ParsedQuery pq5 = parser.parseQuery(q8, null);
ParsedQuery pq6 = parser.parseQuery(q14, null);
System.out.println("Query is " + pq1.getTupleExpr());
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());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
list.add(extTup2);
list.add(extTup3);
list.add(extTup4);
list.add(extTup5);
VarConstantIndexListPruner vci = new VarConstantIndexListPruner(pq1.getTupleExpr());
List<ExternalTupleSet> processedIndexSet = vci.getRelevantIndices(list);
System.out.println("Relevant indexes are: ");
for (ExternalTupleSet e : processedIndexSet) {
System.out.println(e);
}
Set<ExternalTupleSet> indexSet = Sets.newHashSet();
indexSet.add(extTup1);
indexSet.add(extTup2);
indexSet.add(extTup4);
Assert.assertTrue(Sets.intersection(indexSet, Sets.<ExternalTupleSet>newHashSet(processedIndexSet)).equals(Sets.<ExternalTupleSet>newHashSet(processedIndexSet)));
}
Aggregations