Paul Rogers created DRILL-5334: ---------------------------------- Summary: Questionable code in the TimeVector class Key: DRILL-5334 URL: https://issues.apache.org/jira/browse/DRILL-5334 Project: Apache Drill Issue Type: Bug Affects Versions: 1.9.0 Reporter: Paul Rogers
The {{TimeVector}} class, which holds Time data, should hold a simple local time with no associated date or time zone. (A local time cannot be converted to UTC without a date since the conversion depends on when daylight savings is in effect.) But, the implementation of {{TimeVector}} uses the following very questionable code: {code} @Override public DateTime getObject(int index) { org.joda.time.DateTime time = new org.joda.time.DateTime(get(index), org.joda.time.DateTimeZone.UTC); time = time.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault()); return time; } {code} That is, we convert a date-less, local time into a Joda UTC DateTime object, then reset the time zone to local time. This is abusing the Joda library and is the very kind of fun & games that Joda was designed to prevent. The conversion of a time into Joda should use the {{LocalTime}} class. In fact, according to [Oracle|http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html], the following is the mapping from ANSI SQL date/time types to Java 8 (and thus Joda) classes: ||ANSI SQL||Java SE 8 |DATE|LocalDate |TIME|LocalTime |TIMESTAMP|LocalDateTime |TIME WITH TIMEZONE|OffsetTime |TIMESTAMP WITH TIMEZONE|OffsetDateTime -- This message was sent by Atlassian JIRA (v6.3.15#6346)