use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class TupleExprs method containsSubquery.
/**
* Verifies if the supplied {@link TupleExpr} contains a {@link Projection} with the subquery flag set to
* true (default). If the supplied TupleExpr is a {@link Join} or contains a {@link Join}, projections
* inside that Join's arguments will not be taken into account.
*
* @param t
* a tuple expression.
* @return <code>true</code> if the TupleExpr contains a subquery projection (outside of a Join),
* <code>false</code> otherwise.
*/
public static boolean containsSubquery(TupleExpr t) {
Deque<TupleExpr> queue = new ArrayDeque<>();
queue.add(t);
while (!queue.isEmpty()) {
TupleExpr n = queue.removeFirst();
if (n instanceof Projection && ((Projection) n).isSubquery()) {
return true;
} else if (n instanceof Join) {
// taken into account
return false;
} else {
queue.addAll(getChildren(n));
}
}
return false;
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class SPARQLParserTest method testParsedGraphQueryRootNode.
@Test
public void testParsedGraphQueryRootNode() throws Exception {
StringBuilder qb = new StringBuilder();
qb.append("CONSTRUCT WHERE {?a <foo:bar> \"test\"}");
ParsedGraphQuery q = (ParsedGraphQuery) parser.parseQuery(qb.toString(), null);
TupleExpr te = q.getTupleExpr();
assertNotNull(te);
assertTrue(te instanceof Projection);
assertNull(te.getParentNode());
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class SPARQLParserTest method testSES1922PathSequenceWithValueConstant.
@Test
public void testSES1922PathSequenceWithValueConstant() throws Exception {
StringBuilder qb = new StringBuilder();
qb.append("ASK {?A (<foo:bar>)/<foo:foo> <foo:objValue>} ");
ParsedQuery q = parser.parseQuery(qb.toString(), null);
TupleExpr te = q.getTupleExpr();
assertNotNull(te);
assertTrue(te instanceof Slice);
Slice s = (Slice) te;
assertTrue(s.getArg() instanceof Join);
Join j = (Join) s.getArg();
assertTrue(j.getLeftArg() instanceof StatementPattern);
assertTrue(j.getRightArg() instanceof StatementPattern);
StatementPattern leftArg = (StatementPattern) j.getLeftArg();
StatementPattern rightArg = (StatementPattern) j.getRightArg();
assertTrue(leftArg.getObjectVar().equals(rightArg.getSubjectVar()));
assertEquals(leftArg.getObjectVar().getName(), rightArg.getSubjectVar().getName());
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class SPARQLParserTest method testSES1927UnequalLiteralValueConstants1.
@Test
public void testSES1927UnequalLiteralValueConstants1() throws Exception {
StringBuilder qb = new StringBuilder();
qb.append("ASK {?a <foo:bar> \"test\". ?a <foo:foo> \"test\"@en .} ");
ParsedQuery q = parser.parseQuery(qb.toString(), null);
TupleExpr te = q.getTupleExpr();
assertNotNull(te);
assertTrue(te instanceof Slice);
Slice s = (Slice) te;
assertTrue(s.getArg() instanceof Join);
Join j = (Join) s.getArg();
assertTrue(j.getLeftArg() instanceof StatementPattern);
assertTrue(j.getRightArg() instanceof StatementPattern);
StatementPattern leftArg = (StatementPattern) j.getLeftArg();
StatementPattern rightArg = (StatementPattern) j.getRightArg();
assertFalse(leftArg.getObjectVar().equals(rightArg.getObjectVar()));
assertNotEquals(leftArg.getObjectVar().getName(), rightArg.getObjectVar().getName());
}
use of org.eclipse.rdf4j.query.algebra.TupleExpr in project rdf4j by eclipse.
the class BasicGroup method expr.
private TupleExpr expr(boolean filterExpr) {
TupleExpr aExpr = null;
if (mExpressions.isEmpty() && mFilters.isEmpty()) {
if (mChildren.isEmpty()) {
return null;
}
} else if (mExpressions.isEmpty() && !mFilters.isEmpty()) {
if (mChildren.isEmpty()) {
aExpr = new Filter(new EmptySet(), filtersAsAnd());
}
} else {
aExpr = asJoin(mExpressions);
if (filterExpr) {
aExpr = filteredTuple(aExpr);
}
}
if (!mChildren.isEmpty()) {
for (Group aGroup : mChildren) {
if (aExpr == null) {
if (mExpressions.isEmpty() && !mFilters.isEmpty()) {
aExpr = new Filter(aGroup.expr(), filtersAsAnd());
} else {
aExpr = aGroup.expr();
}
} else {
BinaryTupleOperator aJoin = aGroup.isOptional() ? new LeftJoin() : new Join();
aJoin.setLeftArg(aExpr);
if (aGroup.isOptional() && aJoin instanceof LeftJoin && aGroup instanceof BasicGroup && !((BasicGroup) aGroup).mFilters.isEmpty()) {
BasicGroup aBasicGroup = (BasicGroup) aGroup;
aJoin.setRightArg(aBasicGroup.expr(false));
((LeftJoin) aJoin).setCondition(aBasicGroup.filtersAsAnd());
} else {
aJoin.setRightArg(aGroup.expr());
}
aExpr = aJoin;
}
}
}
return aExpr;
}
Aggregations