Search in sources :

Example 21 with QueryRoot

use of org.eclipse.rdf4j.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPipelineTransformVisitorTest method testStatementPattern.

@Test
public void testStatementPattern() throws Exception {
    QueryRoot query = new QueryRoot(new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD)));
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    query.visit(visitor);
    Assert.assertTrue(query.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) query.getArg();
    Assert.assertEquals(Sets.newHashSet("x"), pipelineNode.getAssuredBindingNames());
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) Var(org.eclipse.rdf4j.query.algebra.Var) Test(org.junit.Test)

Example 22 with QueryRoot

use of org.eclipse.rdf4j.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPigTransformVisitorTest method testMutliReturnJoin.

public void testMutliReturnJoin() throws Exception {
    String query = "select * where {\n" + "?subj <urn:lubm:rdfts#name> 'Department0'.\n" + "?subj <urn:lubm:rdfts#subOrganizationOf> ?suborg.\n" + "}";
    QueryParser parser = new SPARQLParser();
    ParsedQuery parsedQuery = parser.parseQuery(query, null);
    System.out.println(query);
    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());
}
Also used : QueryParser(org.eclipse.rdf4j.query.parser.QueryParser) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery)

Example 23 with QueryRoot

use of org.eclipse.rdf4j.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPigTransformVisitorTest method testStatementPatternContextVar.

public void testStatementPatternContextVar() throws Exception {
    String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + " PREFIX ub: <urn:lubm:rdfts#>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + " SELECT * WHERE\n" + " {\n" + " GRAPH ?g {\n" + "\t?x rdf:type ub:UndergraduateStudent\n" + " }\n" + " ?x ub:pred ?g." + " }\n" + "";
    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());
}
Also used : QueryParser(org.eclipse.rdf4j.query.parser.QueryParser) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery)

Example 24 with QueryRoot

use of org.eclipse.rdf4j.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPigTransformVisitorTest method testStatementPattern.

public void testStatementPattern() throws Exception {
    String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + " PREFIX ub: <urn:lubm:rdfts#>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + " SELECT * WHERE\n" + " {\n" + "\t?x rdf:type ub:UndergraduateStudent\n" + " }\n" + "";
    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());
}
Also used : QueryParser(org.eclipse.rdf4j.query.parser.QueryParser) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery)

Example 25 with QueryRoot

use of org.eclipse.rdf4j.query.algebra.QueryRoot in project incubator-rya by apache.

the class SparqlToPigTransformVisitorTest method testStatementPatternContext.

public void testStatementPatternContext() throws Exception {
    String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + " PREFIX ub: <urn:lubm:rdfts#>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + " SELECT * WHERE\n" + " {\n" + " GRAPH ub:g1 {\n" + "\t?x rdf:type ub:UndergraduateStudent\n" + " }\n" + " }\n" + "";
    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());
}
Also used : QueryParser(org.eclipse.rdf4j.query.parser.QueryParser) SPARQLParser(org.eclipse.rdf4j.query.parser.sparql.SPARQLParser) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) ParsedQuery(org.eclipse.rdf4j.query.parser.ParsedQuery)

Aggregations

QueryRoot (org.eclipse.rdf4j.query.algebra.QueryRoot)27 Test (org.junit.Test)13 ParsedQuery (org.eclipse.rdf4j.query.parser.ParsedQuery)11 QueryParser (org.eclipse.rdf4j.query.parser.QueryParser)11 SPARQLParser (org.eclipse.rdf4j.query.parser.sparql.SPARQLParser)11 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)9 Var (org.eclipse.rdf4j.query.algebra.Var)8 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)5 Join (org.eclipse.rdf4j.query.algebra.Join)5 QueryBindingSet (org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet)5 EmptyBindingSet (org.eclipse.rdf4j.query.impl.EmptyBindingSet)5 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)4 IRI (org.eclipse.rdf4j.model.IRI)3 Projection (org.eclipse.rdf4j.query.algebra.Projection)3 ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)3 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)2 QueryJoinOptimizer (org.apache.rya.rdftriplestore.evaluation.QueryJoinOptimizer)2 InverseOfVisitor (org.apache.rya.rdftriplestore.inference.InverseOfVisitor)2 Extension (org.eclipse.rdf4j.query.algebra.Extension)2