Search in sources :

Example 1 with RowSetNavigatorData

use of org.hsqldb_voltpatches.navigator.RowSetNavigatorData in project voltdb by VoltDB.

the class QueryExpression method getResult.

Result getResult(Session session, int maxRows) {
    int currentMaxRows = unionType == UNION_ALL ? maxRows : Integer.MAX_VALUE;
    Result first = leftQueryExpression.getResult(session, currentMaxRows);
    RowSetNavigatorData navigator = (RowSetNavigatorData) first.getNavigator();
    Result second = rightQueryExpression.getResult(session, currentMaxRows);
    RowSetNavigatorData rightNavigator = (RowSetNavigatorData) second.getNavigator();
    if (unionCorresponding) {
        RowSetNavigatorData rowSet = new RowSetNavigatorData(session, this);
        rowSet.copy(navigator, leftQueryExpression.unionColumnMap);
        navigator = rowSet;
        first.setNavigator(navigator);
        first.metaData = this.getMetaData();
        rowSet = new RowSetNavigatorData(session, this);
        if (unionType != UNION && unionType != UNION_ALL) {
            rowSet.copy(rightNavigator, rightQueryExpression.unionColumnMap);
            rightNavigator = rowSet;
        }
    }
    switch(unionType) {
        case UNION:
            navigator.union(rightNavigator, rightQueryExpression.unionColumnMap);
            break;
        case UNION_ALL:
            navigator.unionAll(rightNavigator, rightQueryExpression.unionColumnMap);
            break;
        case INTERSECT:
            navigator.intersect(rightNavigator);
            break;
        case INTERSECT_ALL:
            navigator.intersectAll(rightNavigator);
            break;
        case EXCEPT:
            navigator.except(rightNavigator);
            break;
        case EXCEPT_ALL:
            navigator.exceptAll(rightNavigator);
            break;
        default:
            throw Error.runtimeError(ErrorCode.U_S0500, "QueryExpression");
    }
    if (sortAndSlice.hasOrder()) {
        RowSetNavigatorData nav = (RowSetNavigatorData) first.getNavigator();
        nav.sortUnion(sortAndSlice);
        nav.trim(sortAndSlice.getLimitStart(session), sortAndSlice.getLimitCount(session, maxRows));
    }
    navigator.reset();
    return first;
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData) Result(org.hsqldb_voltpatches.result.Result)

Example 2 with RowSetNavigatorData

use of org.hsqldb_voltpatches.navigator.RowSetNavigatorData in project voltdb by VoltDB.

the class QuerySpecification method buildResult.

private Result buildResult(Session session, int limitcount) {
    RowSetNavigatorData navigator = new RowSetNavigatorData(session, this);
    Result result = Result.newResult(navigator);
    result.metaData = resultMetaData;
    result.setDataResultConcurrency(isUpdatable);
    // Test for early return case added by VoltDB to support LIMIT 0 in "HSQL backend".
    if (limitcount == 0) {
        return result;
    }
    // End of VoltDB extension
    int fullJoinIndex = 0;
    RangeIterator[] rangeIterators = new RangeIterator[rangeVariables.length];
    for (int i = 0; i < rangeVariables.length; i++) {
        rangeIterators[i] = rangeVariables[i].getIterator(session);
    }
    for (int currentIndex = 0; ; ) {
        if (currentIndex < fullJoinIndex) {
            boolean end = true;
            for (int i = fullJoinIndex + 1; i < rangeVariables.length; i++) {
                if (rangeVariables[i].isRightJoin) {
                    rangeIterators[i] = rangeVariables[i].getFullIterator(session, (RangeIteratorMain) rangeIterators[i]);
                    fullJoinIndex = i;
                    currentIndex = i;
                    end = false;
                    break;
                }
            }
            if (end) {
                break;
            }
        }
        RangeIterator it = rangeIterators[currentIndex];
        if (it.next()) {
            if (currentIndex < rangeVariables.length - 1) {
                currentIndex++;
                continue;
            }
        } else {
            it.reset();
            currentIndex--;
            continue;
        }
        session.sessionData.startRowProcessing();
        Object[] data = new Object[indexLimitData];
        for (int i = 0; i < indexStartAggregates; i++) {
            if (isAggregated && aggregateCheck[i]) {
                continue;
            } else {
                data[i] = exprColumns[i].getValue(session);
            }
        }
        for (int i = indexLimitVisible; i < indexLimitRowId; i++) {
            data[i] = it.getRowidObject();
        }
        Object[] groupData = null;
        if (isAggregated || isGrouped) {
            groupData = navigator.getGroupData(data);
            if (groupData != null) {
                data = groupData;
            }
        }
        for (int i = indexStartAggregates; i < indexLimitExpressions; i++) {
            data[i] = ((ExpressionAggregate) exprColumns[i]).updateAggregatingValue(session, data[i]);
        }
        if (groupData == null) {
            navigator.add(data);
        }
        if (isAggregated || isGrouped) {
            continue;
        }
        if (navigator.getSize() >= limitcount) {
            break;
        }
    }
    navigator.reset();
    if (!isGrouped && !isAggregated) {
        return result;
    }
    if (isAggregated) {
        if (!isGrouped && navigator.getSize() == 0) {
            Object[] data = new Object[exprColumns.length];
            navigator.add(data);
        }
        RangeIteratorBase it = new RangeIteratorBase(session, navigator.store, navigator.table, resultRangePosition);
        session.sessionContext.setRangeIterator(it);
        while (it.next()) {
            for (int i = indexStartAggregates; i < indexLimitExpressions; i++) {
                ExpressionAggregate aggregate = (ExpressionAggregate) exprColumns[i];
                it.currentData[i] = aggregate.getAggregatedValue(session, it.currentData[i]);
            }
            for (int i = 0; i < indexStartAggregates; i++) {
                if (aggregateCheck[i]) {
                    it.currentData[i] = exprColumns[i].getValue(session);
                }
            }
        }
    }
    navigator.reset();
    if (havingCondition != null) {
        while (navigator.hasNext()) {
            Object[] data = navigator.getNext();
            if (!Boolean.TRUE.equals(data[indexLimitVisible + groupByColumnCount])) {
                navigator.remove();
            }
        }
        navigator.reset();
    }
    return result;
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData) RangeIterator(org.hsqldb_voltpatches.navigator.RangeIterator) RangeIteratorBase(org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase) RangeIteratorMain(org.hsqldb_voltpatches.RangeVariable.RangeIteratorMain) Result(org.hsqldb_voltpatches.result.Result)

