use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class JoinSegment method clone.
@Override
public JoinSegment<T> clone() {
List<QueryModelNode> order = new ArrayList<>();
for (QueryModelNode node : orderedNodes) {
order.add(node.clone());
}
Set<QueryModelNode> unorder = Sets.newHashSet(order);
Map<ValueExpr, Filter> map = new HashMap<>();
for (ValueExpr expr : conditionMap.keySet()) {
map.put(expr.clone(), conditionMap.get(expr).clone());
}
return new JoinSegment<T>(unorder, order, map);
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class AbstractQuerySegment method getQuery.
/**
* @return - a TupleExpr representing this JoinSegment
*/
@Override
public TupleExprAndNodes getQuery() {
List<QueryModelNode> nodeCopy = new ArrayList<>();
for (QueryModelNode q : orderedNodes) {
if (!(q instanceof ValueExpr)) {
nodeCopy.add(q.clone());
}
}
QueryNodesToTupleExpr qnt = new QueryNodesToTupleExpr(nodeCopy, getFilters());
return qnt.getTupleAndNodes();
}
use of org.openrdf.query.algebra.QueryModelNode 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.openrdf.query.algebra.QueryModelNode 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));
}
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class PrecompJoinOptimizerVarToConstTest method testFreeTestIndexFunction.
@Test
public void testFreeTestIndexFunction() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser2 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q22, null);
final ParsedQuery pq2 = parser2.parseQuery(q24, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Index is " + pq2.getTupleExpr());
final SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup);
final TupleExpr tup = pq1.getTupleExpr().clone();
final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
pcj.optimize(tup, null, null);
System.out.println("Processed query is " + tup);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
Assert.assertEquals(2, eTupSet.size());
for (final QueryModelNode s : eTupSet) {
final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
set.addAll(tempSet);
}
Assert.assertTrue(qSet.containsAll(set));
}
Aggregations