Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-5334

Questionable code in the TimeVector class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.9.0
    • None
    • None
    • None

    Description

      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:

          @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;
          }
      

      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, 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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              paul-rogers Paul Rogers
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: