Question

I want to emit key and value as custom datatype.

whether I should implement 2 classes for key and value?

one KeyWritable implements WritableComparable and

the other one

ValueWritable implements Writable.

Is it like that or one

WritableComparable is enough for emiting custom key and value.

Was it helpful?

Solution

If you want to use same class for your key and value, Then you need to write only one custom class which implements WritableComparable Interface.

A class which implements WritableComparable interface can be used for Key and Value. That means your new custom class will be Writable and Comparable also.

The super interfaces of WritableComparable are Writable and Comparable.

Please verify this

OTHER TIPS

There is no need to write KeyWritable separate if your key is not custom object and it's only text or string value.

In Hadoop, every data type to be used as keys must implement Writable and Comparable interfaces or more conveniently WritableComparable interface, and every data type to be used as values must implement Writable interface.

If your custom key and value are of the same type, then you could write one custom data type which implements WritableComparable interface. If your custom key type differs from your custom value type, you will have to write two separate custom data types, where custom key class implements WritableComparable interface and custom value class implements Writable interface. Note that usually developers tend to use WritableComparable interface when they write custom data types since they can use interchangeably as custom keys and custom values. HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top