Search in sources :

Example 26 with QueryRoot

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

the class SparqlToPigTransformVisitorTest method testFixedStatementPatternInferenceQuery.

public void testFixedStatementPatternInferenceQuery() throws Exception {
    String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + " PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + " PREFIX ub: <urn:lubm:rdfts#>\n" + " SELECT * WHERE\n" + " {\n" + "      ?y ub:memberOf <http://www.Department3.University10.edu>.\n" + "      {?y rdf:type ub:Professor.}\n" + "       UNION \n" + "      {?y rdf:type ub:GraduateStudent.}\n" + " }";
    // System.out.println(query);
    QueryParser parser = new SPARQLParser();
    ParsedQuery parsedQuery = parser.parseQuery(query, null);
    TupleExpr tupleExpr = parsedQuery.getTupleExpr();
    // Configuration conf = new Configuration();
    // Connector connector = new ZooKeeperInstance("stratus", "stratus13:2181").getConnector("root", "password".getBytes());
    // 
    // InferenceEngine inferenceEngine = new InferenceEngine();
    // CloudbaseRdfDAO rdfDAO = new CloudbaseRdfDAO();
    // rdfDAO.setConf(conf);
    // rdfDAO.setConnector(connector);
    // rdfDAO.setNamespaceTable("l_ns");
    // rdfDAO.setSpoTable("l_spo");
    // rdfDAO.setPoTable("l_po");
    // rdfDAO.setOspTable("l_osp");
    // rdfDAO.init();
    // 
    // inferenceEngine.setRdfDao(rdfDAO);
    // inferenceEngine.setConf(conf);
    // inferenceEngine.init();
    // 
    // tupleExpr.visit(new TransitivePropertyVisitor(conf, inferenceEngine));
    // tupleExpr.visit(new SymmetricPropertyVisitor(conf, inferenceEngine));
    // tupleExpr.visit(new InverseOfVisitor(conf, inferenceEngine));
    // tupleExpr.visit(new SubPropertyOfVisitor(conf, inferenceEngine));
    // tupleExpr.visit(new SubClassOfVisitor(conf, inferenceEngine));
    // 
    // CloudbaseRdfEvalStatsDAO rdfEvalStatsDAO = new CloudbaseRdfEvalStatsDAO();
    // rdfEvalStatsDAO.setConnector(connector);
    // rdfEvalStatsDAO.setEvalTable("l_eval");
    // RdfCloudTripleStoreEvaluationStatistics stats = new RdfCloudTripleStoreEvaluationStatistics(conf, rdfEvalStatsDAO);
    // (new QueryJoinOptimizer(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());
}
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) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 27 with QueryRoot

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

the class SparqlQueryPigEngine method generatePigScript.

public String generatePigScript(final String sparql) throws Exception {
    Preconditions.checkNotNull(sparql, "Sparql query cannot be null");
    final QueryParser parser = new SPARQLParser();
    final ParsedQuery parsedQuery = parser.parseQuery(sparql, null);
    final QueryRoot tupleExpr = new QueryRoot(parsedQuery.getTupleExpr());
    if (inference || stats) {
        if (inference) {
            tupleExpr.visit(new TransitivePropertyVisitor(conf, inferenceEngine));
            tupleExpr.visit(new SymmetricPropertyVisitor(conf, inferenceEngine));
            tupleExpr.visit(new InverseOfVisitor(conf, inferenceEngine));
        }
        if (stats) {
            (new QueryJoinOptimizer(rdfCloudTripleStoreEvaluationStatistics)).optimize(tupleExpr, null, null);
        }
    }
    sparqlToPigTransformVisitor.meet(tupleExpr);
    return sparqlToPigTransformVisitor.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) QueryJoinOptimizer(org.apache.rya.rdftriplestore.evaluation.QueryJoinOptimizer) SymmetricPropertyVisitor(org.apache.rya.rdftriplestore.inference.SymmetricPropertyVisitor) TransitivePropertyVisitor(org.apache.rya.rdftriplestore.inference.TransitivePropertyVisitor) InverseOfVisitor(org.apache.rya.rdftriplestore.inference.InverseOfVisitor)

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