Search in sources :

Example 31 with VectorAccessible

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;
}
Also used : SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) VectorAccessible(org.apache.drill.exec.record.VectorAccessible)

Example 32 with VectorAccessible

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;
}
Also used : SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) VectorAccessible(org.apache.drill.exec.record.VectorAccessible)

Aggregations

VectorAccessible (org.apache.drill.exec.record.VectorAccessible)32 ValueVector (org.apache.drill.exec.vector.ValueVector)17 Test (org.junit.Test)14 UInt4Vector (org.apache.drill.exec.vector.UInt4Vector)12 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)8 RecordBatchSizer (org.apache.drill.exec.record.RecordBatchSizer)8 RepeatedVarCharVector (org.apache.drill.exec.vector.RepeatedVarCharVector)8 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 MaterializedField (org.apache.drill.exec.record.MaterializedField)7 ScanBatch (org.apache.drill.exec.physical.impl.ScanBatch)6 RecordBatch (org.apache.drill.exec.record.RecordBatch)6 VarCharVector (org.apache.drill.exec.vector.VarCharVector)6 ExecTest (org.apache.drill.exec.ExecTest)4 FragmentContextImpl (org.apache.drill.exec.ops.FragmentContextImpl)4 SelectionVector2 (org.apache.drill.exec.record.selection.SelectionVector2)4 SelectionVector4 (org.apache.drill.exec.record.selection.SelectionVector4)4 Text (org.apache.drill.exec.util.Text)4 RepeatedListVector (org.apache.drill.exec.vector.complex.RepeatedListVector)4 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)4 List (java.util.List)3