-1

Probably because implementing Writable would present us with a serializable object. I know DataInput and DataOutput directly deal with byte streams but I see no harm in directly reading values off them and storing it in primitive types too.

That being said, the very use of readFields() and write() methods seems futile and only could be used with the perspective of modularity. Creating objects for DataInput and DataOutput classes for instance variables and directly taking inputs (using DataInput and DataOutput like a Scanner utility class) seems quite simple. Creating an interface for them and implementing those obvious methods (be it in pre-defined box classes or our own custom classes) look like syntactic sugar as far as I can see.

Help me see through it if there's something to be seen.

UPDATE: DataInput and DataOutput classes produce serialized objects! :o

user207421
  • 305,947
  • 44
  • 307
  • 483
Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
  • `Writable` does not produce serializable objects, and neither do `DataInput` or `DataOutput`. Unclear what you're talking about, let alone what you're asking. – user207421 Jul 11 '16 at 09:43
  • Possible duplicate of [What is the reason for Writable ...](http://stackoverflow.com/q/17203661/207421). – user207421 Jul 11 '16 at 09:46
  • @EJP All of them do. [Here](https://acadgild.com/blog/writable-and-writablecomparable-in-hadoop/) and [here](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiRs4aNkuvNAhUJPxoKHTWgDCEQFggdMAA&url=https%3A%2F%2Fhadoop.apache.org%2Fdocs%2Fr2.6.1%2Fapi%2Forg%2Fapache%2Fhadoop%2Fio%2FWritable.html&usg=AFQjCNEz5Mh9TeOMqXd8AX74QxlfFMzCzw&sig2=35nxbPRITVf6lfzivGUSjw). And your second comment's question is talking about something else. Don't just read the title! – Aakash Verma Jul 11 '16 at 09:54
  • No, `Writable` does, *in Hadoop*, and by *using* the `DataOutput` interface, and `DataInput` on the way in, *for Hadoop's Serialization protocol*. `DataInput/Output` by themselves don't have any such magical properties, and certainly none of them represent 'syntactic sugar'. Your question is just confused. – user207421 Jul 11 '16 at 09:57
  • @EJP I mentioned a couple of links. The first one directly mentions that they serialize the most basic types. And if you want the official website's word, you can see that they directly read for write to *byte streams*. – Aakash Verma Jul 11 '16 at 10:02
  • I'm aware of what `DataOutput` does, thank you, and what it doesn't do is serialize *objects.* Your question is based on a false assumption. – user207421 Jul 11 '16 at 11:00
  • Because it helps you to write efficient serialization for *complex* objects, something that `DataOutput` does not offer. Of course you can use any other serialization library like protobuf, thrift or bond instead. – Thomas Jungblut Jul 11 '16 at 11:18

1 Answers1

1

DataOutput and DataInput serialize/deserialze only the most basic types, that is, the primitive types and not the custom or complex objects.

This is why by implementing Writable, and in turn its method readFields(DataInput in) and write(DataOutput out), we can serialize the members/instance variables of our own class and traverse their inputs or outputs. And since Writables are written for specific classes, they are compact, small (and not 5-bytes long) and so provide higher performance as we don't have to store the metdata for the class type and allow easy streaming over the distributed network as compared to Java Serializable.

Community
  • 1
  • 1
Aakash Verma
  • 3,705
  • 5
  • 29
  • 66