Search in sources :

Example 6 with Reduced

use of org.eclipse.rdf4j.query.algebra.Reduced in project rdf4j by eclipse.

the class AbstractQueryBuilder method query.

/**
 * @inheritDoc
 */
public T query() {
    UnaryTupleOperator aRoot = null;
    UnaryTupleOperator aCurr = null;
    if (mLimit != -1 || mOffset != -1) {
        Slice aSlice = new Slice();
        if (mLimit != -1) {
            aSlice.setLimit(mLimit);
        }
        if (mOffset != -1) {
            aSlice.setOffset(mOffset);
        }
        aRoot = aCurr = aSlice;
    }
    if (mOrderByElems != null && !mOrderByElems.isEmpty()) {
        Order aOrder = new Order();
        aOrder.addElements(mOrderByElems);
        if (aRoot == null) {
            aRoot = aCurr = aOrder;
        } else {
            aCurr.setArg(aOrder);
            aCurr = aOrder;
        }
    }
    if (mDistinct) {
        Distinct aDistinct = new Distinct();
        if (aRoot == null) {
            aRoot = aCurr = aDistinct;
        } else {
            aCurr.setArg(aDistinct);
            aCurr = aDistinct;
        }
    }
    if (mReduced) {
        Reduced aReduced = new Reduced();
        if (aRoot == null) {
            aRoot = aCurr = aReduced;
        } else {
            aCurr.setArg(aReduced);
            aCurr = aReduced;
        }
    }
    TupleExpr aJoin = join();
    if (mQuery instanceof ParsedTupleQuery && mProjectionVars.isEmpty()) {
        VarNameCollector aCollector = new VarNameCollector();
        aJoin.visit(aCollector);
        mProjectionVars.addAll(aCollector.getVarNames());
    } else if (mQuery instanceof ParsedGraphQuery && mProjectionPatterns.isEmpty()) {
        StatementPatternCollector aCollector = new StatementPatternCollector();
        aJoin.visit(aCollector);
        mProjectionPatterns.addAll(aCollector.getStatementPatterns());
    }
    UnaryTupleOperator aProjection = projection();
    if (aRoot == null) {
        aRoot = aCurr = aProjection;
    } else {
        aCurr.setArg(aProjection);
    }
    if (aProjection.getArg() == null) {
        aCurr = aProjection;
    } else {
        // I think this is always a safe cast
        aCurr = (UnaryTupleOperator) aProjection.getArg();
    }
    if (aJoin != null) {
        aCurr.setArg(aJoin);
    }
    mQuery.setTupleExpr(aRoot);
    if (!mFrom.isEmpty() || !mFromNamed.isEmpty()) {
        SimpleDataset aDataset = new SimpleDataset();
        for (IRI aFrom : mFrom) {
            aDataset.addDefaultGraph(aFrom);
        }
        for (IRI aFrom : mFromNamed) {
            aDataset.addNamedGraph(aFrom);
        }
        mQuery.setDataset(aDataset);
    }
    return mQuery;
}
Also used : Order(org.eclipse.rdf4j.query.algebra.Order) StatementPatternCollector(org.eclipse.rdf4j.query.algebra.helpers.StatementPatternCollector) IRI(org.eclipse.rdf4j.model.IRI) Distinct(org.eclipse.rdf4j.query.algebra.Distinct) UnaryTupleOperator(org.eclipse.rdf4j.query.algebra.UnaryTupleOperator) Slice(org.eclipse.rdf4j.query.algebra.Slice) ParsedGraphQuery(org.eclipse.rdf4j.query.parser.ParsedGraphQuery) VarNameCollector(org.eclipse.rdf4j.query.algebra.helpers.VarNameCollector) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) Reduced(org.eclipse.rdf4j.query.algebra.Reduced) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ParsedTupleQuery(org.eclipse.rdf4j.query.parser.ParsedTupleQuery)

Aggregations

Reduced (org.eclipse.rdf4j.query.algebra.Reduced)6 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)6 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)5 Extension (org.eclipse.rdf4j.query.algebra.Extension)5 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)5 Projection (org.eclipse.rdf4j.query.algebra.Projection)5 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)5 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)5 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)5 Var (org.eclipse.rdf4j.query.algebra.Var)5 ArrayList (java.util.ArrayList)4 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)4 BNodeGenerator (org.eclipse.rdf4j.query.algebra.BNodeGenerator)3 EmptySet (org.eclipse.rdf4j.query.algebra.EmptySet)3 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)3 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)3 HashMap (java.util.HashMap)2 Order (org.eclipse.rdf4j.query.algebra.Order)2 LinkedHashMap (java.util.LinkedHashMap)1 IRI (org.eclipse.rdf4j.model.IRI)1