use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class PrecompJoinOptimizerTest2 method testThreeIndexGeoFreeCompareFilterMix.
@Test
public void testThreeIndexGeoFreeCompareFilterMix() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser2 = new SPARQLParser();
final SPARQLParser parser3 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q25, null);
final ParsedQuery pq2 = parser2.parseQuery(q24, null);
final ParsedQuery pq3 = parser3.parseQuery(q26, null);
final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
list.add(extTup2);
final TupleExpr tup = pq1.getTupleExpr().clone();
provider.setIndices(list);
final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
pcj.optimize(tup, null, null);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
for (final QueryModelNode s : eTupSet) {
set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
}
Assert.assertTrue(set.equals(qSet) && eTupSet.size() == 2);
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class PrecompJoinOptimizerTest2 method testTwoRepeatedIndex.
@Test
public void testTwoRepeatedIndex() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser2 = new SPARQLParser();
final SPARQLParser parser3 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q35, null);
final ParsedQuery pq2 = parser2.parseQuery(q34, null);
final ParsedQuery pq3 = parser3.parseQuery(q36, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
list.add(extTup2);
final TupleExpr tup = pq1.getTupleExpr().clone();
provider.setIndices(list);
final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
pcj.optimize(tup, null, null);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
for (final QueryModelNode s : eTupSet) {
set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
}
Assert.assertEquals(4, eTupSet.size());
Assert.assertEquals(qSet, set);
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class PrecompJoinOptimizerTest2 method testThreeIndexLargeQuery.
@Test
public void testThreeIndexLargeQuery() throws Exception {
final SPARQLParser parser1 = new SPARQLParser();
final SPARQLParser parser2 = new SPARQLParser();
final SPARQLParser parser3 = new SPARQLParser();
final SPARQLParser parser4 = new SPARQLParser();
final ParsedQuery pq1 = parser1.parseQuery(q13, null);
final ParsedQuery pq2 = parser2.parseQuery(q5, null);
final ParsedQuery pq3 = parser3.parseQuery(q12, null);
final ParsedQuery pq4 = parser4.parseQuery(q14, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Indexes are " + pq2.getTupleExpr() + " , " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr());
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);
list.add(extTup2);
list.add(extTup3);
final TupleExpr tup = pq1.getTupleExpr().clone();
provider.setIndices(list);
final PCJOptimizer pcj = new PCJOptimizer(list, false, provider);
pcj.optimize(tup, null, null);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
for (final QueryModelNode s : eTupSet) {
set.addAll(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
}
Assert.assertTrue(set.equals(qSet));
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class JoinSegmentTest method testBasicSegment.
@Test
public void testBasicSegment() throws MalformedQueryException {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?e a ?c . " + //
" ?e <uri:talksTo> ?l . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
String query2 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?e a ?c . " + //
" ?e <uri:talksTo> ?l . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(query1, null);
ParsedQuery pq2 = parser.parseQuery(query2, null);
TupleExpr te1 = pq1.getTupleExpr();
TupleExpr te2 = pq2.getTupleExpr();
Join join1 = (Join) ((Projection) te1).getArg();
Join join2 = (Join) ((Projection) te2).getArg();
QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(join1);
QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(join2);
Assert.assertEquals(true, seg1.containsQuerySegment(seg2));
Assert.assertEquals(join1, seg1.getQuery().getTupleExpr());
Assert.assertEquals(join2, seg2.getQuery().getTupleExpr());
SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
List<QueryModelNode> nodes = seg1.getOrderedNodes();
QueryModelNode node = nodes.get(0);
seg1.replaceWithExternalSet(seg2, pcj);
Set<QueryModelNode> nodeSet = new HashSet<>();
nodeSet.add(node);
nodeSet.add(pcj);
Assert.assertEquals(nodeSet, seg1.getUnOrderedNodes());
}
use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.
the class JoinSegmentTest method testBasicMatchWithFilter.
@Test
public void testBasicMatchWithFilter() throws Exception {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e a ?c . " + //
" ?e <uri:talksTo> ?l . " + //
"}";
String query2 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" ?e a ?c . " + //
" ?e <uri:talksTo> ?l . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(query1, null);
ParsedQuery pq2 = parser.parseQuery(query2, null);
TupleExpr te1 = pq1.getTupleExpr();
TupleExpr te2 = pq2.getTupleExpr();
TopOfQueryFilterRelocator.moveFiltersToTop(te1);
TopOfQueryFilterRelocator.moveFiltersToTop(te1);
Filter filter1 = (Filter) ((Projection) te1).getArg();
Filter filter2 = (Filter) ((Projection) te2).getArg();
QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(filter1);
QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(filter2);
Assert.assertEquals(filter1, seg1.getQuery().getTupleExpr());
Assert.assertEquals(filter2, seg2.getQuery().getTupleExpr());
Assert.assertEquals(true, seg1.containsQuerySegment(seg2));
SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
List<QueryModelNode> nodes = seg1.getOrderedNodes();
QueryModelNode node = nodes.get(3);
seg1.replaceWithExternalSet(seg2, pcj);
Set<QueryModelNode> nodeSet = new HashSet<>();
nodeSet.add(node);
nodeSet.add(pcj);
Assert.assertEquals(nodeSet, seg1.getUnOrderedNodes());
}
Aggregations