use of org.hsqldb_voltpatches.navigator.RangeIterator in project voltdb by VoltDB.
the class StatementDML method executeDeleteStatement.
// fredt - currently deletes that fail due to referential constraints are caught
// prior to actual delete operation
/**
* Executes a DELETE statement. It is assumed that the argument is
* of the correct type.
*
* @return the result of executing the statement
*/
Result executeDeleteStatement(Session session) {
int count = 0;
RowSetNavigatorLinkedList oldRows = new RowSetNavigatorLinkedList();
RangeIterator it = RangeVariable.getIterator(session, targetRangeVariables);
while (it.next()) {
Row currentRow = it.getCurrentRow();
oldRows.add(currentRow);
}
count = delete(session, baseTable, oldRows);
if (restartIdentity && targetTable.identitySequence != null) {
targetTable.identitySequence.reset();
}
return Result.getUpdateCountResult(count);
}
use of org.hsqldb_voltpatches.navigator.RangeIterator 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;
}
use of org.hsqldb_voltpatches.navigator.RangeIterator in project voltdb by VoltDB.
the class StatementDML method executeMergeStatement.
/**
* Executes a MERGE statement. It is assumed that the argument
* is of the correct type.
*
* @return Result object
*/
Result executeMergeStatement(Session session) {
Result resultOut = null;
RowSetNavigator generatedNavigator = null;
PersistentStore store = session.sessionData.getRowStore(baseTable);
if (generatedIndexes != null) {
resultOut = Result.newUpdateCountResult(generatedResultMetaData, 0);
generatedNavigator = resultOut.getChainedResult().getNavigator();
}
int count = 0;
// data generated for non-matching rows
RowSetNavigatorClient newData = new RowSetNavigatorClient(8);
// rowset for update operation
HashMappedList updateRowSet = new HashMappedList();
RangeVariable[] joinRangeIterators = targetRangeVariables;
// populate insert and update lists
RangeIterator[] rangeIterators = new RangeIterator[joinRangeIterators.length];
for (int i = 0; i < joinRangeIterators.length; i++) {
rangeIterators[i] = joinRangeIterators[i].getIterator(session);
}
for (int currentIndex = 0; 0 <= currentIndex; ) {
RangeIterator it = rangeIterators[currentIndex];
boolean beforeFirst = it.isBeforeFirst();
if (it.next()) {
if (currentIndex < joinRangeIterators.length - 1) {
currentIndex++;
continue;
}
} else {
if (currentIndex == 1 && beforeFirst) {
Object[] data = getMergeInsertData(session);
if (data != null) {
newData.add(data);
}
}
it.reset();
currentIndex--;
continue;
}
// row matches!
if (updateExpressions != null) {
// this is always the second iterator
Row row = it.getCurrentRow();
Object[] data = getUpdatedData(session, baseTable, updateColumnMap, updateExpressions, baseTable.getColumnTypes(), row.getData());
updateRowSet.add(row, data);
}
}
// update any matched rows
if (updateRowSet.size() > 0) {
count = update(session, baseTable, updateRowSet);
}
// insert any non-matched rows
newData.beforeFirst();
while (newData.hasNext()) {
Object[] data = newData.getNext();
baseTable.insertRow(session, store, data);
if (generatedNavigator != null) {
Object[] generatedValues = getGeneratedColumns(data);
generatedNavigator.add(generatedValues);
}
}
baseTable.fireAfterTriggers(session, Trigger.INSERT_AFTER, newData);
count += newData.getSize();
if (resultOut == null) {
return Result.getUpdateCountResult(count);
} else {
resultOut.setUpdateCount(count);
return resultOut;
}
}
Aggregations