Search in sources :

Example 6 with QueryRoot

use of org.eclipse.rdf4j.query.algebra.QueryRoot 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());
}
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 7 with QueryRoot

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

the class PipelineQueryIT method testNoVariableSP.

@Test
public void testNoVariableSP() throws Exception {
    // Insert data
    insert(OWL.THING, RDF.TYPE, OWL.CLASS);
    insert(FOAF.PERSON, RDF.TYPE, OWL.CLASS, 1);
    insert(FOAF.PERSON, RDFS.SUBCLASSOF, OWL.THING);
    insert(VF.createIRI("urn:Alice"), RDF.TYPE, FOAF.PERSON);
    dao.flush();
    // Define query and expected results
    final String query = "SELECT * WHERE {\n" + "  owl:Thing a owl:Class .\n" + "}";
    final Multiset<BindingSet> expectedSolutions = HashMultiset.create();
    expectedSolutions.add(new EmptyBindingSet());
    // Execute pipeline and verify results
    final QueryRoot queryTree = new QueryRoot(PARSER.parseQuery(query, null).getTupleExpr());
    final SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(getRyaCollection());
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof Projection);
    final Projection projection = (Projection) queryTree.getArg();
    Assert.assertTrue(projection.getArg() instanceof AggregationPipelineQueryNode);
    final AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) projection.getArg();
    final Multiset<BindingSet> solutions = HashMultiset.create();
    final CloseableIteration<BindingSet, QueryEvaluationException> iter = pipelineNode.evaluate(new QueryBindingSet());
    while (iter.hasNext()) {
        solutions.add(iter.next());
    }
    Assert.assertEquals(expectedSolutions, solutions);
}
Also used : ListBindingSet(org.eclipse.rdf4j.query.impl.ListBindingSet) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) EmptyBindingSet(org.eclipse.rdf4j.query.impl.EmptyBindingSet) BindingSet(org.eclipse.rdf4j.query.BindingSet) EmptyBindingSet(org.eclipse.rdf4j.query.impl.EmptyBindingSet) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Projection(org.eclipse.rdf4j.query.algebra.Projection) QueryBindingSet(org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 8 with QueryRoot

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

the class SparqlToPipelineTransformVisitorTest method testJoin.

@Test
public void testJoin() throws Exception {
    QueryRoot query = new QueryRoot(new Join(new StatementPattern(new Var("x"), constant(RDF.TYPE), constant(UNDERGRAD)), new StatementPattern(new Var("x"), constant(TAKES), new Var("course"))));
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    query.visit(visitor);
    Assert.assertTrue(query.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) query.getArg();
    Assert.assertEquals(Sets.newHashSet("x", "course"), 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) Join(org.eclipse.rdf4j.query.algebra.Join) Test(org.junit.Test)

Example 9 with QueryRoot

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

the class SparqlToPipelineTransformVisitorTest method testUnsupportedExtension.

@Test
public void testUnsupportedExtension() throws Exception {
    StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
    List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"), new ExtensionElem(new ValueConstant(TAKES), "constant"));
    Extension extensionNode = new Extension(sp, elements);
    QueryRoot queryTree = new QueryRoot(extensionNode);
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof Extension);
    Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
    TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
    Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
    Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) Not(org.eclipse.rdf4j.query.algebra.Not) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) Var(org.eclipse.rdf4j.query.algebra.Var) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) Test(org.junit.Test)

Example 10 with QueryRoot

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

the class SparqlToPipelineTransformVisitorTest method testExtension.

@Test
public void testExtension() throws Exception {
    QueryRoot queryTree = new QueryRoot(new Extension(new StatementPattern(new Var("x"), constant(TAKES), new Var("c")), new ExtensionElem(new Var("x"), "renamed"), new ExtensionElem(new ValueConstant(TAKES), "constant")));
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
    Assert.assertEquals(Sets.newHashSet("x", "c", "renamed", "constant"), pipelineNode.getAssuredBindingNames());
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) QueryRoot(org.eclipse.rdf4j.query.algebra.QueryRoot) Var(org.eclipse.rdf4j.query.algebra.Var) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) Test(org.junit.Test)

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