title: Advantages of using NullWritable in Hadoop
body: <p>What are the advantages of using <code>NullWritable</code> for <code>null</code> keys/values over using <code>null</code> texts (i.e. <code>new Text(null)</code>). I see the following from the «Hadoop: The Definitive Guide» book.</p>
  
  <blockquote>
    <p><code>NullWritable</code> is a special type of <code>Writable</code>, as it has a zero-length serialization. No bytes
    are written to, or read from, the stream. It is used as a placeholder; for example, in
    MapReduce, a key or a value can be declared as a <code>NullWritable</code> when you don’t need
    to use that position—it effectively stores a constant empty value. NullWritable can also
    be useful as a key in <code>SequenceFile</code> when you want to store a list of values, as opposed
    to key-value pairs. It is an immutable singleton: the instance can be retrieved by calling
    <code>NullWritable.get()</code></p>
  </blockquote>
  
  <p>I do not clearly understand how the output is written out using <code>NullWritable</code>? Will there be a single constant value in the beginning output file indicating that the keys or values of this file are <code>null</code>, so that the MapReduce framework can ignore reading the <code>null</code> keys/values (whichever is <code>null</code>)? Also, how actually are <code>null</code> texts serialized?</p>
  
  <p>Thanks,</p>
  
  <p>Venkat</p>