use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class GeneralizedExternalProcessorTest 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);
ParsedQuery pq4 = parser.parseQuery(q19, null);
System.out.println("Query is " + pq1.getTupleExpr());
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new Projection(pq4.getTupleExpr()));
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup2);
list.add(extTup3);
list.add(extTup1);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(6, indexSet.size());
Set<TupleExpr> processedTups = Sets.newHashSet(iep.getIndexedTuples());
Assert.assertEquals(17, processedTups.size());
TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator();
List<TupleExpr> plans = Lists.newArrayList(tep.getPlans(processedTups.iterator()));
System.out.println("Size is " + plans.size());
System.out.println("Possible indexed tuple plans are :");
for (TupleExpr te : plans) {
System.out.println(te);
}
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class GeneralizedExternalProcessorTest 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);
System.out.println("Query is " + pq1.getTupleExpr());
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new 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());
Set<TupleExpr> processedTups = Sets.newHashSet(iep.getIndexedTuples());
Assert.assertEquals(5, processedTups.size());
}
use of org.openrdf.query.algebra.Projection 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);
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class TupleExecutionPlanGenerator method getPlans.
private List<TupleExpr> getPlans(final TupleExpr te) {
final NodeCollector nc = new NodeCollector();
te.visit(nc);
final Set<QueryModelNode> nodeSet = nc.getNodeSet();
final List<Filter> filterList = nc.getFilterSet();
final Projection projection = nc.getProjection().clone();
final List<TupleExpr> queryPlans = Lists.newArrayList();
final Collection<List<QueryModelNode>> plans = Collections2.permutations(nodeSet);
for (final List<QueryModelNode> p : plans) {
if (p.size() == 0) {
throw new IllegalArgumentException("Tuple must contain at least one node!");
} else if (p.size() == 1) {
queryPlans.add(te);
} else {
queryPlans.add(buildTuple(p, filterList, projection));
}
}
return queryPlans;
}
use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.
the class TupleExecutionPlanGenerator method buildTuple.
private TupleExpr buildTuple(final List<QueryModelNode> nodes, final List<Filter> filters, final Projection projection) {
final Projection proj = projection.clone();
Join join = null;
join = new Join((TupleExpr) nodes.get(0).clone(), (TupleExpr) nodes.get(1).clone());
for (int i = 2; i < nodes.size(); i++) {
join = new Join(join, (TupleExpr) nodes.get(i).clone());
}
if (filters.size() == 0) {
proj.setArg(join);
return proj;
} else {
TupleExpr queryPlan = join;
for (final Filter f : filters) {
final Filter filt = f.clone();
filt.setArg(queryPlan);
queryPlan = filt;
}
proj.setArg(queryPlan);
return proj;
}
}
Aggregations