Search in sources :

Example 16 with QueryModelNode

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

the class PCJOptimizerTest method testBasicSegment.

@Test
public void testBasicSegment() throws Exception {
    final 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 " + // 
    "}";
    final String query2 = // 
    "" + // 
    "SELECT ?a ?b ?m" + // 
    "{" + // 
    "  ?a a ?b . " + // 
    "  OPTIONAL {?a <uri:talksTo> ?m}  . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(2));
    final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj);
    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 17 with QueryModelNode

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

the class PCJOptimizerTest method testSubsetMatchLargeReOrdered.

@Test
public void testSubsetMatchLargeReOrdered() throws Exception {
    final 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:p5> ?i. ?i <uri:p6> ?j} . " + // 
    "  OPTIONAL{?b <uri:p5> ?k. ?k <uri:p6> ?l} . " + // 
    "  OPTIONAL{?b <uri:p5> ?m. ?m <uri:p6> ?n} . " + // 
    "  OPTIONAL{?b <uri:p4> ?o. ?o <uri:p1> ?p} . " + // 
    "}";
    final 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:p3> ?e. ?e <uri:p1> ?f} . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(8));
    unMatchedNodes.add(remainingNodes.get(9));
    unMatchedNodes.add(remainingNodes.get(10));
    unMatchedNodes.add(remainingNodes.get(11));
    unMatchedNodes.add(remainingNodes.get(12));
    unMatchedNodes.add(remainingNodes.get(7));
    final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj);
    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 18 with QueryModelNode

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

the class PCJOptimizerTest method validatePcj.

private boolean validatePcj(final TupleExpr optTupleExp, final TupleExpr unOptTup, final List<ExternalTupleSet> pcjs, final Set<QueryModelNode> expUnmatchedNodes) {
    final IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(unOptTup, pcjs);
    final List<ExternalTupleSet> indexList = iep.getNormalizedIndices();
    final Set<QueryModelNode> indexSet = new HashSet<>();
    for (final ExternalTupleSet etup : indexList) {
        indexSet.add(etup);
    }
    final Set<QueryModelNode> tupNodes = Sets.newHashSet(getNodes(optTupleExp));
    final Set<QueryModelNode> diff = Sets.difference(tupNodes, indexSet);
    return diff.equals(expUnmatchedNodes);
}
Also used : QueryModelNode(org.openrdf.query.algebra.QueryModelNode) IndexedExecutionPlanGenerator(org.apache.rya.indexing.IndexPlanValidator.IndexedExecutionPlanGenerator) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) HashSet(java.util.HashSet)

Example 19 with QueryModelNode

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

the class PCJOptimizerTest method testSwitchTwoBoundVars.

@Test
public void testSwitchTwoBoundVars() throws Exception {
    final String query1 = // 
    "" + // 
    "SELECT ?a ?b ?c " + // 
    "{" + // 
    "  ?a <uri:p0> ?c ." + // 
    "  ?c <uri:p5> <uri:o5> ." + " OPTIONAL{?c <uri:p4> <uri:o4>} ." + // 
    " ?b<uri:p1> ?c ." + // 
    " OPTIONAL{ ?a <uri:p1> ?b } ." + // 
    " ?a <uri:p2> <uri:o2>. " + // 
    " ?b <uri:p3> <uri:o3> " + // 
    "}";
    final String query2 = // 
    "" + // 
    "SELECT ?a ?b ?c " + // 
    "{" + // 
    " ?a <uri:p2> <uri:o2>. " + // 
    " ?b <uri:p3> <uri:o3>. " + // 
    " OPTIONAL{ ?a <uri:p1> ?b } ." + // 
    "  ?a <uri:p0> ?c ." + // 
    "  ?b<uri:p1> ?c " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query1, null);
    final ParsedQuery pq2 = parser.parseQuery(query2, null);
    final TupleExpr te1 = pq1.getTupleExpr();
    final TupleExpr te2 = pq2.getTupleExpr();
    final TupleExpr unOpt = te1.clone();
    final List<QueryModelNode> remainingNodes = getNodes(te1);
    final Set<QueryModelNode> unMatchedNodes = new HashSet<>();
    unMatchedNodes.add(remainingNodes.get(1));
    unMatchedNodes.add(remainingNodes.get(2));
    final SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    final List<ExternalTupleSet> externalList = new ArrayList<>();
    externalList.add(pcj);
    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 20 with QueryModelNode

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

the class StatementMetadataOptimizerTest method getExpected.

private static Set<StatementMetadataNode<?>> getExpected(String query) throws MalformedQueryException {
    ParsedQuery pq = parser.parseQuery(query, null);
    StatementMetadataExternalSetProvider provider = new StatementMetadataExternalSetProvider(getConf(false));
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<QueryModelNode>(patterns), new ArrayList<QueryModelNode>(patterns), new HashMap<ValueExpr, Filter>());
    return new HashSet<>(provider.getExternalSets(segment));
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) ParsedQuery(org.openrdf.query.parser.ParsedQuery) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) JoinSegment(org.apache.rya.indexing.external.matching.JoinSegment) StatementMetadataExternalSetProvider(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataExternalSetProvider) StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) Filter(org.openrdf.query.algebra.Filter) HashSet(java.util.HashSet)

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