OffHeapRowBlock extends OffHeapMemory implements Deallocatable { @Override public ByteBuffer nioBuffer() { return (ByteBuffer) buffer.position(0).limit(position); } private  OffHeapRowBlock(ByteBuffer buffer, Schema schema, ResizableLimitSpec limitSpec);  OffHeapRowBlock(Schema schema, ResizableLimitSpec limitSpec); @VisibleForTesting  OffHeapRowBlock(Schema schema, int bytes); @VisibleForTesting  OffHeapRowBlock(Schema schema, ByteBuffer buffer); void position(int pos); void clear(); @Override ByteBuffer nioBuffer(); int position(); long usedMem(); void ensureSize(int size); long remain(); int maxRowNum(); int rows(); void setRows(int rowNum); boolean copyFromChannel(FileChannel channel, TableStats stats); RowWriter getWriter(); OffHeapRowBlockReader getReader(); static final int NULL_FIELD_OFFSET; }
@Test public void testSerDerOfRowBlock() { int rowNum = 1000; OffHeapRowBlock rowBlock = createRowBlock(rowNum); ByteBuffer bb = rowBlock.nioBuffer(); OffHeapRowBlock restoredRowBlock = new OffHeapRowBlock(schema, bb); validateResults(restoredRowBlock); rowBlock.release(); }
@Test public void testSerDerOfZeroCopyTuple() { int rowNum = 1000; OffHeapRowBlock rowBlock = createRowBlock(rowNum); ByteBuffer bb = rowBlock.nioBuffer(); OffHeapRowBlock restoredRowBlock = new OffHeapRowBlock(schema, bb); OffHeapRowBlockReader reader = new OffHeapRowBlockReader(restoredRowBlock); long readStart = System.currentTimeMillis(); ZeroCopyTuple tuple = new ZeroCopyTuple(); ZeroCopyTuple copyTuple = new ZeroCopyTuple(); int j = 0; reader.reset(); while(reader.next(tuple)) { ByteBuffer copy = tuple.nioBuffer(); copyTuple.set(copy, SchemaUtil.toDataTypes(schema)); validateTupleResult(j, copyTuple); j++; } long readEnd = System.currentTimeMillis(); LOG.info("reading takes " + (readEnd - readStart) + " msec"); rowBlock.release(); }