Example usage for org.apache.spark.sql.catalyst.expressions UnsafeRow UnsafeRow

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

Introduction

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

Prototype

public UnsafeRow(int numFields) 

Source Link

Document

Construct a new UnsafeRow.

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.// w  w  w. ja  v a  2s . co  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);
    }
}