use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class SparqlToPigTransformVisitorTest method testHardQuery.
public void testHardQuery() throws Exception {
String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + " PREFIX ub: <urn:lubm:rdfts#>\n" + " SELECT * WHERE\n" + " {\n" + " ?y rdf:type ub:University .\n" + " ?z ub:subOrganizationOf ?y .\n" + " ?z rdf:type ub:Department .\n" + " ?x ub:memberOf ?z .\n" + " ?x ub:undergraduateDegreeFrom ?y .\n" + " ?x rdf:type ub:GraduateStudent .\n" + " }\n" + "limit 100";
// String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
// " PREFIX ub: <urn:lubm:rdfts#>\n" +
// " SELECT * WHERE\n" +
// " {\n" +
// "\t?x ub:advisor ?y.\n" +
// "\t?y ub:teacherOf ?z.\n" +
// "\t?x ub:takesCourse ?z.\n" +
// "\t?x rdf:type ub:Student.\n" +
// "\t?y rdf:type ub:Faculty.\n" +
// "\t?z rdf:type ub:Course.\n" +
// " }\n" +
// "limit 100";
// System.out.println(query);
QueryParser parser = new SPARQLParser();
ParsedQuery parsedQuery = parser.parseQuery(query, null);
TupleExpr tupleExpr = parsedQuery.getTupleExpr();
// CloudbaseRdfEvalStatsDAO rdfEvalStatsDAO = new CloudbaseRdfEvalStatsDAO();
// rdfEvalStatsDAO.setConnector(new ZooKeeperInstance("stratus", "stratus13:2181").getConnector("root", "password".getBytes()));
// rdfEvalStatsDAO.setEvalTable("l_eval");
// RdfCloudTripleStoreEvaluationStatistics stats = new RdfCloudTripleStoreEvaluationStatistics(new Configuration(), rdfEvalStatsDAO);
// (new SimilarVarJoinOptimizer(stats)).optimize(tupleExpr, null, null);
// System.out.println(tupleExpr);
SparqlToPigTransformVisitor visitor = new SparqlToPigTransformVisitor();
visitor.setTablePrefix(tablePrefix);
visitor.setInstance(instance);
visitor.setZk(zk);
visitor.setUser(user);
visitor.setPassword(password);
visitor.meet(new QueryRoot(tupleExpr));
// System.out.println(visitor.getPigScript());
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class SparqlToPigTransformVisitorTest method testJoin.
public void testJoin() throws Exception {
String query = "select * where {\n" + "?subj <urn:lubm:rdfts#name> 'Department0'.\n" + "?subj <urn:lubm:rdfts#subOrganizationOf> <http://www.University0.edu>.\n" + "}";
// System.out.println(query);
QueryParser parser = new SPARQLParser();
ParsedQuery parsedQuery = parser.parseQuery(query, null);
// System.out.println(parsedQuery);
SparqlToPigTransformVisitor visitor = new SparqlToPigTransformVisitor();
visitor.setTablePrefix(tablePrefix);
visitor.setInstance(instance);
visitor.setZk(zk);
visitor.setUser(user);
visitor.setPassword(password);
visitor.meet(new QueryRoot(parsedQuery.getTupleExpr()));
// System.out.println(visitor.getPigScript());
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class RdfCloudTripleStoreSelectivityEvaluationStatisticsTest method getTupleExpr.
private TupleExpr getTupleExpr(String query) throws MalformedQueryException {
SPARQLParser sp = new SPARQLParser();
ParsedQuery pq = sp.parseQuery(query, null);
return pq.getTupleExpr();
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class QueryJoinSelectOptimizerTest method getTupleExpr.
private TupleExpr getTupleExpr(String query) throws MalformedQueryException {
SPARQLParser sp = new SPARQLParser();
ParsedQuery pq = sp.parseQuery(query, null);
return pq.getTupleExpr();
}
use of org.eclipse.rdf4j.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryNoBindingSetConstantContext.
@Test
public void simpleQueryNoBindingSetConstantContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
// query is used to build statement that will be evaluated
String query = "select ?x ?c where{ graph <uri:context1> {?x <uri:talksTo> <uri:Bob>. }}";
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaType("uri:Bob"), new RyaIRI("uri:context1"), "", new StatementMetadata());
dao.add(statement1);
RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Doug"), new RyaIRI("uri:talksTo"), new RyaType("uri:Bob"), new RyaIRI("uri:context2"), "", new StatementMetadata());
dao.add(statement2);
RyaStatement statement3 = new RyaStatement(new RyaIRI("uri:Eric"), new RyaIRI("uri:talksTo"), new RyaType("uri:Bob"), new RyaIRI("uri:context3"), "", new StatementMetadata());
dao.add(statement3);
QueryBindingSet bsConstraint1 = new QueryBindingSet();
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
QueryBindingSet expected = new QueryBindingSet();
expected.addBinding("x", VF.createIRI("uri:Joe"));
Assert.assertEquals(expected, bsList.get(0));
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
Aggregations