use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerTest method testSwitchTwoBoundVars.
@Test
public void testSwitchTwoBoundVars() throws Exception {
final String query1 = //
"" + //
"SELECT ?a ?b ?c " + //
"{" + //
" ?a <uri:p0> ?c ." + //
" ?c <uri:p5> <uri:o5> ." + " OPTIONAL{?c <uri:p4> <uri:o4>} ." + //
" ?b<uri:p1> ?c ." + //
" OPTIONAL{ ?a <uri:p1> ?b } ." + //
" ?a <uri:p2> <uri:o2>. " + //
" ?b <uri:p3> <uri:o3> " + //
"}";
final String query2 = //
"" + //
"SELECT ?a ?b ?c " + //
"{" + //
" ?a <uri:p2> <uri:o2>. " + //
" ?b <uri:p3> <uri:o3>. " + //
" OPTIONAL{ ?a <uri:p1> ?b } ." + //
" ?a <uri:p0> ?c ." + //
" ?b<uri:p1> ?c " + //
"}";
final SPARQLParser parser = new SPARQLParser();
final ParsedQuery pq1 = parser.parseQuery(query1, null);
final ParsedQuery pq2 = parser.parseQuery(query2, null);
final TupleExpr te1 = pq1.getTupleExpr();
final TupleExpr te2 = pq2.getTupleExpr();
final TupleExpr unOpt = te1.clone();
final List<QueryModelNode> remainingNodes = getNodes(te1);
final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
unMatchedNodes.add(remainingNodes.get(1));
unMatchedNodes.add(remainingNodes.get(2));
final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
final List<ExternalTupleSet> externalList = new ArrayList<>();
externalList.add(pcj);
provider.setIndices(externalList);
final PCJOptimizer optimizer = new PCJOptimizer(externalList, false, provider);
optimizer.optimize(te1, null, null);
Assert.assertEquals(true, validatePcj(te1, unOpt, externalList, unMatchedNodes));
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PCJOptionalTestIT method testSimpleOptionalTest1.
@Test
public void testSimpleOptionalTest1() throws Exception {
final String query = //
"" + //
"SELECT ?u ?s ?t " + //
"{" + //
" ?s a ?t ." + //
" OPTIONAL{?t <http://www.w3.org/2000/01/rdf-schema#label> ?u } ." + //
" ?u <uri:talksTo> ?s . " + //
"}";
final SPARQLParser parser = new SPARQLParser();
final ParsedQuery pq1 = parser.parseQuery(query, null);
final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq1.getTupleExpr().clone());
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
final List<QueryModelNode> optTupNodes = Lists.newArrayList();
optTupNodes.add(extTup1);
final PCJOptimizer pcj = new PCJOptimizer(list, true, new AccumuloIndexSetProvider(new Configuration(), list));
final TupleExpr te = pq1.getTupleExpr();
pcj.optimize(te, null, null);
final NodeCollector nc = new NodeCollector();
te.visit(nc);
final List<QueryModelNode> qNodes = nc.getNodes();
Assert.assertEquals(qNodes.size(), optTupNodes.size());
for (final QueryModelNode node : qNodes) {
Assert.assertTrue(optTupNodes.contains(node));
}
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThreeSingleNodeIndex.
@Test
public void testThreeSingleNodeIndex() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q19, null);
ParsedQuery pq2 = parser.parseQuery(q20, null);
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(3, 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(3, size);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThreeIndexQuery.
@Test
public void testThreeIndexQuery() 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();
int size = 0;
while (processedTups.hasNext()) {
Assert.assertTrue(processedTups.hasNext());
processedTups.next();
size++;
}
Assert.assertTrue(!processedTups.hasNext());
Assert.assertEquals(9, size);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThrowsException2.
@Test
public void testThrowsException2() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q19, null);
ParsedQuery pq2 = parser.parseQuery(q20, null);
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(3, indexSet.size());
Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
processedTups.next();
processedTups.next();
processedTups.next();
boolean exceptionThrown = false;
try {
processedTups.next();
} catch (NoSuchElementException e) {
exceptionThrown = true;
}
Assert.assertTrue(exceptionThrown);
}
Aggregations