use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PrecompJoinOptimizerVarToConstTest method testFourIndexGeoFreeCompareFilterMix.
@Test
public void testFourIndexGeoFreeCompareFilterMix() 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(q27, null);
final ParsedQuery pq2 = parser2.parseQuery(q23, null);
final ParsedQuery pq3 = parser3.parseQuery(q26, null);
final ParsedQuery pq4 = parser4.parseQuery(q24, null);
System.out.println("Query is " + pq1.getTupleExpr());
System.out.println("Indexes are " + pq2.getTupleExpr() + " , " + pq3.getTupleExpr() + " , " + pq4.getTupleExpr());
final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
final SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet(new 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();
final PCJOptimizer pcj = new PCJOptimizer(list, false, new AccumuloIndexSetProvider(new Configuration(), list));
pcj.optimize(tup, null, null);
System.out.println("Processed query is " + tup);
final Set<StatementPattern> qSet = Sets.newHashSet(StatementPatternCollector.process(pq1.getTupleExpr()));
final Set<QueryModelNode> eTupSet = PcjIntegrationTestingUtil.getTupleSets(tup);
final Set<StatementPattern> set = Sets.newHashSet();
Assert.assertEquals(3, eTupSet.size());
for (final QueryModelNode s : eTupSet) {
final Set<StatementPattern> tempSet = Sets.newHashSet(StatementPatternCollector.process(((ExternalTupleSet) s).getTupleExpr()));
set.addAll(tempSet);
}
Assert.assertTrue(qSet.containsAll(set));
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class JoinSegmentPCJMatcherTest method testBasicMatchWithFilter.
@Test
public void testBasicMatchWithFilter() throws Exception {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" Filter(?c = <uri:Lawyer>)" + //
" ?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;
Filter filter = (Filter) proj.getArg();
ExternalSetMatcher<ExternalTupleSet> jsm = pcjFactory.getMatcher(qFactory.getQuerySegment(filter));
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 = QueryNodeGatherer.getNodes(te);
List<QueryModelNode> nodes = jsm.getOrderedNodes();
Set<QueryModelNode> nodeSet = new HashSet<>();
nodeSet.add(nodes.get(0));
nodeSet.add(pcj);
nodeSet.add(nodes.get(1));
Assert.assertEquals(nodeSet, new HashSet<QueryModelNode>(nodes));
Assert.assertEquals(nodeSet, qNodes);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class OptionalJoinSegmentPCJMatcherTest method testBasicMatchWithFilter.
@Test
public void testBasicMatchWithFilter() throws Exception {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" Filter(?e = <uri:Bob>)" + //
" Filter(?c = <uri:Lawyer>)" + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e a ?c . " + //
" OPTIONAL {?e <uri:talksTo> ?l} . " + //
"}";
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();
Projection proj = (Projection) te1;
Filter filter = (Filter) proj.getArg();
ExternalSetMatcher<ExternalTupleSet> jsm = pcjFactory.getMatcher(qFactory.getQuerySegment(filter));
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(pcj);
nodeSet.add(nodes.get(2));
Assert.assertEquals(nodeSet, new HashSet<QueryModelNode>(nodes));
Assert.assertEquals(nodeSet, qNodes);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class OptionalJoinSegmentPCJMatcherTest method testBasicSegment.
@Test
public void testBasicSegment() throws MalformedQueryException {
String query1 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?e a ?c . " + //
" OPTIONAL {?e <uri:talksTo> ?l} . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + //
"}";
String query2 = //
"" + //
"SELECT ?e ?c ?l" + //
"{" + //
" ?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();
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(pcj);
Assert.assertEquals(nodeSet, new HashSet<QueryModelNode>(nodes));
Assert.assertEquals(nodeSet, qNodes);
}
use of org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet in project incubator-rya by apache.
the class PCJOptimizerUtilitesTest method testValidPCJ.
@Test
public void testValidPCJ() throws MalformedQueryException {
String query1 = //
"" + //
"SELECT ?e ?c " + //
"{" + //
" ?e a ?c . " + //
"}";
String query2 = //
"" + //
"SELECT ?a ?b ?m" + //
"{" + //
" ?a a ?b . " + //
" OPTIONAL {?a <uri:talksTo> ?m} . " + //
"}";
String query3 = //
"" + //
"SELECT ?a ?b ?m" + //
"{" + //
" ?a a ?b . " + //
" ?a <uri:talksTo> ?m . " + //
"}";
String query4 = //
"" + //
"SELECT ?a ?b ?m ?n" + //
"{" + //
" ?a a ?b . " + //
" OPTIONAL {?a <uri:talksTo> ?m} . " + //
"}";
String query5 = //
"" + //
"SELECT ?e ?c " + //
"{" + //
"Filter(?e = <uri:s1>) " + //
" ?e a ?c . " + //
"}";
String query6 = //
"" + //
"SELECT ?e ?c " + //
"{" + //
"Filter(?f = <uri:s1>) " + //
" ?e a ?c . " + //
" ?c <uri:p1> <uri:o1> " + //
"}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(query1, null);
ParsedQuery pq2 = parser.parseQuery(query2, null);
ParsedQuery pq3 = parser.parseQuery(query3, null);
ParsedQuery pq4 = parser.parseQuery(query4, null);
ParsedQuery pq5 = parser.parseQuery(query5, null);
ParsedQuery pq6 = parser.parseQuery(query6, null);
TupleExpr te1 = pq1.getTupleExpr();
TupleExpr te2 = pq2.getTupleExpr();
TupleExpr te3 = pq3.getTupleExpr();
TupleExpr te4 = pq4.getTupleExpr();
TupleExpr te5 = pq5.getTupleExpr();
TupleExpr te6 = pq6.getTupleExpr();
SimpleExternalTupleSet pcj1 = new SimpleExternalTupleSet((Projection) te1);
SimpleExternalTupleSet pcj2 = new SimpleExternalTupleSet((Projection) te2);
SimpleExternalTupleSet pcj3 = new SimpleExternalTupleSet((Projection) te3);
SimpleExternalTupleSet pcj4 = new SimpleExternalTupleSet((Projection) te4);
SimpleExternalTupleSet pcj5 = new SimpleExternalTupleSet((Projection) te5);
SimpleExternalTupleSet pcj6 = new SimpleExternalTupleSet((Projection) te6);
Assert.assertEquals(false, PCJOptimizerUtilities.isPCJValid(pcj1));
Assert.assertEquals(true, PCJOptimizerUtilities.isPCJValid(pcj2));
Assert.assertEquals(true, PCJOptimizerUtilities.isPCJValid(pcj3));
Assert.assertEquals(false, PCJOptimizerUtilities.isPCJValid(pcj4));
Assert.assertEquals(true, PCJOptimizerUtilities.isPCJValid(pcj5));
Assert.assertEquals(false, PCJOptimizerUtilities.isPCJValid(pcj6));
}
Aggregations