private void spillBlock(ROW[] block, int length) throws HiveException {
    try {
      if (tmpFile == null) {
        setupWriter();
      } else if (rw == null) {
        throw new HiveException("RowContainer has already been closed for writing.");
      }

      row.clear();
      row.add(null);
      row.add(null);

      if (this.keyObject != null) {
        row.set(1, this.keyObject);
        for (int i = 0; i < length; ++i) {
          ROW currentValRow = block[i];
          row.set(0, currentValRow);
          Writable outVal = serde.serialize(row, standardOI);
          rw.write(outVal);
        }
      } else {
        for (int i = 0; i < length; ++i) {
          ROW currentValRow = block[i];
          Writable outVal = serde.serialize(currentValRow, standardOI);
          rw.write(outVal);
        }
      }

      if (block == this.currentWriteBlock) {
        this.addCursor = 0;
      }

      this.numFlushedBlocks++;
    } catch (Exception e) {
      clearRows();
      LOG.error(e.toString(), e);
      if ( e instanceof HiveException ) {
        throw (HiveException) e;
      }
      throw new HiveException(e);
    }
  }
Simple persistent container for rows.

This container interface only accepts adding or appending new rows and iterating through the rows
in the order of their insertions.

The iterator interface is a lightweight first()/next() API rather than the Java Iterator
interface. This way we do not need to create an Iterator object every time we want to start a new
iteration. Below is simple example of how to convert a typical Java's Iterator code to the LW
iterator interface.

Iterator itr = rowContainer.iterator(); while (itr.hasNext()) { v = itr.next(); // do anything
with v }

can be rewritten to:

for ( v = rowContainer.first(); v != null; v = rowContainer.next()) { // do anything with v }

Once the first is called, it will not be able to write again. So there can not be any writes
after read. It can be read multiple times, but it does not support multiple reader interleaving
reading.
ql/src/java/org/apache/hadoop/hive/ql/exec/persistence/RowContainer.java