Search in sources :

Example 1 with BinaryTupleOperator

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;
}
Also used : LeftJoin(org.eclipse.rdf4j.query.algebra.LeftJoin) Filter(org.eclipse.rdf4j.query.algebra.Filter) EmptySet(org.eclipse.rdf4j.query.algebra.EmptySet) BinaryTupleOperator(org.eclipse.rdf4j.query.algebra.BinaryTupleOperator) LeftJoin(org.eclipse.rdf4j.query.algebra.LeftJoin) Join(org.eclipse.rdf4j.query.algebra.Join) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Example 2 with BinaryTupleOperator

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;
}
Also used : LeftJoin(org.eclipse.rdf4j.query.algebra.LeftJoin) Filter(org.eclipse.rdf4j.query.algebra.Filter) And(org.eclipse.rdf4j.query.algebra.And) BinaryTupleOperator(org.eclipse.rdf4j.query.algebra.BinaryTupleOperator) EmptySet(org.eclipse.rdf4j.query.algebra.EmptySet) LeftJoin(org.eclipse.rdf4j.query.algebra.LeftJoin) Join(org.eclipse.rdf4j.query.algebra.Join) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Aggregations

BinaryTupleOperator (org.eclipse.rdf4j.query.algebra.BinaryTupleOperator)2 EmptySet (org.eclipse.rdf4j.query.algebra.EmptySet)2 Filter (org.eclipse.rdf4j.query.algebra.Filter)2 Join (org.eclipse.rdf4j.query.algebra.Join)2 LeftJoin (org.eclipse.rdf4j.query.algebra.LeftJoin)2 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)2 And (org.eclipse.rdf4j.query.algebra.And)1