use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithoutBindingSetInvalidProperty.
/**
* Tests if results are filtered correctly using the metadata properties. In
* this case, the date for the ingested RyaStatement differs from the date
* specified in the query.
*/
@Test
public void simpleQueryWithoutBindingSetInvalidProperty() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Doug"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-15"));
RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(new QueryBindingSet());
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(0, bsList.size());
dao.delete(statement, conf);
} finally {
dao.destroy();
}
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSetJoinPropertyToSubject.
/**
* Tests to see if correct result is passed back when a metadata statement
* is joined with a StatementPattern statement (i.e. a common variable
* appears in a StatementPattern statement and a metadata statement).
* StatementPattern statements have either rdf:subject, rdf:predicate, or
* rdf:object as the predicate while a metadata statement is any statement
* in the reified query whose predicate is not rdf:type and not a
* StatementPattern predicate.
*/
@Test
public void simpleQueryWithBindingSetJoinPropertyToSubject() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
dao.add(statement1);
dao.add(statement2);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query2, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
List<BindingSet> bsCollection = new ArrayList<>();
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("y", new LiteralImpl("CoffeeShop"));
bsConstraint1.addBinding("z", new LiteralImpl("Virginia"));
QueryBindingSet bsConstraint2 = new QueryBindingSet();
bsConstraint2.addBinding("y", new LiteralImpl("HardwareStore"));
bsConstraint2.addBinding("z", new LiteralImpl("Maryland"));
bsCollection.add(bsConstraint1);
bsCollection.add(bsConstraint2);
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection);
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("y", new LiteralImpl("CoffeeShop"));
expected.addBinding("x", new URIImpl("http://Joe"));
expected.addBinding("z", new LiteralImpl("Virginia"));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(expected, bsList.get(0));
dao.delete(statement1, conf);
dao.delete(statement2, conf);
} finally {
dao.destroy();
}
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSetCollection.
/**
* Tests if StatementMetadataNode joins BindingSet values correctly for
* variables appearing as the object in one of the StatementPattern
* statements (in the case ?x appears as the Object in the statement
* _:blankNode rdf:object ?x). StatementPattern statements have either
* rdf:subject, rdf:predicate, or rdf:object as the predicate.
*/
@Test
public void simpleQueryWithBindingSetCollection() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
dao.add(statement1);
dao.add(statement2);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
List<BindingSet> bsCollection = new ArrayList<>();
QueryBindingSet bsConstraint1 = new QueryBindingSet();
bsConstraint1.addBinding("x", new LiteralImpl("CoffeeShop"));
bsConstraint1.addBinding("z", new LiteralImpl("Virginia"));
QueryBindingSet bsConstraint2 = new QueryBindingSet();
bsConstraint2.addBinding("x", new LiteralImpl("HardwareStore"));
bsConstraint2.addBinding("z", new LiteralImpl("Maryland"));
QueryBindingSet bsConstraint3 = new QueryBindingSet();
bsConstraint3.addBinding("x", new LiteralImpl("BurgerShack"));
bsConstraint3.addBinding("z", new LiteralImpl("Delaware"));
bsCollection.add(bsConstraint1);
bsCollection.add(bsConstraint2);
bsCollection.add(bsConstraint3);
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection);
Set<BindingSet> expected = new HashSet<>();
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("x", new LiteralImpl("CoffeeShop"));
expected1.addBinding("y", new LiteralImpl("Joe"));
expected1.addBinding("z", new LiteralImpl("Virginia"));
QueryBindingSet expected2 = new QueryBindingSet();
expected2.addBinding("x", new LiteralImpl("HardwareStore"));
expected2.addBinding("y", new LiteralImpl("Joe"));
expected2.addBinding("z", new LiteralImpl("Maryland"));
expected.add(expected1);
expected.add(expected2);
Set<BindingSet> bsSet = new HashSet<>();
while (iteration.hasNext()) {
bsSet.add(iteration.next());
}
Assert.assertEquals(expected, bsSet);
dao.delete(statement1, conf);
dao.delete(statement2, conf);
} finally {
dao.destroy();
}
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSet.
@Test
public void simpleQueryWithBindingSet() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata);
dao.add(statement1);
dao.add(statement2);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<MongoDBRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
QueryBindingSet bsConstraint = new QueryBindingSet();
bsConstraint.addBinding("x", new LiteralImpl("CoffeeShop"));
bsConstraint.addBinding("z", new LiteralImpl("Virginia"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("x", new LiteralImpl("CoffeeShop"));
expected.addBinding("y", new LiteralImpl("Joe"));
expected.addBinding("z", new LiteralImpl("Virginia"));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(expected, bsList.get(0));
dao.delete(statement1, conf);
dao.delete(statement2, conf);
} finally {
dao.destroy();
}
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class PeriodicQueryUpdater method updatePeriodicBinResults.
/**
* Uses the {@link PeriodicQueryMetadata} to create a collection of binned BindingSets
* that are added to Fluo. Each binned BindingSet is the original BindingSet with an additional
* Binding that contains the periodic bin id of the BindingSet.
* @param tx - Fluo Transaction
* @param bs - VisibilityBindingSet that will be binned
* @param metadata - PeriodicQueryMetadata used to bin BindingSets
* @throws Exception
*/
public void updatePeriodicBinResults(TransactionBase tx, VisibilityBindingSet bs, PeriodicQueryMetadata metadata) throws Exception {
Set<Long> binIds = getBinEndTimes(metadata, bs);
for (Long id : binIds) {
// create binding set value bytes
QueryBindingSet binnedBs = new QueryBindingSet(bs);
binnedBs.addBinding(IncrementalUpdateConstants.PERIODIC_BIN_ID, vf.createLiteral(id));
VisibilityBindingSet visibilityBindingSet = new VisibilityBindingSet(binnedBs, bs.getVisibility());
Bytes periodicBsBytes = BS_SERDE.serialize(visibilityBindingSet);
// create row
final Bytes resultRow = makeRowKey(metadata.getNodeId(), metadata.getVariableOrder(), visibilityBindingSet);
Column col = FluoQueryColumns.PERIODIC_QUERY_BINDING_SET;
tx.set(resultRow, col, periodicBsBytes);
}
}
Aggregations