use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet 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.apache.rya.indexing.external.tupleSet.ExternalTupleSet 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());
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class JoinSegmentTest method testNoMatchTooLarge.
@Test
public void testNoMatchTooLarge() throws Exception {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e a ?c . " + //
" ?e <uri:talksTo> ?l . " + //
"}";
String query2 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?e a ?c . " + //
" ?e <uri:worksAt> ?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);
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(false, seg2.containsQuerySegment(seg1));
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerTest method testSegmentWithUnionAndFilters.
@Test
public void testSegmentWithUnionAndFilters() throws Exception {
final String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:s1>) " + //
" Filter(?c = <uri:s2>) " + //
" {?e <uri:p1> <uri:o1>. } UNION { ?e a ?c. OPTIONAL {?e <uri:talksTo> ?l}. ?e <uri:p5> <uri:o4>. ?e <uri:p4> <uri:o3> } . " + //
" ?e <uri:p2> ?c . " + //
" ?e <uri:p3> <uri:o2> . " + //
"}";
final String query2 = //
"" + //
"SELECT ?a ?b ?m" + //
"{" + //
" Filter(?b = <uri:s2>) " + //
" ?a <uri:p5> <uri:o4> ." + //
" ?a <uri:p4> <uri:o3> ." + //
" OPTIONAL {?a <uri:talksTo> ?m} . " + //
" ?a a ?b . " + //
"}";
final String query3 = //
"" + //
"SELECT ?h ?i" + //
"{" + //
" Filter(?h = <uri:s1>) " + //
" ?h <uri:p2> ?i . " + //
" ?h <uri:p3> <uri:o2> . " + //
"}";
final SPARQLParser parser = new SPARQLParser();
final ParsedQuery pq1 = parser.parseQuery(query1, null);
final ParsedQuery pq2 = parser.parseQuery(query2, null);
final ParsedQuery pq3 = parser.parseQuery(query3, null);
final TupleExpr te1 = pq1.getTupleExpr();
final TupleExpr te2 = pq2.getTupleExpr();
final TupleExpr te3 = pq3.getTupleExpr();
final TupleExpr unOpt = te1.clone();
final List<QueryModelNode> remainingNodes = getNodes(te1);
final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
unMatchedNodes.add(remainingNodes.get(0));
final SimpleExternalTupleSet pcj1 = new SimpleExternalTupleSet((Projection) te2);
final SimpleExternalTupleSet pcj2 = new SimpleExternalTupleSet((Projection) te3);
final List<ExternalTupleSet> externalList = new ArrayList<>();
externalList.add(pcj1);
externalList.add(pcj2);
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.ExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerTest method testSegmentWithLeftJoinsAndFilters.
@Test
public void testSegmentWithLeftJoinsAndFilters() throws Exception {
final String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:s1>) " + //
" Filter(?c = <uri:s2>) " + " ?e <uri:p1> <uri:o1>. " + " OPTIONAL {?e <uri:p2> ?l}. " + //
" ?c <uri:p3> <uri:o3> . " + //
" ?c <uri:p4> ?e . " + //
" OPTIONAL {?e <uri:p2> ?c } . " + //
"}";
final String query2 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?c = <uri:s2>) " + " ?e <uri:p1> <uri:o1>. " + " OPTIONAL {?e <uri:p2> ?l}. " + //
" ?c <uri:p3> <uri:o3> . " + //
"}";
final String query3 = //
"" + //
"SELECT ?e ?c" + //
"{" + //
" Filter(?e = <uri:s1>) " + //
" ?c <uri:p4> ?e . " + //
" OPTIONAL {?e <uri:p2> ?c } . " + //
"}";
final SPARQLParser parser = new SPARQLParser();
final ParsedQuery pq1 = parser.parseQuery(query1, null);
final ParsedQuery pq2 = parser.parseQuery(query2, null);
final ParsedQuery pq3 = parser.parseQuery(query3, null);
final TupleExpr te1 = pq1.getTupleExpr();
final TupleExpr te2 = pq2.getTupleExpr();
final TupleExpr te3 = pq3.getTupleExpr();
final TupleExpr unOpt = te1.clone();
final SimpleExternalTupleSet pcj1 = new SimpleExternalTupleSet((Projection) te2);
final SimpleExternalTupleSet pcj2 = new SimpleExternalTupleSet((Projection) te3);
final List<ExternalTupleSet> externalList = new ArrayList<>();
externalList.add(pcj1);
externalList.add(pcj2);
provider.setIndices(externalList);
final PCJOptimizer optimizer = new PCJOptimizer(externalList, false, provider);
optimizer.optimize(te1, null, null);
Assert.assertEquals(true, validatePcj(te1, unOpt, externalList, new HashSet<QueryModelNode>()));
}
Aggregations