Search in sources :

Example 26 with SPARQLParser

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

the class EntityOptimizerTest method getTupleExpr.

private TupleExpr getTupleExpr(String query) throws MalformedQueryException {
    SPARQLParser sp = new SPARQLParser();
    ParsedQuery pq = sp.parseQuery(query, null);
    return pq.getTupleExpr();
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery)

Example 27 with SPARQLParser

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

the class FlattenedOptionalTest method testReOrderedBasicOptional.

@Test
public void testReOrderedBasicOptional() throws MalformedQueryException {
    String query = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  OPTIONAL{?e <uri:talksTo> ?l } . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    System.out.println(pq.getTupleExpr());
    List<TupleExpr> joinArgs = getJoinArgs(pq.getTupleExpr(), new ArrayList<TupleExpr>());
    // System.out.println(joinArgs);
    FlattenedOptional optional = (FlattenedOptional) joinArgs.get(0);
    TupleExpr sp1 = joinArgs.get(1);
    TupleExpr sp2 = joinArgs.get(2);
    Assert.assertEquals(false, optional.canRemoveTuple(sp1));
    Assert.assertEquals(false, optional.canAddTuple(sp2));
}
Also used : FlattenedOptional(org.apache.rya.indexing.external.matching.FlattenedOptional) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 28 with SPARQLParser

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

the class FlattenedOptionalTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() throws MalformedQueryException {
    String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e <uri:worksAt> ?c . " + // 
    "  OPTIONAL{?e <uri:talksTo> ?l } . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    List<TupleExpr> joinArgs1 = getJoinArgs(pq1.getTupleExpr(), new ArrayList<TupleExpr>());
    String query2 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "  OPTIONAL{?e <uri:talksTo> ?l } . " + // 
    "}";
    parser = new SPARQLParser();
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    List<TupleExpr> joinArgs2 = getJoinArgs(pq2.getTupleExpr(), new ArrayList<TupleExpr>());
    FlattenedOptional optional1 = (FlattenedOptional) joinArgs1.get(0);
    FlattenedOptional optional2 = (FlattenedOptional) joinArgs2.get(0);
    System.out.println(optional1 + " and " + optional2);
    Assert.assertEquals(optional1, optional2);
    Assert.assertEquals(optional1.hashCode(), optional2.hashCode());
}
Also used : FlattenedOptional(org.apache.rya.indexing.external.matching.FlattenedOptional) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) TupleExpr(org.openrdf.query.algebra.TupleExpr) Test(org.junit.Test)

Example 29 with SPARQLParser

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

the class JoinSegmentTest method testNoMatch.

@Test
public void testNoMatch() throws Exception {
    String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " Filter(?e = <uri:Bob>)" + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
    "  ?e a ?c . " + // 
    "  ?e <uri:talksTo> ?l  . " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    " Filter(?e = <uri:Bob>)" + // 
    " ?e a ?c . " + // 
    " ?e <uri:worksAt> ?l . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    TopOfQueryFilterRelocator.moveFiltersToTop(te1);
    TopOfQueryFilterRelocator.moveFiltersToTop(te1);
    Filter filter1 = (Filter) ((Projection) te1).getArg();
    Filter filter2 = (Filter) ((Projection) te2).getArg();
    QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(filter1);
    QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(filter2);
    Assert.assertEquals(false, seg1.containsQuerySegment(seg2));
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Filter(org.openrdf.query.algebra.Filter) TupleExpr(org.openrdf.query.algebra.TupleExpr) SimpleExternalTupleSet(org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) Test(org.junit.Test)

Example 30 with SPARQLParser

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

the class OptionalJoinSegmentTest method testBasicOptional.

@Test
public void testBasicOptional() throws MalformedQueryException {
    String query1 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  OPTIONAL{?e <uri:talksTo> ?l } . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l " + // 
    "}";
    String query2 = // 
    "" + // 
    "SELECT ?e ?c ?l" + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  OPTIONAL{?e <uri:talksTo> ?l } . " + // 
    "}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq1 = parser.parseQuery(query1, null);
    ParsedQuery pq2 = parser.parseQuery(query2, null);
    TupleExpr te1 = pq1.getTupleExpr();
    TupleExpr te2 = pq2.getTupleExpr();
    Join join = (Join) ((Projection) te1).getArg();
    LeftJoin lj = (LeftJoin) ((Projection) te2).getArg();
    QuerySegment<ExternalTupleSet> seg1 = qFactory.getQuerySegment(join);
    QuerySegment<ExternalTupleSet> seg2 = qFactory.getQuerySegment(lj);
    Assert.assertEquals(true, seg1.containsQuerySegment(seg2));
    Assert.assertEquals(join, seg1.getQuery().getTupleExpr());
    SimpleExternalTupleSet pcj = new SimpleExternalTupleSet((Projection) te2);
    List<QueryModelNode> nodes = seg1.getOrderedNodes();
    QueryModelNode node = nodes.get(0);
    seg1.replaceWithExternalSet(seg2, pcj);
    Set<QueryModelNode> nodeSet = new HashSet<>();
    nodeSet.add(node);
    nodeSet.add(pcj);
    Assert.assertEquals(nodeSet, seg1.getUnOrderedNodes());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join) 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) LeftJoin(org.openrdf.query.algebra.LeftJoin) HashSet(java.util.HashSet) Test(org.junit.Test)

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