use of org.openrdf.query.parser.sparql.SPARQLParser 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.openrdf.query.parser.sparql.SPARQLParser 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.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class StatementMetadataOptimizerTest method testMongoMatchQuery.
@Test
public void testMongoMatchQuery() throws MalformedQueryException {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
TupleExpr te = pq.getTupleExpr();
System.out.println("Parametrized query is : " + te);
mongoOptimizer.optimize(te, null, null);
System.out.println("Result of optimization is : " + te);
assertEquals(expected, StatementMetadataTestUtils.getMetadataNodes(te));
}
use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class RyaClientExample method prettyFormatSparql.
private static String[] prettyFormatSparql(final String sparql) throws Exception {
final SPARQLParser parser = new SPARQLParser();
final SPARQLQueryRenderer renderer = new SPARQLQueryRenderer();
final ParsedQuery pq = parser.parseQuery(sparql, null);
final String prettySparql = renderer.render(pq);
return StringUtils.split(prettySparql, '\n');
}
use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class StatementMetadataExample method prettyPrintQueryPlan.
private void prettyPrintQueryPlan(String query) throws MalformedQueryException {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
TupleExpr exp = pq.getTupleExpr();
new StatementMetadataOptimizer(getConf()).optimize(exp, null, null);
System.out.println("=================== RYA SPARQL QUERY PLAN ===================");
for (String str : exp.toString().split("\\r?\\n")) {
System.out.println(str);
}
System.out.println("=================== END RYA QUERY PLAN ======================");
}
Aggregations