Search in sources :

Example 61 with ExternalTupleSet

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());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Join(org.openrdf.query.algebra.Join) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 62 with ExternalTupleSet

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());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Filter(org.openrdf.query.algebra.Filter) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with ExternalTupleSet

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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Join(org.openrdf.query.algebra.Join) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Example 64 with ExternalTupleSet

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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 65 with ExternalTupleSet

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>()));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)107 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)99 Test (org.junit.Test)97 ParsedQuery (org.openrdf.query.parser.ParsedQuery)97 TupleExpr (org.openrdf.query.algebra.TupleExpr)92 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 ArrayList (java.util.ArrayList)73 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)56 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 Projection (org.openrdf.query.algebra.Projection)27 StatementPattern (org.openrdf.query.algebra.StatementPattern)23 HashSet (java.util.HashSet)19 Join (org.openrdf.query.algebra.Join)14 LeftJoin (org.openrdf.query.algebra.LeftJoin)14 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)12 Configuration (org.apache.hadoop.conf.Configuration)10 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)10 List (java.util.List)9 MalformedQueryException (org.openrdf.query.MalformedQueryException)7 Filter (org.openrdf.query.algebra.Filter)6