Review Board 1.7.22

DRILL-356 : Support for Date, Time data types

Review Request #18055 - Created Feb. 13, 2014 and updated

Mehant Baid
Added value vectors, holders, cast and comparison functions for the following data types.


Internal representation of these data types:
For the data types Date, DateTime, TimeStamp we internally store milliseconds (from epoch) in UTC. We use a 'long' to store the milliseconds. Since TimeStamp has a timezone associated with it, we use another field (int) to store the index of the timezone into a static list of timezones we maintain (in DateUtility class)

For the Time data type we again store milliseconds, but since Time has a small range (00:00:00.000 - 23:59:59.999) we use an 'int' to store the value.

For Interval data type, which can be used to express an interval of time using one or more of the parameters: years, months, days, hours, minutes, seconds, milliseconds we internally store three fields. Months (int), days (int) and milliseconds (long). Using these three fields we can express all the above parameters with simple conversions. Eg: Years (parameter) - Months (internal) is a simple 1 Year = 12 months conversion. Similar conversion can be applied to hours, minutes and seconds to convert them to milliseconds. 

Sorting, comparison functions for Date, DateTime, TimeStamp, Time are straight forward as internally they are stored as long or int.

In addition to these types we also have a way to represent each type as a literal. For eg: a Date literal can be expressed using the expression: "datetype(2008, 1, 20)", a TimeStamp literal can be expressed using the expression: "timestamptype(2008, 1, 27, 0, 0, 0, 0, 'UTC')" and so on for all the types. 

For performing date functions the design is to use the internal representation to construct a Joda object (MutableDateTime) and use Joda for date arithmetic and other functions. As an example in this patch I've added a date_add() function that adds a Date and an Interval (DateTypeFunctions class)

Added unit tests and some manual testing. 
Review request changed
Updated (March 12, 2014, 11:42 a.m.)
Added two new interval types: IntervalYear, IntervalDay.
Integrate with the latest JDBC thinning changes.
Addressed initial round of review comments