Search in sources :

Example 51 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class ParsedQueryUtilTest method findProjection_distinctIsTopNode.

@Test
public void findProjection_distinctIsTopNode() throws MalformedQueryException {
    // A SPARQL query that uses the DISTINCT keyword.
    String sparql = "SELECT DISTINCT ?a ?b " + "WHERE {" + "?a <http://talksTo> ?b" + "}";
    // Run the test.
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery query = parser.parseQuery(sparql, null);
    Optional<Projection> projection = new ParsedQueryUtil().findProjection(query);
    assertTrue(projection.isPresent());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) Test(org.junit.Test)

Example 52 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class SimpleExternalTupleSetTest method hashCode_same.

@Test
public void hashCode_same() throws MalformedQueryException {
    // The common PCJ expression.
    final String sparql = "SELECT ?f ?m ?d { " + "?f <urn:talksTo> ?m . " + "?m <uri:associatesWith> ?d . " + "}";
    final ParsedQuery query = new SPARQLParser().parseQuery(sparql, null);
    final Projection pcjExpression = (Projection) query.getTupleExpr();
    // Create two SimpleExternalTupleSet pbjects using the same expression.
    final SimpleExternalTupleSet testSet = new SimpleExternalTupleSet(pcjExpression);
    final SimpleExternalTupleSet identicalTestSet = new SimpleExternalTupleSet(pcjExpression);
    // Show that they are equal.
    assertEquals(testSet.hashCode(), identicalTestSet.hashCode());
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) Test(org.junit.Test)

Example 53 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class SimpleExternalTupleSetTest method equals_equals.

@Test
public void equals_equals() throws MalformedQueryException {
    // The common PCJ expression.
    final String sparql = "SELECT ?f ?m ?d { " + "?f <urn:talksTo> ?m . " + "?m <uri:associatesWith> ?d . " + "}";
    final ParsedQuery query = new SPARQLParser().parseQuery(sparql, null);
    final Projection pcjExpression = (Projection) query.getTupleExpr();
    // Create two SimpleExternalTupleSet pbjects using the same expression.
    final SimpleExternalTupleSet testSet = new SimpleExternalTupleSet(pcjExpression);
    final SimpleExternalTupleSet identicalTestSet = new SimpleExternalTupleSet(pcjExpression);
    // Show that they are equal.
    assertEquals(testSet, identicalTestSet);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) Test(org.junit.Test)

Example 54 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class SimpleExternalTupleSetTest method equals_notEquals.

@Test
public void equals_notEquals() throws MalformedQueryException {
    // Create the first SimpleExternalTupleSet object.
    final String sparql1 = "SELECT ?f ?m ?d { " + "?f <urn:talksTo> ?m . " + "?m <uri:associatesWith> ?d . " + "}";
    final ParsedQuery query1 = new SPARQLParser().parseQuery(sparql1, null);
    final Projection pcjExpression1 = (Projection) query1.getTupleExpr();
    final SimpleExternalTupleSet set1 = new SimpleExternalTupleSet(pcjExpression1);
    // Create another one using a different expression.
    final String sparql2 = "SELECT ?f ?m ?d { " + "?f <urn:talksTo> ?m . " + "?m <uri:friendsWith> ?d . " + "}";
    final ParsedQuery query2 = new SPARQLParser().parseQuery(sparql2, null);
    final Projection pcjExpression2 = (Projection) query2.getTupleExpr();
    final SimpleExternalTupleSet set2 = new SimpleExternalTupleSet(pcjExpression2);
    // Show they are not equal.
    assertNotEquals(set1, set2);
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) Projection(org.openrdf.query.algebra.Projection) Test(org.junit.Test)

Example 55 with Projection

use of org.openrdf.query.algebra.Projection in project incubator-rya by apache.

the class FlattenedOptionalTest method getJoinArgs.

private List<TupleExpr> getJoinArgs(TupleExpr tupleExpr, List<TupleExpr> joinArgs) {
    if (tupleExpr instanceof Projection) {
        Projection projection = (Projection) tupleExpr;
        getJoinArgs(projection.getArg(), joinArgs);
    } else if (tupleExpr instanceof Join) {
        Join join = (Join) tupleExpr;
        getJoinArgs(join.getLeftArg(), joinArgs);
        getJoinArgs(join.getRightArg(), joinArgs);
    } else if (tupleExpr instanceof LeftJoin) {
        LeftJoin lj = (LeftJoin) tupleExpr;
        joinArgs.add(new FlattenedOptional(lj));
        getJoinArgs(lj.getLeftArg(), joinArgs);
    } else if (tupleExpr instanceof Filter) {
        getJoinArgs(((Filter) tupleExpr).getArg(), joinArgs);
    } else {
        joinArgs.add(tupleExpr);
    }
    return joinArgs;
}
Also used : FlattenedOptional(org.apache.rya.indexing.external.matching.FlattenedOptional) LeftJoin(org.openrdf.query.algebra.LeftJoin) Filter(org.openrdf.query.algebra.Filter) Projection(org.openrdf.query.algebra.Projection) LeftJoin(org.openrdf.query.algebra.LeftJoin) Join(org.openrdf.query.algebra.Join)

Aggregations

Projection (org.openrdf.query.algebra.Projection)76 Test (org.junit.Test)64 StatementPattern (org.openrdf.query.algebra.StatementPattern)41 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)37 ParsedQuery (org.openrdf.query.parser.ParsedQuery)34 TupleExpr (org.openrdf.query.algebra.TupleExpr)33 ExternalTupleSet (org.apache.rya.indexing.external.tupleSet.ExternalTupleSet)27 SimpleExternalTupleSet (org.apache.rya.indexing.external.tupleSet.SimpleExternalTupleSet)27 ProjectionElemList (org.openrdf.query.algebra.ProjectionElemList)24 Var (org.openrdf.query.algebra.Var)24 ArrayList (java.util.ArrayList)23 QueryModelNode (org.openrdf.query.algebra.QueryModelNode)23 ProjectionElem (org.openrdf.query.algebra.ProjectionElem)22 PCJOptimizer (org.apache.rya.indexing.pcj.matching.PCJOptimizer)17 Join (org.openrdf.query.algebra.Join)15 HashSet (java.util.HashSet)14 Union (org.openrdf.query.algebra.Union)10 Resource (org.openrdf.model.Resource)9 MultiProjection (org.openrdf.query.algebra.MultiProjection)9 HashMap (java.util.HashMap)8