Search in sources :

Example 1 with EntityQueryNode

use of org.apache.rya.indexing.entity.query.EntityQueryNode in project incubator-rya by apache.

the class MongoDbSmartUriIT method testStorage.

@Test
public void testStorage() throws SmartUriException, MalformedQueryException, RuntimeException, QueryEvaluationException {
    smartUriConverter.storeEntity(BOB_ENTITY);
    final String sparql = "SELECT * WHERE { " + "<" + BOB.getData() + "> <" + RDF.TYPE + "> <" + PERSON_TYPE.getId().getData() + "> . " + "<" + BOB.getData() + "> <" + HAS_SSN.getData() + "> ?ssn . " + "<" + BOB.getData() + "> <" + HAS_AGE.getData() + "> ?age . " + "<" + BOB.getData() + "> <" + HAS_WEIGHT.getData() + "> ?weight . " + "<" + BOB.getData() + "> <" + HAS_ADDRESS.getData() + "> ?address . " + "}";
    final StatementPatternCollector spCollector = new StatementPatternCollector();
    new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(spCollector);
    final List<StatementPattern> patterns = spCollector.getStatementPatterns();
    final EntityQueryNode entityQueryNode = new EntityQueryNode(PERSON_TYPE, patterns, smartUriConverter.getEntityStorage());
    final QueryBindingSet queryBindingSet = new QueryBindingSet();
    final Property ssnProperty = BOB_ENTITY.lookupTypeProperty(PERSON_TYPE, HAS_SSN).get();
    queryBindingSet.addBinding(HAS_SSN.getData(), RyaToRdfConversions.convertValue(ssnProperty.getValue()));
    final CloseableIteration<BindingSet, QueryEvaluationException> iter = entityQueryNode.evaluate(queryBindingSet);
    int count = 0;
    // These should match what was used in the SPARQL query.
    final List<String> queryParamNames = Lists.newArrayList("ssn", "age", "weight", "address");
    while (iter.hasNext()) {
        final BindingSet bs = iter.next();
        assertTrue(bs.getBindingNames().containsAll(queryParamNames));
        count++;
    }
    assertEquals(count, 1);
}
Also used : StatementPatternCollector(org.openrdf.query.algebra.helpers.StatementPatternCollector) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 2 with EntityQueryNode

use of org.apache.rya.indexing.entity.query.EntityQueryNode in project incubator-rya by apache.

the class MongoEntityIndex2IT method queryIsSplitEntityWithOptional.

@Test()
public void queryIsSplitEntityWithOptional() throws Exception {
    // A pattern that has two different subjects.
    final String query = "SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> ?eye . " + "  OPTIONAL{" + "    <urn:SSN:111-11-1111> <urn:name> ?name . " + " } . " + "}";
    final String expectedQuery = "SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> ?eye . " + "}";
    final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
    assertOptimizer(query, expected);
}
Also used : EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) Test(org.junit.Test)

Example 3 with EntityQueryNode

use of org.apache.rya.indexing.entity.query.EntityQueryNode in project incubator-rya by apache.

the class MongoEntityIndex2IT method queryIsFullEntityWithExtra.

@Test()
public void queryIsFullEntityWithExtra() throws Exception {
    // A pattern that has two different subjects.
    final String query = "SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> ?eye . " + "<urn:SSN:111-11-1111> <urn:name> ?name . " + "<urn:SSN:222-22-2222> <urn:age> ?age . " + "<urn:SSN:222-22-2222> <urn:eye> ?eye . " + "<urn:SSN:222-22-2222> <urn:name> ?name . " + "}";
    final String expectedQuery = "SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> ?eye . " + "<urn:SSN:111-11-1111> <urn:name> ?name . " + "}";
    final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(expectedQuery), entityStorage);
    assertOptimizer(query, expected);
}
Also used : EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) Test(org.junit.Test)

Example 4 with EntityQueryNode

use of org.apache.rya.indexing.entity.query.EntityQueryNode in project incubator-rya by apache.

the class MongoEntityIndex2IT method queryIsFullEntity.

@Test()
public void queryIsFullEntity() throws Exception {
    // A pattern that has two different subjects.
    final String query = "SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:name> ?name . " + "<urn:SSN:111-11-1111> <urn:eye> ?eye . " + "}";
    final EntityQueryNode expected = new EntityQueryNode(PERSON_TYPE, getSPs(query), entityStorage);
    assertOptimizer(query, expected);
}
Also used : EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) Test(org.junit.Test)

Example 5 with EntityQueryNode

use of org.apache.rya.indexing.entity.query.EntityQueryNode in project incubator-rya by apache.

the class EntityIndexSetProvider method getExternalSets.

@Override
public List<EntityQueryNode> getExternalSets(final QuerySegment<EntityQueryNode> node) {
    typeMap = HashMultimap.create();
    subjectTypeMap = new HashMap<>();
    // discover entities
    final List<StatementPattern> unused = new ArrayList<>();
    for (final QueryModelNode pattern : node.getOrderedNodes()) {
        if (pattern instanceof StatementPattern) {
            discoverEntities((StatementPattern) pattern, unused);
        }
    }
    final List<EntityQueryNode> nodes = new ArrayList<>();
    for (final Type type : typeMap.keySet()) {
        // replace all nodes in the tupleExpr of the collection of statement patterns with this node.
        final EntityQueryNode entity = new EntityQueryNode(type, typeMap.get(type), entityStorage);
        nodes.add(entity);
    }
    return nodes;
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Type(org.apache.rya.indexing.entity.model.Type) EntityQueryNode(org.apache.rya.indexing.entity.query.EntityQueryNode) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode)

Aggregations

EntityQueryNode (org.apache.rya.indexing.entity.query.EntityQueryNode)9 Test (org.junit.Test)8 StatementPattern (org.openrdf.query.algebra.StatementPattern)2 ArrayList (java.util.ArrayList)1 Property (org.apache.rya.indexing.entity.model.Property)1 Type (org.apache.rya.indexing.entity.model.Type)1 BindingSet (org.openrdf.query.BindingSet)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)1 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)1 StatementPatternCollector (org.openrdf.query.algebra.helpers.StatementPatternCollector)1 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)1