use of org.apache.drill.exec.exception.SchemaChangeException in project drill by apache.
the class MergeSort method merge.
/**
* Merge the set of in-memory batches to produce a single logical output in the given
* destination container, indexed by an SV4.
*
* @param batchGroups the complete set of in-memory batches
* @param batch the record batch (operator) for the sort operator
* @param destContainer the vector container for the sort operator
* @return the sv4 for this operator
*/
public SelectionVector4 merge(LinkedList<BatchGroup.InputBatch> batchGroups, VectorAccessible batch, VectorContainer destContainer) {
// Add the buffered batches to a collection that MSorter can use.
// The builder takes ownership of the batches and will release them if
// an error occurs.
builder = new SortRecordBatchBuilder(oAllocator);
for (BatchGroup.InputBatch group : batchGroups) {
RecordBatchData rbd = new RecordBatchData(group.getContainer(), oAllocator);
rbd.setSv2(group.getSv2());
builder.add(rbd);
}
batchGroups.clear();
try {
builder.build(context, destContainer);
sv4 = builder.getSv4();
mSorter = opCg.createNewMSorter(batch);
mSorter.setup(context, oAllocator, sv4, destContainer, sv4.getCount());
} catch (SchemaChangeException e) {
throw UserException.unsupportedError(e).message("Unexpected schema change - likely code error.").build(logger);
}
// For testing memory-leaks, inject exception after mSorter finishes setup
ExternalSortBatch.injector.injectUnchecked(context.getExecutionControls(), ExternalSortBatch.INTERRUPTION_AFTER_SETUP);
mSorter.sort(destContainer);
// sort may have prematurely exited due to should continue returning false.
if (!context.shouldContinue()) {
return null;
}
// For testing memory-leak purpose, inject exception after mSorter finishes sorting
ExternalSortBatch.injector.injectUnchecked(context.getExecutionControls(), ExternalSortBatch.INTERRUPTION_AFTER_SORT);
sv4 = mSorter.getSV4();
destContainer.buildSchema(SelectionVectorMode.FOUR_BYTE);
return sv4;
}
use of org.apache.drill.exec.exception.SchemaChangeException in project drill by apache.
the class ExternalSortBatch method newSV2.
private SelectionVector2 newSV2() throws OutOfMemoryException, InterruptedException {
@SuppressWarnings("resource") SelectionVector2 sv2 = new SelectionVector2(oAllocator);
if (!sv2.allocateNewSafe(incoming.getRecordCount())) {
try {
@SuppressWarnings("resource") final BatchGroup merged = mergeAndSpill(batchGroups);
if (merged != null) {
spilledBatchGroups.add(merged);
} else {
throw UserException.memoryError("Unable to allocate sv2 for %d records, and not enough batchGroups to spill.", incoming.getRecordCount()).addContext("batchGroups.size", batchGroups.size()).addContext("spilledBatchGroups.size", spilledBatchGroups.size()).addContext("allocated memory", oAllocator.getAllocatedMemory()).addContext("allocator limit", oAllocator.getLimit()).build(logger);
}
} catch (SchemaChangeException e) {
throw new RuntimeException(e);
}
int waitTime = 1;
while (true) {
try {
Thread.sleep(waitTime * 1000);
} catch (final InterruptedException e) {
if (!context.shouldContinue()) {
throw e;
}
}
waitTime *= 2;
if (sv2.allocateNewSafe(incoming.getRecordCount())) {
break;
}
if (waitTime >= 32) {
throw new OutOfMemoryException("Unable to allocate sv2 buffer after repeated attempts");
}
}
}
for (int i = 0; i < incoming.getRecordCount(); i++) {
sv2.setIndex(i, (char) i);
}
sv2.setRecordCount(incoming.getRecordCount());
return sv2;
}
use of org.apache.drill.exec.exception.SchemaChangeException in project drill by apache.
the class CopierHolder method createCopier.
/**
* Prepare a copier which will write a collection of vectors to disk. The copier
* uses generated code to do the actual writes. If the copier has not yet been
* created, generate code and create it. If it has been created, close it and
* prepare it for a new collection of batches.
*
* @param batch the (hyper) batch of vectors to be copied
* @param batchGroupList same batches as above, but represented as a list
* of individual batches
* @param outputContainer the container into which to copy the batches
*/
@SuppressWarnings("unchecked")
private void createCopier(VectorAccessible batch, List<? extends BatchGroup> batchGroupList, VectorContainer outputContainer) {
if (copier != null) {
opCodeGen.closeCopier();
} else {
copier = opCodeGen.getCopier(batch);
}
for (VectorWrapper<?> i : batch) {
@SuppressWarnings("resource") ValueVector v = TypeHelper.getNewVector(i.getField(), allocator);
outputContainer.add(v);
}
try {
copier.setup(context, allocator, batch, (List<BatchGroup>) batchGroupList, outputContainer);
} catch (SchemaChangeException e) {
throw UserException.unsupportedError(e).message("Unexpected schema change - likely code error.").build(logger);
}
}
use of org.apache.drill.exec.exception.SchemaChangeException in project drill by apache.
the class RemovingRecordBatch method getGenerated2Copier.
private Copier getGenerated2Copier() throws SchemaChangeException {
Preconditions.checkArgument(incoming.getSchema().getSelectionVectorMode() == SelectionVectorMode.TWO_BYTE);
for (VectorWrapper<?> vv : incoming) {
vv.getValueVector().makeTransferPair(container.addOrGet(vv.getField(), callBack));
}
try {
final CodeGenerator<Copier> cg = CodeGenerator.get(Copier.TEMPLATE_DEFINITION2, context.getFunctionRegistry(), context.getOptions());
CopyUtil.generateCopies(cg.getRoot(), incoming, false);
Copier copier = context.getImplementationClass(cg);
copier.setupRemover(context, incoming, this);
cg.plainJavaCapable(true);
return copier;
} catch (ClassTransformationException | IOException e) {
throw new SchemaChangeException("Failure while attempting to load generated class", e);
}
}
use of org.apache.drill.exec.exception.SchemaChangeException in project drill by apache.
the class WindowFrameRecordBatch method buildSchema.
@Override
protected void buildSchema() throws SchemaChangeException {
logger.trace("buildSchema()");
final IterOutcome outcome = next(incoming);
switch(outcome) {
case NONE:
state = BatchState.DONE;
container.buildSchema(BatchSchema.SelectionVectorMode.NONE);
return;
case STOP:
state = BatchState.STOP;
return;
case OUT_OF_MEMORY:
state = BatchState.OUT_OF_MEMORY;
return;
}
try {
createFramers(incoming);
} catch (IOException | ClassTransformationException e) {
throw new SchemaChangeException("Exception when creating the schema", e);
}
if (incoming.getRecordCount() > 0) {
batches.add(new WindowDataBatch(incoming, oContext));
}
}
Aggregations