use of org.apache.arrow.vector.ipc.InvalidArrowFileException in project tracdap by finos.
the class ArrowFileDecoder method decodeChunk.
@Override
protected void decodeChunk(ByteBuf chunk) {
try (var stream = new ByteSeekableChannel(chunk);
var reader = new ArrowFileReader(stream, arrowAllocator);
var root = reader.getVectorSchemaRoot()) {
var schema = root.getSchema();
emitBlock(DataBlock.forSchema(schema));
var unloader = new VectorUnloader(root);
while (reader.loadNextBatch()) {
var batch = unloader.getRecordBatch();
emitBlock(DataBlock.forRecords(batch));
}
} catch (InvalidArrowFileException e) {
// A nice clean validation failure from the Arrow framework
// E.g. missing / incorrect magic number at the start (or end) of the file
var errorMessage = "Arrow file decoding failed, file is invalid: " + e.getMessage();
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (IllegalArgumentException | IndexOutOfBoundsException | IOException e) {
// These errors occur if the data stream contains bad values for vector sizes, offsets etc.
// This may be as a result of a corrupt data stream, or a maliciously crafted message
// Decoders work on a stream of buffers, "real" IO exceptions should not occur
var errorMessage = "Arrow file decoding failed, content is garbled";
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (Throwable e) {
// Ensure unexpected errors are still reported to the Flow API
log.error("Unexpected error in Arrow file decoding", e);
throw new EUnexpected(e);
} finally {
chunk.release();
}
}
use of org.apache.arrow.vector.ipc.InvalidArrowFileException in project tracdap by finos.
the class ArrowFileDecoder method decodeChunk.
@Override
protected void decodeChunk(ByteBuf chunk) {
try (var stream = new ByteSeekableChannel(chunk);
var reader = new ArrowFileReader(stream, arrowAllocator);
var root = reader.getVectorSchemaRoot()) {
var schema = root.getSchema();
emitBlock(DataBlock.forSchema(schema));
var unloader = new VectorUnloader(root);
while (reader.loadNextBatch()) {
var batch = unloader.getRecordBatch();
emitBlock(DataBlock.forRecords(batch));
}
} catch (InvalidArrowFileException e) {
// A nice clean validation failure from the Arrow framework
// E.g. missing / incorrect magic number at the start (or end) of the file
var errorMessage = "Arrow file decoding failed, file is invalid: " + e.getMessage();
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (IllegalArgumentException | IndexOutOfBoundsException | IOException e) {
// These errors occur if the data stream contains bad values for vector sizes, offsets etc.
// This may be as a result of a corrupt data stream, or a maliciously crafted message
// Decoders work on a stream of buffers, "real" IO exceptions should not occur
var errorMessage = "Arrow file decoding failed, content is garbled";
log.error(errorMessage, e);
throw new EDataCorruption(errorMessage, e);
} catch (Throwable e) {
// Ensure unexpected errors are still reported to the Flow API
log.error("Unexpected error in Arrow file decoding", e);
throw new EUnexpected(e);
} finally {
chunk.release();
}
}
Aggregations