use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThreeIndexQueryFilter.
@Test
public void testThreeIndexQueryFilter() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q22, null);
ParsedQuery pq2 = parser.parseQuery(q7, null);
ParsedQuery pq3 = parser.parseQuery(q21, null);
ParsedQuery pq4 = parser.parseQuery(q23, 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(extTup2);
list.add(extTup1);
list.add(extTup3);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(5, indexSet.size());
Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
int size = 0;
while (processedTups.hasNext()) {
Assert.assertTrue(processedTups.hasNext());
TupleExpr te = processedTups.next();
System.out.println(te);
size++;
}
Assert.assertTrue(!processedTups.hasNext());
Assert.assertEquals(10, size);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest 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);
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((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());
Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
int size = 0;
while (processedTups.hasNext()) {
Assert.assertTrue(processedTups.hasNext());
processedTups.next();
size++;
}
Assert.assertTrue(!processedTups.hasNext());
Assert.assertEquals(5, size);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class ValidIndexCombinationGeneratorTest method medQueryEightOverlapIndex.
@Test
public void medQueryEightOverlapIndex() {
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 ." + //
"}";
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 ?t ?s ?u " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
" ?s <uri:hangOutWith> ?t ." + //
" ?t <uri:hangOutWith> ?u ." + //
"}";
String q6 = //
"" + //
"SELECT ?s ?t ?u " + //
"{" + //
" ?s <uri:associatesWith> ?t ." + //
" ?t <uri:associatesWith> ?u ." + //
" ?s <uri:hangOutWith> ?t ." + //
" ?t <uri:hangOutWith> ?u ." + //
"}";
String q7 = //
"" + //
"SELECT ?s ?t ?u " + //
"{" + //
" ?s <uri:associatesWith> ?t ." + //
" ?t <uri:associatesWith> ?u ." + //
" ?t <uri:hangOutWith> ?u ." + //
"}";
String q8 = //
"" + //
"SELECT ?t ?s ?u " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
" ?s <uri:associatesWith> ?t ." + //
"}";
String q9 = //
"" + //
"SELECT ?t ?s ?u " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
"}";
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;
ParsedQuery pq8 = null;
ParsedQuery pq9 = null;
SimpleExternalTupleSet extTup1 = null;
SimpleExternalTupleSet extTup2 = null;
SimpleExternalTupleSet extTup3 = null;
SimpleExternalTupleSet extTup4 = null;
SimpleExternalTupleSet extTup5 = null;
SimpleExternalTupleSet extTup6 = null;
SimpleExternalTupleSet extTup7 = null;
SimpleExternalTupleSet extTup8 = 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);
pq8 = parser.parseQuery(q8, null);
pq9 = parser.parseQuery(q9, null);
extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr());
extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr());
extTup7 = new SimpleExternalTupleSet((Projection) pq8.getTupleExpr());
extTup8 = new SimpleExternalTupleSet((Projection) pq9.getTupleExpr());
} catch (MalformedQueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<ExternalTupleSet> indexList = Lists.newArrayList();
indexList.add(extTup1);
indexList.add(extTup2);
indexList.add(extTup3);
indexList.add(extTup4);
indexList.add(extTup5);
indexList.add(extTup6);
indexList.add(extTup7);
indexList.add(extTup8);
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(21, size);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PrecompJoinOptimizerTest method testThreeIndex.
@Test
public void testThreeIndex() throws Exception {
final String q7 = //
"" + //
"SELECT ?s ?t ?u " + //
"{" + //
" ?s a ?t ." + //
" ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + //
" ?u <uri:talksTo> ?s . " + //
"}";
final String q8 = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" ?e a ?l ." + //
" ?l <http://www.w3.org/2000/01/rdf-schema#label> ?c ." + //
" ?c <uri:talksTo> ?e . " + //
"}";
final String q9 = //
"" + //
"SELECT ?f ?m ?d " + //
"{" + //
" ?f a ?m ." + //
" ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + //
" ?d <uri:talksTo> ?f . " + //
"}";
final String q15 = //
"" + //
"SELECT ?f ?m ?d ?e ?l ?c " + //
"{" + //
" ?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 SPARQLParser parser = new SPARQLParser();
final ParsedQuery pq1 = parser.parseQuery(q15, null);
final ParsedQuery pq2 = parser.parseQuery(q7, null);
final ParsedQuery pq3 = parser.parseQuery(q8, null);
final ParsedQuery pq4 = parser.parseQuery(q9, null);
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 List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
final List<QueryModelNode> optTupNodes = Lists.newArrayList();
optTupNodes.add(extTup2);
optTupNodes.add(extTup3);
provider.setIndices(list);
final PCJOptimizer pcj = new PCJOptimizer(list, true, provider);
final TupleExpr te = pq1.getTupleExpr();
pcj.optimize(te, null, null);
final NodeCollector nc = new NodeCollector();
te.visit(nc);
Assert.assertEquals(nc.qNodes.size(), optTupNodes.size());
for (final QueryModelNode node : nc.qNodes) {
Assert.assertTrue(optTupNodes.contains(node));
}
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet 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));
}
}
Aggregations