Java – Hadoop writable for dates/calendars

Hadoop writable for dates/calendars… here is a solution to the problem.

Hadoop writable for dates/calendars

I want to implement a custom hadoop writable class where one field is a timestamp. I can’t seem to find a class in the hadoop library (e.g. writable classes for dates or calendars) that would make this easy. I’m thinking of creating a custom writable object using get/setTimeInMillis on the calendar, but I’m wondering if there’s a better/built-in solution to this problem.

Solution

Calendars/dates in Hadoop have no writable objects. Consider that you can get timeInMillis as long from the Calendar object, if and only if your application always uses the default UTC time zone (that is, it is “agnostic” to the time zone, it always assumes that timeInMillis represents a UTC time).

If you use another time zone, or if your application needs to be able to interpret timeInMillis in relation to a different time zone, you must write a default Writable implementation from scratch.

Related Problems and Solutions