use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThrowsException1.
@Test
public void testThrowsException1() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q16, null);
ParsedQuery pq2 = parser.parseQuery(q17, null);
ParsedQuery pq3 = parser.parseQuery(q18, 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(6, indexSet.size());
Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
boolean exceptionThrown = false;
try {
processedTups.remove();
} catch (UnsupportedOperationException e) {
exceptionThrown = true;
}
Assert.assertTrue(exceptionThrown);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class ValidIndexCombinationGeneratorTest method overlappingFilterIndex.
@Test
public void overlappingFilterIndex() {
String q5 = //
"" + //
"SELECT ?s ?t " + //
"{" + //
" ?s a \"Person\" ." + //
" ?t a \"Student\" ." + //
"}";
String q4 = //
"" + //
"SELECT ?s ?t " + //
"{" + //
" ?s a ?t ." + //
" ?s <uri:talksTo> ?t . " + //
"}";
String q3 = //
"" + //
"SELECT ?s ?t " + //
"{" + //
" Filter(?s > 5). " + //
" ?s a ?t ." + //
" ?s <uri:talksTo> ?t . " + //
"}";
String q2 = //
"" + //
"SELECT ?s ?t " + //
"{" + //
" Filter(?s > 5). " + //
" ?s a \"Person\" ." + //
" ?t a \"Student\" ." + //
"}";
String q1 = //
"" + //
"SELECT ?s ?t " + //
"{" + //
" Filter(?s > 5). " + //
" ?s a ?t ." + //
" ?s <uri:talksTo> ?t . " + //
" ?s a \"Person\" ." + //
" ?t a \"Student\" ." + //
"}";
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 (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());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup2);
list.add(extTup1);
list.add(extTup3);
list.add(extTup4);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(4, indexSet.size());
ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet));
int size = 0;
while (eSet.hasNext()) {
size++;
Assert.assertTrue(eSet.hasNext());
List<ExternalTupleSet> eList = eSet.next();
}
Assert.assertTrue(!eSet.hasNext());
Assert.assertEquals(7, size);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class ValidIndexCombinationGeneratorTest method largeQuerySixteenIndexTest.
@Test
public void largeQuerySixteenIndexTest() {
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 . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = null;
ParsedQuery pq2 = null;
ParsedQuery pq3 = null;
try {
pq1 = parser.parseQuery(q1, null);
pq2 = parser.parseQuery(q2, null);
pq3 = parser.parseQuery(q3, null);
} catch (Exception e) {
e.printStackTrace();
}
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(16, indexSet.size());
ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet));
int size = 0;
while (eSet.hasNext()) {
size++;
Assert.assertTrue(eSet.hasNext());
eSet.next();
}
Assert.assertTrue(!eSet.hasNext());
Assert.assertEquals(75, size);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class ValidIndexCombinationGeneratorTest 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 . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = null;
ParsedQuery pq2 = null;
ParsedQuery pq3 = null;
ParsedQuery pq4 = null;
try {
pq1 = parser.parseQuery(q1, null);
pq2 = parser.parseQuery(q2, null);
pq3 = parser.parseQuery(q3, null);
pq4 = parser.parseQuery(q4, 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());
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(40, indexSet.size());
ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator(pq1.getTupleExpr());
Iterator<List<ExternalTupleSet>> eSet = vic.getValidIndexCombos(Lists.newArrayList(indexSet));
int size = 0;
while (eSet.hasNext()) {
size++;
Assert.assertTrue(eSet.hasNext());
eSet.next();
}
Assert.assertTrue(!eSet.hasNext());
Assert.assertEquals(123, size);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class ValidIndexCombinationGeneratorTest method singleIndex.
@Test
public void singleIndex() {
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 ." + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = null;
SimpleExternalTupleSet extTup1 = null;
try {
pq1 = parser.parseQuery(q1, null);
extTup1 = new SimpleExternalTupleSet((Projection) pq1.getTupleExpr());
} catch (MalformedQueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<ExternalTupleSet> indexList = Lists.newArrayList();
indexList.add(extTup1);
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(1, size);
}
Aggregations