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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations