@SuppressWarnings("resource") public void add(RecordBatchData rbd) { long batchBytes = getSize(rbd.getContainer()); if (batchBytes == 0 && batches.size() > 0) { return; } if (runningBatches >= Character.MAX_VALUE) { final String errMsg = String.format("Tried to add more than %d number of batches.", (int) Character.MAX_VALUE); logger.error(errMsg); throw new DrillRuntimeException(errMsg); } if (!reservation.add(rbd.getRecordCount() * 4)) { final String errMsg = String.format("Failed to pre-allocate memory for SV. " + "Existing recordCount*4 = %d, " + "incoming batch recordCount*4 = %d", recordCount * 4, rbd.getRecordCount() * 4); logger.error(errMsg); throw new DrillRuntimeException(errMsg); } if (rbd.getRecordCount() == 0 && batches.size() > 0) { rbd.getContainer().zeroVectors(); SelectionVector2 sv2 = rbd.getSv2(); if (sv2 != null) { sv2.clear(); } return; } runningBatches++; batches.put(rbd.getContainer().getSchema(), rbd); recordCount += rbd.getRecordCount(); }
/** * Add another record batch to the set of record batches. TODO: Refactor this and other {@link #add * (RecordBatchData)} method into one method. * @param batch * @return True if the requested add completed successfully. Returns false in the case that this builder is full and cannot receive additional packages. * @throws SchemaChangeException */ public boolean add(VectorAccessible batch) { if (batch.getSchema().getSelectionVectorMode() == SelectionVectorMode.FOUR_BYTE) { throw new UnsupportedOperationException("A sort cannot currently work against a sv4 batch."); } if (batch.getRecordCount() == 0 && batches.size() > 0) { return true; // skip over empty record batches. } long batchBytes = getSize(batch); if (batchBytes == 0 && batches.size() > 0) { return true; } if (runningBatches >= Character.MAX_VALUE) { return false; // allowed in batch. } if (!reservation.add(batch.getRecordCount() * 4)) { return false; // sv allocation available. } RecordBatchData bd = new RecordBatchData(batch, allocator); runningBatches++; batches.put(batch.getSchema(), bd); recordCount += bd.getRecordCount(); return true; }
throw new SchemaChangeException("Sort currently only supports a single schema."); if (batches.size() > Character.MAX_VALUE) { throw new SchemaChangeException("Sort cannot work on more than %d batches at a time.", (int) Character.MAX_VALUE);