Search in sources :

Example 1 with RangeIteratorBase

use of org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase 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 2 with RangeIteratorBase

use of org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase in project voltdb by VoltDB.

the class StatementDML method executeUpdateStatement.

/**
     * Executes an UPDATE statement.  It is assumed that the argument
     * is of the correct type.
     *
     * @return the result of executing the statement
     */
Result executeUpdateStatement(Session session) {
    int count = 0;
    Expression[] colExpressions = updateExpressions;
    HashMappedList rowset = new HashMappedList();
    Type[] colTypes = baseTable.getColumnTypes();
    RangeIteratorBase it = RangeVariable.getIterator(session, targetRangeVariables);
    Expression checkCondition = null;
    if (targetTable != baseTable) {
        checkCondition = ((TableDerived) targetTable).getQueryExpression().getMainSelect().checkQueryCondition;
    }
    while (it.next()) {
        session.sessionData.startRowProcessing();
        Row row = it.getCurrentRow();
        Object[] data = row.getData();
        Object[] newData = getUpdatedData(session, baseTable, updateColumnMap, colExpressions, colTypes, data);
        if (checkCondition != null) {
            it.currentData = newData;
            boolean check = checkCondition.testCondition(session);
            if (!check) {
                throw Error.error(ErrorCode.X_44000);
            }
        }
        rowset.add(row, newData);
    }
    /* debug 190
        if (rowset.size() == 0) {
            System.out.println(targetTable.getName().name + " zero update: session "
                               + session.getId());
        } else if (rowset.size() >1) {
           System.out.println("multiple update: session "
                              + session.getId() + ", " + rowset.size());
       }

//* debug 190 */
    count = update(session, baseTable, rowset);
    return Result.getUpdateCountResult(count);
}
Also used : HashMappedList(org.hsqldb_voltpatches.lib.HashMappedList) Type(org.hsqldb_voltpatches.types.Type) RangeIteratorBase(org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)

Example 3 with RangeIteratorBase

use of org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase in project voltdb by VoltDB.

the class StatementInsert method getResult.

/**
     * Executes an INSERT_SELECT statement.  It is assumed that the argument
     * is of the correct type.
     *
     * @return the result of executing the statement
     */
Result getResult(Session session) {
    Table table = baseTable;
    Result resultOut = null;
    RowSetNavigator generatedNavigator = null;
    PersistentStore store = session.sessionData.getRowStore(baseTable);
    if (generatedIndexes != null) {
        resultOut = Result.newUpdateCountResult(generatedResultMetaData, 0);
        generatedNavigator = resultOut.getChainedResult().getNavigator();
    }
    RowSetNavigator newDataNavigator = queryExpression == null ? getInsertValuesNavigator(session) : getInsertSelectNavigator(session);
    Expression checkCondition = null;
    RangeIteratorBase checkIterator = null;
    if (targetTable != baseTable) {
        QuerySpecification select = ((TableDerived) targetTable).getQueryExpression().getMainSelect();
        checkCondition = select.checkQueryCondition;
        if (checkCondition != null) {
            checkIterator = select.rangeVariables[0].getIterator(session);
        }
    }
    while (newDataNavigator.hasNext()) {
        Object[] data = newDataNavigator.getNext();
        if (checkCondition != null) {
            checkIterator.currentData = data;
            boolean check = checkCondition.testCondition(session);
            if (!check) {
                throw Error.error(ErrorCode.X_44000);
            }
        }
        table.insertRow(session, store, data);
        if (generatedNavigator != null) {
            Object[] generatedValues = getGeneratedColumns(data);
            generatedNavigator.add(generatedValues);
        }
    }
    newDataNavigator.beforeFirst();
    table.fireAfterTriggers(session, Trigger.INSERT_AFTER, newDataNavigator);
    if (resultOut == null) {
        resultOut = Result.getUpdateCountResult(newDataNavigator.getSize());
    } else {
        resultOut.setUpdateCount(newDataNavigator.getSize());
    }
    return resultOut;
}
Also used : RangeIteratorBase(org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase) RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Result(org.hsqldb_voltpatches.result.Result)

Example 4 with RangeIteratorBase

use of org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase in project voltdb by VoltDB.

the class Constraint method checkCheckConstraint.

/*
     * Tests a row against this CHECK constraint.
     */
void checkCheckConstraint(Session session, Table table, Object[] data) {
    /*
        if (session.compiledStatementExecutor.rangeIterators[1] == null) {
            session.compiledStatementExecutor.rangeIterators[1] =
                rangeVariable.getIterator(session);
        }
*/
    RangeIteratorBase it = (RangeIteratorBase) session.sessionContext.getCheckIterator();
    if (it == null) {
        it = rangeVariable.getIterator(session);
        session.sessionContext.setCheckIterator(it);
    }
    it.currentData = data;
    boolean nomatch = Boolean.FALSE.equals(check.getValue(session));
    it.currentData = null;
    if (nomatch) {
        String[] info = new String[] { name.name, table.tableName.name };
        throw Error.error(ErrorCode.X_23504, ErrorCode.CONSTRAINT, info);
    }
}
Also used : RangeIteratorBase(org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)

Aggregations

RangeIteratorBase (org.hsqldb_voltpatches.RangeVariable.RangeIteratorBase)4 Result (org.hsqldb_voltpatches.result.Result)2 RangeIteratorMain (org.hsqldb_voltpatches.RangeVariable.RangeIteratorMain)1 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)1 RangeIterator (org.hsqldb_voltpatches.navigator.RangeIterator)1 RowSetNavigator (org.hsqldb_voltpatches.navigator.RowSetNavigator)1 RowSetNavigatorData (org.hsqldb_voltpatches.navigator.RowSetNavigatorData)1 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)1 Type (org.hsqldb_voltpatches.types.Type)1