Search in sources :

Example 81 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class PrecompJoinOptimizerVarToConstTest method testThreeIndexGeoFreeCompareFilterMix.

@Test
public void testThreeIndexGeoFreeCompareFilterMix() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final SPARQLParser parser3 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q25, null);
    final ParsedQuery pq2 = parser2.parseQuery(q24, null);
    final ParsedQuery pq3 = parser3.parseQuery(q26, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Indexes are " + pq2.getTupleExpr() + " and " + pq3.getTupleExpr());
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet(new Projection(pq3.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    list.add(extTup2);
    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(2, 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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 82 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class PrecompJoinOptimizerVarToConstTest method testGeoIndexFunction.

@Test
public void testGeoIndexFunction() throws Exception {
    final SPARQLParser parser1 = new SPARQLParser();
    final SPARQLParser parser2 = new SPARQLParser();
    final ParsedQuery pq1 = parser1.parseQuery(q21, null);
    final ParsedQuery pq2 = parser2.parseQuery(q23, null);
    System.out.println("Query is " + pq1.getTupleExpr());
    System.out.println("Index is " + pq2.getTupleExpr());
    final SimpleExternalTupleSet extTup = new SimpleExternalTupleSet(new Projection(pq2.getTupleExpr()));
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup);
    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(1, 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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 83 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode 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));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) Projection(org.openrdf.query.algebra.Projection) 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) StatementPattern(org.openrdf.query.algebra.StatementPattern) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Test(org.junit.Test)

Example 84 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode 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);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) 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) Filter(org.openrdf.query.algebra.Filter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 85 with QueryModelNode

use of org.openrdf.query.algebra.QueryModelNode in project incubator-rya by apache.

the class VarConstQueryVariableNormalizerTest method queryConstGeoFilter.

@Test
public void queryConstGeoFilter() throws Exception {
    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();
    ParsedQuery pq1 = parser1.parseQuery(q32, null);
    ParsedQuery pq2 = parser2.parseQuery(q34, null);
    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());
    Assert.assertEquals(1, normalize.size());
    for (TupleExpr te : normalize) {
        Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(), te));
    }
    FilterCollector fc1 = new FilterCollector();
    pq1.getTupleExpr().visit(fc1);
    List<QueryModelNode> fList1 = fc1.getFilters();
    for (TupleExpr te : normalize) {
        FilterCollector fc2 = new FilterCollector();
        te.visit(fc2);
        List<QueryModelNode> fList2 = fc2.getFilters();
        for (QueryModelNode q : fList2) {
            Assert.assertTrue(fList1.contains(q));
        }
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Aggregations

QueryModelNode (org.openrdf.query.algebra.QueryModelNode)98 TupleExpr (org.openrdf.query.algebra.TupleExpr)74 Test (org.junit.Test)68 ArrayList (java.util.ArrayList)63 ParsedQuery (org.openrdf.query.parser.ParsedQuery)63 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)62 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)56 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)48 StatementPattern (org.openrdf.query.algebra.StatementPattern)33 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)27 HashSet (java.util.HashSet)26 Projection (org.openrdf.query.algebra.Projection)23 Filter (org.openrdf.query.algebra.Filter)15 LeftJoin (org.openrdf.query.algebra.LeftJoin)12 Join (org.openrdf.query.algebra.Join)11 ValueExpr (org.openrdf.query.algebra.ValueExpr)11 QueryNodeConsolidator (org.apache.rya.indexing.external.matching.QueryNodeConsolidator)8 Configuration (org.apache.hadoop.conf.Configuration)7 AccumuloIndexSetProvider (org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider)7 BatchWriter (org.apache.accumulo.core.client.BatchWriter)6