ihuzenko commented on a change in pull request #1929: DRILL-6832: Remove the old "unmanaged" external sort URL: https://github.com/apache/drill/pull/1929#discussion_r360521056
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/xsort/PriorityQueueCopierTemplate.java ########## @@ -17,94 +17,95 @@ */ package org.apache.drill.exec.physical.impl.xsort; -import io.netty.buffer.DrillBuf; - import java.io.IOException; import java.util.List; import javax.inject.Named; import org.apache.drill.exec.exception.SchemaChangeException; import org.apache.drill.exec.memory.BufferAllocator; -import org.apache.drill.exec.ops.FragmentContext; import org.apache.drill.exec.record.VectorAccessible; import org.apache.drill.exec.record.VectorAccessibleUtilities; import org.apache.drill.exec.record.selection.SelectionVector4; +import io.netty.buffer.DrillBuf; public abstract class PriorityQueueCopierTemplate implements PriorityQueueCopier { +// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(PriorityQueueCopierTemplate.class); private SelectionVector4 vector4; private List<BatchGroup> batchGroups; private VectorAccessible hyperBatch; private VectorAccessible outgoing; private int size; - private int queueSize; + private int queueSize = 0; @Override - public void setup(FragmentContext context, BufferAllocator allocator, - VectorAccessible hyperBatch, List<BatchGroup> batchGroups, - VectorAccessible outgoing) throws SchemaChangeException { + public void setup(BufferAllocator allocator, VectorAccessible hyperBatch, List<BatchGroup> batchGroups, + VectorAccessible outgoing) throws SchemaChangeException { this.hyperBatch = hyperBatch; this.batchGroups = batchGroups; this.outgoing = outgoing; this.size = batchGroups.size(); final DrillBuf drillBuf = allocator.buffer(4 * size); vector4 = new SelectionVector4(drillBuf, size, Character.MAX_VALUE); - doSetup(context, hyperBatch, outgoing); + doSetup(hyperBatch, outgoing); queueSize = 0; for (int i = 0; i < size; i++) { - vector4.set(i, i, batchGroups.get(i).getNextIndex()); - siftUp(); - queueSize++; + int index = batchGroups.get(i).getNextIndex(); + vector4.set(i, i, index); + if (index > -1) { + siftUp(); + queueSize++; + } } } @Override public int next(int targetRecordCount) { - allocateVectors(targetRecordCount); for (int outgoingIndex = 0; outgoingIndex < targetRecordCount; outgoingIndex++) { if (queueSize == 0) { return 0; } int compoundIndex = vector4.get(0); int batch = compoundIndex >>> 16; assert batch < batchGroups.size() : String.format("batch: %d batchGroups: %d", batch, batchGroups.size()); - doCopy(compoundIndex, outgoingIndex); + try { Review comment: It's better to put whole loop inside try-catch and remove this and ```siftDown()``` one. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services