use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class PCJNodeConsolidatorTest method testExactMatchLargeReOrdered.
@Test
public void testExactMatchLargeReOrdered() throws Exception {
String query1 = //
"" + //
"SELECT ?a ?b ?c ?d ?e ?f ?g ?h" + //
"{" + //
" ?a <uri:p0> ?b ." + //
" OPTIONAL{?b <uri:p2> ?c. ?c <uri:p1> ?d} . " + //
" OPTIONAL{?b <uri:p3> ?e. ?e <uri:p1> ?f} . " + //
" OPTIONAL{?b <uri:p4> ?g. ?g <uri:p1> ?h} . " + //
" OPTIONAL{?b <uri:p4> ?i. ?i <uri:p1> ?j} . " + //
" OPTIONAL{?b <uri:p4> ?k. ?k <uri:p1> ?l} . " + //
" OPTIONAL{?b <uri:p4> ?m. ?m <uri:p1> ?n} . " + //
" OPTIONAL{?b <uri:p4> ?o. ?o <uri:p1> ?p} . " + //
"}";
String query2 = //
"" + //
"SELECT ?a ?b ?c ?d ?e ?f ?g ?h" + //
"{" + //
" ?a <uri:p0> ?b ." + //
" OPTIONAL{?b <uri:p4> ?o. ?o <uri:p1> ?p} . " + //
" OPTIONAL{?b <uri:p4> ?g. ?g <uri:p1> ?h} . " + //
" OPTIONAL{?b <uri:p2> ?c. ?c <uri:p1> ?d} . " + //
" OPTIONAL{?b <uri:p4> ?i. ?i <uri:p1> ?j} . " + //
" OPTIONAL{?b <uri:p4> ?m. ?m <uri:p1> ?n} . " + //
" OPTIONAL{?b <uri:p4> ?k. ?k <uri:p1> ?l} . " + //
" OPTIONAL{?b <uri:p3> ?e. ?e <uri:p1> ?f} . " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(query1, null);
ParsedQuery pq2 = parser.parseQuery(query2, null);
TupleExpr te1 = pq1.getTupleExpr();
TupleExpr te2 = pq2.getTupleExpr();
LeftJoin join1 = (LeftJoin) ((Projection) te1).getArg();
LeftJoin join2 = (LeftJoin) ((Projection) te2).getArg();
QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(join1);
QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(join2);
QueryNodeConsolidator consolidator = new QueryNodeConsolidator(seg1.getOrderedNodes(), seg2.getOrderedNodes());
List<QueryModelNode> queryNodes = new ArrayList<>(seg2.getOrderedNodes());
Assert.assertTrue(consolidator.consolidateNodes());
Assert.assertEquals(consolidator.getQueryNodes(), queryNodes);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class PCJNodeConsolidatorTest method testBasicOptionalWithFilter.
@Test
public void testBasicOptionalWithFilter() throws Exception {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" OPTIONAL{?e <uri:talksTo> ?l } . " + //
" OPTIONAL{?c <uri:worksAt> <uri:Apple>} . " + //
" ?e a ?c . " + " ?e <uri:livesIn> <uri:Virginia>" + //
"}";
String query2 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" ?e a ?c . " + //
" OPTIONAL{?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(te2);
Filter filter1 = (Filter) ((Projection) te1).getArg();
Filter filter2 = (Filter) ((Projection) te2).getArg();
QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(filter1);
QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(filter2);
QueryNodeConsolidator consolidator = new QueryNodeConsolidator(seg1.getOrderedNodes(), seg2.getOrderedNodes());
List<QueryModelNode> queryNodes = new ArrayList<>(seg1.getOrderedNodes());
QueryModelNode node = queryNodes.remove(0);
queryNodes.add(1, node);
node = queryNodes.remove(4);
queryNodes.add(2, node);
Assert.assertTrue(consolidator.consolidateNodes());
Assert.assertEquals(consolidator.getQueryNodes(), queryNodes);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class PCJNodeConsolidatorTest method testCantConsolidate.
@Test
public void testCantConsolidate() throws Exception {
String query1 = //
"" + //
"SELECT ?a ?b ?c" + //
"{" + //
" ?c <uri:p5> <uri:o2> ." + //
" ?a <uri:p4> <uri:o1> . " + //
" OPTIONAL{?a <uri:p3> ?b} . " + //
" OPTIONAL{<uri:s2> <uri:p2> ?b} . " + " <uri:s1> <uri:p1> ?b " + //
"}";
String query2 = //
"" + //
"SELECT ?a ?b" + //
"{" + //
" <uri:s1> <uri:p1> ?b . " + " ?a <uri:p4> <uri:o1> " + //
"}";
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);
QueryNodeConsolidator consolidator = new QueryNodeConsolidator(seg1.getOrderedNodes(), seg2.getOrderedNodes());
Assert.assertTrue(!consolidator.consolidateNodes());
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder2.
@Test
public void testEvaluateTwoIndexTwoVarOrder2() throws Exception {
final String indexSparqlString = //
"" + //
"SELECT ?e ?l ?c " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?e ?o ?l " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String queryString = //
"" + //
"SELECT ?e ?c ?l ?o " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final SPARQLParser sp = new SPARQLParser();
final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null);
final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
final List<ExternalTupleSet> index = Lists.newArrayList();
final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection) index1.getTupleExpr());
final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection) index2.getTupleExpr());
index.add(ais1);
index.add(ais2);
final ParsedQuery pq = sp.parseQuery(queryString, null);
final TupleExpr tup = pq.getTupleExpr().clone();
provider.setIndices(index);
final PCJOptimizer pcj = new PCJOptimizer(index, false, provider);
pcj.optimize(tup, null, null);
final IndexPlanValidator ipv = new IndexPlanValidator(false);
Assert.assertEquals(true, ipv.isValid(tup));
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder3.
@Test
public void testEvaluateTwoIndexTwoVarOrder3() throws Exception {
final String indexSparqlString = //
"" + //
"SELECT ?l ?e ?c " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String indexSparqlString2 = //
"" + //
"SELECT ?e ?o ?l " + //
"{" + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final String queryString = //
"" + //
"SELECT ?e ?c ?l ?o " + //
"{" + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
" ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
final SPARQLParser sp = new SPARQLParser();
final ParsedQuery index1 = sp.parseQuery(indexSparqlString, null);
final ParsedQuery index2 = sp.parseQuery(indexSparqlString2, null);
final List<ExternalTupleSet> index = Lists.newArrayList();
final SimpleExternalTupleSet ais1 = new SimpleExternalTupleSet((Projection) index1.getTupleExpr());
final SimpleExternalTupleSet ais2 = new SimpleExternalTupleSet((Projection) index2.getTupleExpr());
index.add(ais1);
index.add(ais2);
final ParsedQuery pq = sp.parseQuery(queryString, null);
final TupleExpr tup = pq.getTupleExpr().clone();
provider.setIndices(index);
final PCJOptimizer pcj = new PCJOptimizer(index, false, provider);
pcj.optimize(tup, null, null);
final IndexPlanValidator ipv = new IndexPlanValidator(false);
Assert.assertEquals(true, ipv.isValid(tup));
}
Aggregations