use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet 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>()));
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerTest method testJoinMatcherRejectsLeftJoinPcj.
@Test
public void testJoinMatcherRejectsLeftJoinPcj() throws Exception {
final String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?e a ?c . " + //
" ?e <uri:talksTo> ?l . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String query2 = //
"" + //
"SELECT ?a ?b ?m" + //
"{" + //
" ?a a ?b . " + //
" ?a <uri:talksTo> ?m . " + //
" OPTIONAL {?a <http://www.w3.org/2000/01/rdf-schema#label> ?m} . " + //
"}";
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 expected = te1.clone();
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(expected, te1);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerTest method testSegmentWithLargeUnion.
@Test
public void testSegmentWithLargeUnion() throws Exception {
final String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" {?e <uri:p1> <uri:o1>. } UNION { " + //
" ?e <uri:p0> ?l ." + //
" ?l <uri:p5> <uri:o5> ." + " OPTIONAL{?l <uri:p4> <uri:o4>} ." + //
" ?c<uri:p1> ?l ." + //
" OPTIONAL{ ?e <uri:p1> ?c } ." + //
" ?e <uri:p2> <uri:o2>. " + //
" ?c <uri:p3> <uri:o3> " + //
" } . " + //
" ?e <uri:p2> ?c . " + //
" ?e <uri:p3> <uri:o2> . " + //
"}";
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 String query3 = //
"" + //
"SELECT ?h ?i" + //
"{" + //
" ?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));
unMatchedNodes.add(remainingNodes.get(2));
unMatchedNodes.add(remainingNodes.get(3));
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.SimpleExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerTest method testSegmentWithUnion.
@Test
public void testSegmentWithUnion() throws Exception {
final String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" {?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" + //
"{" + //
" ?a <uri:p5> <uri:o4> ." + //
" ?a <uri:p4> <uri:o3> ." + //
" OPTIONAL {?a <uri:talksTo> ?m} . " + //
" ?a a ?b . " + //
"}";
final String query3 = //
"" + //
"SELECT ?h ?i" + //
"{" + //
" ?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.SimpleExternalTupleSet 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);
}
}
Aggregations