use of org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithBindingSetJoinOnProperty.
/**
* Tests if the StatementMetadataNode joins BindingSet correctly for
* variables appearing in metadata statements. In this case, the metadata
* statements are (_:blankNode <http://createdOn 2017-01-04 ) and
* (_:blankNode <http://createdBy> ?y). The variable ?y appears as the
* object in the above metadata statement and its values are joined to the
* constraint BindingSets in the example below.
*/
@Test
public void simpleQueryWithBindingSetJoinOnProperty() 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);
dao.add(statement1);
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("y", new LiteralImpl("Doug"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(0, bsList.size());
dao.delete(statement1, conf);
} finally {
dao.destroy();
}
}
use of org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithoutBindingSet.
@Test
public void simpleQueryWithoutBindingSet() 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 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<?> node = new StatementMetadataNode<>(spList, conf);
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(new QueryBindingSet());
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", new LiteralImpl("CoffeeShop"));
bs.addBinding("y", new LiteralImpl("Joe"));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(bs, bsList.get(0));
dao.delete(statement, conf);
} finally {
dao.destroy();
}
}
use of org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode 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));
}
use of org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode in project incubator-rya by apache.
the class AccumuloStatementMetadataNodeTest method simpleQueryWithBindingSetJoinOnProperty.
/**
* Tests if the StatementMetadataNode joins BindingSet correctly for
* variables appearing in metadata statements. In this case, the metadata
* statements are (_:blankNode <http://createdOn 2017-01-04 ) and
* (_:blankNode <http://createdBy> ?y). The variable ?y appears as the
* object in the above metadata statement and its values are joined to the
* constraint BindingSets in the example below.
*
* @throws MalformedQueryException
* @throws QueryEvaluationException
* @throws RyaDAOException
*/
@Test
public void simpleQueryWithBindingSetJoinOnProperty() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
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);
dao.add(statement1);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf);
QueryBindingSet bsConstraint = new QueryBindingSet();
bsConstraint.addBinding("x", new LiteralImpl("CoffeeShop"));
bsConstraint.addBinding("y", new LiteralImpl("Doug"));
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsConstraint);
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(0, bsList.size());
dao.delete(statement1, conf);
}
use of org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode in project incubator-rya by apache.
the class AccumuloStatementMetadataNodeTest method simpleQueryWithBindingSet.
@Test
public void simpleQueryWithBindingSet() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
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<AccumuloRdfConfiguration> 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);
}
Aggregations