Search in sources :

Example 41 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class PCJOptimizerBenchmark method makeChainedQuery.

private static TupleExpr makeChainedQuery(final BenchmarkParams params) throws MalformedQueryException {
    final Queue<String> varQueue = Lists.newLinkedList(variables);
    final SPARQLParser parser = new SPARQLParser();
    final List<String> queryVars = new ArrayList<>();
    // The first statement pattern has two variables.
    queryVars.add(varQueue.remove());
    queryVars.add(varQueue.remove());
    // The each extra statement pattern joins with the previous one, so only need one more variable each.
    for (int i = 1; i < params.getQuerySPCount(); i++) {
        queryVars.add(varQueue.remove());
    }
    final String sparql = buildChainedSPARQL(queryVars);
    return parser.parseQuery(sparql, null).getTupleExpr();
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ArrayList(java.util.ArrayList)

Example 42 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class PCJOptionalTestIT method testSimpleOptionalTest1.

@Test
public void testSimpleOptionalTest1() throws Exception {
    final String query = // 
    "" + // 
    "SELECT ?u ?s ?t " + // 
    "{" + // 
    "  ?s a ?t ." + // 
    "  OPTIONAL{?t <http://www.w3.org/2000/01/rdf-schema#label> ?u } ." + // 
    "  ?u <uri:talksTo> ?s . " + // 
    "}";
    final SPARQLParser parser = new SPARQLParser();
    final ParsedQuery pq1 = parser.parseQuery(query, null);
    final SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq1.getTupleExpr().clone());
    final List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
    list.add(extTup1);
    final List<QueryModelNode> optTupNodes = Lists.newArrayList();
    optTupNodes.add(extTup1);
    final PCJOptimizer pcj = new PCJOptimizer(list, true, new AccumuloIndexSetProvider(new Configuration(), list));
    final TupleExpr te = pq1.getTupleExpr();
    pcj.optimize(te, null, null);
    final NodeCollector nc = new NodeCollector();
    te.visit(nc);
    final List<QueryModelNode> qNodes = nc.getNodes();
    Assert.assertEquals(qNodes.size(), optTupNodes.size());
    for (final QueryModelNode node : qNodes) {
        Assert.assertTrue(optTupNodes.contains(node));
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) Configuration(org.apache.hadoop.conf.Configuration) ParsedQuery(org.openrdf.query.parser.ParsedQuery) AccumuloIndexSetProvider(org.apache.rya.indexing.pcj.matching.provider.AccumuloIndexSetProvider) ArrayList(java.util.ArrayList) QueryModelNode(org.openrdf.query.algebra.QueryModelNode) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) NodeCollector(org.apache.rya.indexing.external.PrecompJoinOptimizerTest.NodeCollector) Test(org.junit.Test)

Example 43 with SPARQLParser

use of org.openrdf.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());
}
Also used : QueryParser(org.openrdf.query.parser.QueryParser) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) QueryRoot(org.openrdf.query.algebra.QueryRoot) ParsedQuery(org.openrdf.query.parser.ParsedQuery)

Example 44 with SPARQLParser

use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.

the class SparqlToPigTransformVisitorTest method testCross.

public void testCross() throws Exception {
    String query = "select * where {\n" + "?subj0 <urn:lubm:rdfts#name> 'Department0'.\n" + "?subj1 <urn:lubm:rdfts#name> 'Department1'.\n" + "?subj0 <urn:lubm:rdfts#subOrganizationOf> <http://www.University0.edu>.\n" + "?subj1 <urn:lubm:rdfts#subOrganizationOf> <http://www.University0.edu>.\n" + "}";
    // System.out.println(query);
    QueryParser parser = new SPARQLParser();
    ParsedQuery parsedQuery = parser.parseQuery(query, null);
    QueryRoot tupleExpr = new QueryRoot(parsedQuery.getTupleExpr());
    SimilarVarJoinOptimizer similarVarJoinOptimizer = new SimilarVarJoinOptimizer();
    similarVarJoinOptimizer.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(tupleExpr);
// System.out.println(visitor.getPigScript());
}
Also used : QueryParser(org.openrdf.query.parser.QueryParser) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) QueryRoot(org.openrdf.query.algebra.QueryRoot) ParsedQuery(org.openrdf.query.parser.ParsedQuery) SimilarVarJoinOptimizer(org.apache.rya.accumulo.pig.optimizer.SimilarVarJoinOptimizer)

Example 45 with SPARQLParser

use of org.openrdf.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());
}
Also used : QueryParser(org.openrdf.query.parser.QueryParser) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) QueryRoot(org.openrdf.query.algebra.QueryRoot) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr)

Aggregations

SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)265 ParsedQuery (org.openrdf.query.parser.ParsedQuery)249 Test (org.junit.Test)212 TupleExpr (org.openrdf.query.algebra.TupleExpr)162 ArrayList (java.util.ArrayList)100 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)99 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)86 StatementPattern (org.openrdf.query.algebra.StatementPattern)82 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)62 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)46 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)45 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)43 RyaURI (org.apache.rya.api.domain.RyaURI)42 BindingSet (org.openrdf.query.BindingSet)41 RyaStatement (org.apache.rya.api.domain.RyaStatement)39 Projection (org.openrdf.query.algebra.Projection)37 RyaType (org.apache.rya.api.domain.RyaType)35 HashSet (java.util.HashSet)27 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)20 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19