use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class OptionalJoinSegmentPCJMatcherTest method testMultipleFilters.
@Test
public void testMultipleFilters() throws Exception {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" Filter(?c = <uri:Lawyer>)" + " ?l <uri:workAt> <uri:Company1> ." + //
" OPTIONAL { ?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();
Projection proj = (Projection) te1;
Join join = (Join) proj.getArg();
ExternalSetMatcher<ExternalTupleSet> jsm = pcjFactory.getMatcher(qFactory.getQuerySegment(join));
SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
Assert.assertEquals(true, jsm.match(pcj));
TupleExpr te = jsm.getQuery();
Assert.assertEquals(new HashSet<QueryModelNode>(), jsm.getUnmatchedArgNodes());
Set<QueryModelNode> qNodes = LeftJoinQueryNodeGatherer.getNodes(te);
List<QueryModelNode> nodes = jsm.getOrderedNodes();
Set<QueryModelNode> nodeSet = new HashSet<>();
nodeSet.add(nodes.get(0));
nodeSet.add(nodes.get(2));
nodeSet.add(nodes.get(3));
nodeSet.add(pcj);
Assert.assertEquals(nodeSet, new HashSet<QueryModelNode>(nodes));
Assert.assertEquals(nodeSet, qNodes);
}
use of org.apache.rya.indexing.external.tupleSet.ExternalTupleSet in project incubator-rya by apache.
the class PCJNodeConsolidatorTest method testAlreadyInOrder.
@Test
public void testAlreadyInOrder() throws Exception {
String query1 = //
"" + //
"SELECT ?a ?b ?c ?d" + //
"{" + //
" ?a <uri:p5> <uri:const3>" + //
" OPTIONAL{?a <uri:p3> ?c} . " + //
" ?a <uri:p4> ?b . " + //
" OPTIONAL{<uri:const2> <uri:p4> ?d } . " + " ?c <uri:p1> ?d " + //
" OPTIONAL{<uri:const1> <uri:p2> ?b} . " + //
"}";
String query2 = //
"" + //
"SELECT ?a ?b ?c ?d" + //
"{" + //
" ?a <uri:p4> ?b . " + //
" OPTIONAL{<uri:const2> <uri:p4> ?d } . " + " ?c <uri:p1> ?d " + //
"}";
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();
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());
List<QueryModelNode> queryNodes = new ArrayList<>(seg1.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 testSwitchBoundVars.
@Test
public void testSwitchBoundVars() throws Exception {
String query1 = //
"" + //
"SELECT ?a ?b " + //
"{" + //
" ?a <uri:p0> ?b ." + //
" OPTIONAL{ ?a <uri:p1> <uri:o1> } ." + //
" ?a <uri:p2> <uri:o2> " + //
"}";
String query2 = //
"" + //
"SELECT ?a ?b " + //
"{" + //
" ?a <uri:p2> <uri:o2> " + //
" OPTIONAL{ ?a <uri:p1> <uri:o1> } ." + //
" ?a <uri:p0> ?b ." + //
"}";
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());
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 testUpperLowerBoundOptional.
@Test
public void testUpperLowerBoundOptional() throws Exception {
String query1 = //
"" + //
"SELECT ?a ?b ?c ?d" + //
"{" + //
" ?a <uri:p5> <uri:const3>" + //
" OPTIONAL{<uri:const2> <uri:p4> ?d } . " + //
" ?a <uri:p4> ?b . " + //
" OPTIONAL{?a <uri:p3> ?c} . " + //
" OPTIONAL{<uri:const1> <uri:p2> ?b} . " + " ?c <uri:p1> ?d " + //
"}";
String query2 = //
"" + //
"SELECT ?a ?b ?c ?d" + //
"{" + //
" ?a <uri:p4> ?b . " + //
" OPTIONAL{<uri:const2> <uri:p4> ?d } . " + " ?c <uri:p1> ?d " + //
"}";
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());
List<QueryModelNode> queryNodes = new ArrayList<>(seg1.getOrderedNodes());
QueryModelNode node = queryNodes.remove(0);
queryNodes.add(1, node);
node = queryNodes.remove(3);
queryNodes.add(2, 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 IndexPlanValidatorTest method testEvaluateTwoIndexTwoVarOrder6.
@Test
public void testEvaluateTwoIndexTwoVarOrder6() 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 ?l ?e ?o " + //
"{" + //
" ?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(ais2);
index.add(ais1);
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