use of org.eclipse.rdf4j.query.algebra.BinaryTupleOperator 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;
}
use of org.eclipse.rdf4j.query.algebra.BinaryTupleOperator in project rdf4j by eclipse.
the class AbstractQueryBuilder method groupAsJoin.
private TupleExpr groupAsJoin(List<Group> theList) {
BinaryTupleOperator aJoin = new Join();
Filter aFilter = null;
for (Group aGroup : theList) {
TupleExpr aExpr = aGroup.expr();
if (aExpr == null) {
continue;
}
if (aExpr instanceof Filter && (((Filter) aExpr).getArg() == null || ((Filter) aExpr).getArg() instanceof EmptySet)) {
if (aFilter == null) {
aFilter = (Filter) aExpr;
} else {
// if we already have a filter w/ an empty arg, let's And the
// conditions together.
aFilter.setCondition(new And(aFilter.getCondition(), ((Filter) aExpr).getCondition()));
}
continue;
}
if (aFilter != null) {
aFilter.setArg(aExpr);
aExpr = aFilter;
aFilter = null;
}
if (aGroup.isOptional()) {
LeftJoin lj = new LeftJoin();
TupleExpr aLeft = joinOrExpr(aJoin);
if (aLeft != null) {
lj.setLeftArg(aLeft);
lj.setRightArg(aExpr);
aJoin = lj;
continue;
}
}
if (aJoin.getLeftArg() == null) {
aJoin.setLeftArg(aExpr);
} else if (aJoin.getRightArg() == null) {
aJoin.setRightArg(aExpr);
} else {
Join aNewJoin = new Join();
aNewJoin.setLeftArg(aJoin);
aNewJoin.setRightArg(aExpr);
aJoin = aNewJoin;
}
}
TupleExpr aExpr = joinOrExpr(aJoin);
if (aFilter != null) {
aFilter.setArg(aExpr);
aExpr = aFilter;
}
return aExpr;
}
Aggregations