Example usage for org.apache.spark.sql.catalyst.expressions.codegen UnsafeArrayWriter UnsafeArrayWriter

List of usage examples for org.apache.spark.sql.catalyst.expressions.codegen UnsafeArrayWriter UnsafeArrayWriter

Introduction

In this page you can find the example usage for org.apache.spark.sql.catalyst.expressions.codegen UnsafeArrayWriter UnsafeArrayWriter.

Prototype

UnsafeArrayWriter

Source Link

Usage

From source file:com.splicemachine.db.iapi.types.SQLArray.java

License:Apache License

/**
 *
 * Write into a Project Tungsten format (UnsafeRow).  This calls the
 * reference's write method./*from  ww  w .ja v a 2s  .c  o  m*/
 *
 *
 * @param unsafeRowWriter
 * @param ordinal
 * @throws StandardException
  */
public void write(UnsafeRowWriter unsafeRowWriter, int ordinal) throws StandardException {
    if (isNull()) {
        unsafeRowWriter.setNullAt(ordinal);
    } else {
        UnsafeArrayWriter unsafeArrayWriter = new UnsafeArrayWriter();
        BufferHolder bh = new BufferHolder(new UnsafeRow(value.length));
        unsafeArrayWriter.initialize(bh, value.length, 8); // 4 bytes for int?
        for (int i = 0; i < value.length; i++) {
            if (value[i] == null || value[i].isNull()) {
                unsafeArrayWriter.setNull(i);
            } else {
                value[i].writeArray(unsafeArrayWriter, i);
            }
        }
        long currentOffset = unsafeRowWriter.holder().cursor;
        unsafeRowWriter.setOffsetAndSize(ordinal, bh.cursor - 16);
        unsafeRowWriter.holder().grow(bh.cursor - 16);
        Platform.copyMemory(bh.buffer, 16, unsafeRowWriter.holder().buffer, currentOffset, bh.cursor - 16);
    }
}