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());
}
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());
}
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);
}
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);
}
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;
}
Aggregations