use of org.apache.drill.exec.record.VectorAccessible in project drill by apache.
the class FrameSupportTemplate method aggregatePeers.
/**
* Aggregates all peer rows of current row
* @param start starting row of the current frame
* @return num peer rows for current row
*/
private long aggregatePeers(final int start) {
logger.trace("aggregating rows starting from {}", start);
final boolean unboundedFollowing = popConfig.getEnd().isUnbounded();
VectorAccessible last = current;
long length = 0;
// start processing first batch and, if necessary, move to next batches
for (WindowDataBatch batch : batches) {
try {
setupEvaluatePeer(batch, container);
} catch (SchemaChangeException e) {
throw AbstractRecordBatch.schemaChangeException(e, "Window", logger);
}
final int recordCount = batch.getRecordCount();
// for every remaining row in the partition, count it if it's a peer row
for (int row = (batch == current) ? start : 0; row < recordCount; row++, length++) {
if (unboundedFollowing) {
if (length >= remainingRows) {
break;
}
} else {
if (!isPeer(start, current, row, batch)) {
break;
}
}
evaluatePeer(row);
last = batch;
frameLastRow = row;
}
}
try {
setupReadLastValue(last, container);
} catch (SchemaChangeException e) {
throw AbstractRecordBatch.schemaChangeException(e, "Window", logger);
}
return length;
}
use of org.apache.drill.exec.record.VectorAccessible in project drill by apache.
the class WindowFrameRecordBatch method canDoWork.
/**
* @return true when all window functions are ready to process the current
* batch (it's the first batch currently held in memory)
*/
private boolean canDoWork() {
if (batches.size() < 2) {
// current partition
return false;
}
VectorAccessible current = batches.get(0);
int currentSize = current.getRecordCount();
VectorAccessible last = batches.get(batches.size() - 1);
int lastSize = last.getRecordCount();
boolean partitionEndReached;
boolean frameEndReached;
try {
partitionEndReached = !framers[0].isSamePartition(currentSize - 1, current, lastSize - 1, last);
frameEndReached = partitionEndReached || !framers[0].isPeer(currentSize - 1, current, lastSize - 1, last);
for (WindowFunction function : functions) {
if (!function.canDoWork(batches.size(), popConfig, frameEndReached, partitionEndReached)) {
return false;
}
}
} catch (SchemaChangeException e) {
throw new UnsupportedOperationException(e);
}
return true;
}
Aggregations