Example 3 with RowSetNavigatorData

use of org.hsqldb_voltpatches.navigator.RowSetNavigatorData in project voltdb by VoltDB.

the class SubQuery method hasUniqueNotNullRows.

public boolean hasUniqueNotNullRows(Session session) {
    RowSetNavigatorData navigator = new RowSetNavigatorData(session, table);
    boolean result = navigator.hasUniqueNotNullRows();
    return result;
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData)

Example 4 with RowSetNavigatorData

use of org.hsqldb_voltpatches.navigator.RowSetNavigatorData in project voltdb by VoltDB.

the class QuerySpecification method getSingleResult.

private Result getSingleResult(Session session, int rowCount) {
    int maxRows = getMaxRowCount(session, rowCount);
    Result r = buildResult(session, maxRows);
    RowSetNavigatorData navigator = (RowSetNavigatorData) r.getNavigator();
    if (isDistinctSelect) {
        navigator.removeDuplicates();
    }
    navigator.sortOrder();
    navigator.trim(getLimitStart(session), getLimitCount(session, rowCount));
    return r;
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData) Result(org.hsqldb_voltpatches.result.Result)

Example 5 with RowSetNavigatorData

use of org.hsqldb_voltpatches.navigator.RowSetNavigatorData in project voltdb by VoltDB.

the class SubQuery method materialise.

/**
     * Fills the table with a result set
     */
public void materialise(Session session) {
    PersistentStore store;
    // table constructors
    if (isDataExpression) {
        store = session.sessionData.getSubqueryRowStore(table);
        dataExpression.insertValuesIntoSubqueryTable(session, store);
        return;
    }
    Result result = queryExpression.getResult(session, isExistsPredicate ? 1 : 0);
    RowSetNavigatorData navigator = ((RowSetNavigatorData) result.getNavigator());
    if (uniqueRows) {
        navigator.removeDuplicates();
    }
    store = session.sessionData.getSubqueryRowStore(table);
    table.insertResult(store, result);
    result.getNavigator().close();
}
Also used : RowSetNavigatorData(org.hsqldb_voltpatches.navigator.RowSetNavigatorData) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Result(org.hsqldb_voltpatches.result.Result)

Aggregations

RowSetNavigatorData (org.hsqldb_voltpatches.navigator.RowSetNavigatorData)5 Result (org.hsqldb_voltpatches.result.Result)4 RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)1 RangeIteratorMain (org.hsqldb_voltpatches.RangeVariable.RangeIteratorMain)1 RangeIterator (org.hsqldb_voltpatches.navigator.RangeIterator)1 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)1