Search in sources :

Example 96 with QueryModelNode

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

the class ThreshholdPlanSelectorTest method testTwoIndex.

@Test
public void testTwoIndex() throws Exception {
    String q1 = // 
    "" + // 
    "SELECT ?f ?m ?d ?h ?i " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "  ?d <uri:hangOutWith> ?f ." + // 
    "  ?f <uri:hangOutWith> ?h ." + // 
    "  ?f <uri:associatesWith> ?i ." + // 
    "  ?i <uri:associatesWith> ?h ." + // 
    "}";
    String q2 = // 
    "" + // 
    "SELECT ?t ?s ?u " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  ?t <http://www.w3.org/2000/01/rdf-schema#label> ?u ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    String q3 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:hangOutWith> ?t ." + // 
    "  ?t <uri:hangOutWith> ?u ." + // 
    "}";
    String q4 = // 
    "" + // 
    "SELECT ?s ?t ?u " + // 
    "{" + // 
    "  ?s <uri:associatesWith> ?t ." + // 
    "  ?t <uri:associatesWith> ?u ." + // 
    "}";
    String q5 = // 
    "" + // 
    "SELECT ?m ?f ?d " + // 
    "{" + // 
    "  ?f a ?m ." + // 
    "  ?m <http://www.w3.org/2000/01/rdf-schema#label> ?d ." + // 
    "  ?d <uri:talksTo> ?f . " + // 
    "}";
    String q6 = // 
    "" + // 
    "SELECT ?d ?f ?h " + // 
    "{" + // 
    "  ?d <uri:hangOutWith> ?f ." + // 
    "  ?f <uri:hangOutWith> ?h ." + // 
    "}";
    String q7 = // 
    "" + // 
    "SELECT ?f ?i ?h " + // 
    "{" + // 
    "  ?f <uri:associatesWith> ?i ." + // 
    "  ?i <uri:associatesWith> ?h ." + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(q1, null);
    ParsedQuery pq2 = parser.parseQuery(q2, null);
    ParsedQuery pq3 = parser.parseQuery(q3, null);
    ParsedQuery pq4 = parser.parseQuery(q4, null);
    ParsedQuery pq5 = parser.parseQuery(q5, null);
    ParsedQuery pq6 = parser.parseQuery(q6, null);
    ParsedQuery pq7 = parser.parseQuery(q7, null);
    SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
    SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
    SimpleExternalTupleSet extTup3 = new SimpleExternalTupleSet((Projection) pq4.getTupleExpr());
    SimpleExternalTupleSet extTup4 = new SimpleExternalTupleSet((Projection) pq5.getTupleExpr());
    SimpleExternalTupleSet extTup5 = new SimpleExternalTupleSet((Projection) pq6.getTupleExpr());
    SimpleExternalTupleSet extTup6 = new SimpleExternalTupleSet((Projection) pq7.getTupleExpr());
    List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup2);
    list.add(extTup1);
    list.add(extTup3);
    List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup4);
    optTupNodes.add(extTup6);
    optTupNodes.add(extTup5);
    IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
    Iterator<TupleExpr> plans = new TupleExecutionPlanGenerator().getPlans(iep.getIndexedTuples());
    IndexPlanValidator ipv = new IndexPlanValidator(true);
    Iterator<TupleExpr> validPlans = ipv.getValidTuples(plans);
    ThreshholdPlanSelector tps = new ThreshholdPlanSelector(pq1.getTupleExpr());
    TupleExpr optimalTup = tps.getThreshholdQueryPlan(validPlans, .2, .6, .4, 0);
    NodeCollector nc = new NodeCollector();
    optimalTup.visit(nc);
    List<QueryModelNode> qNodes = nc.getNodes();
    Assert.assertTrue(qNodes.equals(optTupNodes));
}
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) Test(org.junit.Test)

Example 97 with QueryModelNode

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

the class StatementMetadataExternalSetProviderTest method createMultipleMetadataNode.

@Test
public void createMultipleMetadataNode() throws MalformedQueryException {
    MongoDBRdfConfiguration conf = (MongoDBRdfConfiguration) getConf(true);
    Set<RyaURI> propertySet = new HashSet<>();
    propertySet.add(new RyaURI("http://createdBy"));
    propertySet.add(new RyaURI("http://createdOn"));
    conf.setStatementMetadataProperties(propertySet);
    StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    ParsedQuery pq3 = parser.parseQuery(query3, null);
    ParsedQuery pq1 = parser.parseQuery(query, null);
    List<QueryModelNode> patterns = new ArrayList<>();
    List<StatementMetadataNode<?>> expected = new ArrayList<>();
    Set<StatementPattern> sp1 = StatementMetadataTestUtils.getMetadataStatementPatterns(pq1.getTupleExpr(), propertySet);
    Set<StatementPattern> sp3 = StatementMetadataTestUtils.getMetadataStatementPatterns(pq3.getTupleExpr(), propertySet);
    // added extra blankNode into query3 to make blankNode names line up with query2.  Need to remove it now so that
    // StatementMetadataNode doesn't blow up because all subjects aren't the same.
    removePatternWithGivenSubject("-anon-1", sp3);
    patterns.addAll(StatementPatternCollector.process(pq2.getTupleExpr()));
    JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
    List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
    expected.add(new StatementMetadataNode<>(sp1, conf));
    expected.add(new StatementMetadataNode<>(sp3, conf));
    Assert.assertEquals(expected, extSets);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) JoinSegment(org.apache.rya.indexing.external.matching.JoinSegment) StatementMetadataExternalSetProvider(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataExternalSetProvider) RyaURI(org.apache.rya.api.domain.RyaURI) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) StatementPattern(org.openrdf.query.algebra.StatementPattern) Filter(org.openrdf.query.algebra.Filter) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with QueryModelNode

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

the class StatementMetadataExternalSetProviderTest method createSingleMongoMetadataNode.

@Test
public void createSingleMongoMetadataNode() throws MalformedQueryException {
    MongoDBRdfConfiguration conf = (MongoDBRdfConfiguration) getConf(true);
    Set<RyaURI> propertySet = new HashSet<>();
    propertySet.add(new RyaURI("http://createdBy"));
    conf.setStatementMetadataProperties(propertySet);
    StatementMetadataExternalSetProvider metaProvider = new StatementMetadataExternalSetProvider(conf);
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<QueryModelNode> patterns = new ArrayList<>();
    List<StatementMetadataNode<?>> expected = new ArrayList<>();
    Set<StatementPattern> sp = StatementMetadataTestUtils.getMetadataStatementPatterns(pq.getTupleExpr(), propertySet);
    patterns.addAll(StatementPatternCollector.process(pq.getTupleExpr()));
    JoinSegment<StatementMetadataNode<?>> segment = new JoinSegment<>(new HashSet<>(patterns), patterns, new HashMap<ValueExpr, Filter>());
    List<StatementMetadataNode<?>> extSets = metaProvider.getExternalSets(segment);
    expected.add(new StatementMetadataNode<>(sp, conf));
    Assert.assertEquals(expected, extSets);
}
Also used : ValueExpr(org.openrdf.query.algebra.ValueExpr) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) JoinSegment(org.apache.rya.indexing.external.matching.JoinSegment) StatementMetadataExternalSetProvider(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataExternalSetProvider) RyaURI(org.apache.rya.api.domain.RyaURI) StatementMetadataNode(org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode) StatementPattern(org.openrdf.query.algebra.StatementPattern) Filter(org.openrdf.query.algebra.Filter) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) HashSet(java.util.HashSet) 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