Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-27004

DateTimeFormatterBuilder cannot parse 'UTC+' in Java versions higher than 8

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0.0-beta-1
    • Hive
    • Patch

    Description

      Some of the unit tests related to DateTimeFormatter were failing in Java versions greater than 8 while working in Java 8.

      Example of a failing Unit Test : org.apache.hadoop.hive.common.type.TestTimestampTZ#testComparision

       

      java.time.format.DateTimeParseException: Text '2017-04-14 18:00:00 UTC+08:00' could not be parsed, unparsed text found at index 23 at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2049) at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1874) at org.apache.hadoop.hive.common.type.TimestampTZUtil.parse(TimestampTZUtil.java:76) at org.apache.hadoop.hive.common.type.TimestampTZUtil.parse(TimestampTZUtil.java:64) at org.apache.hadoop.hive.common.type.TestTimestampTZ.testComparison(TestTimestampTZ.java:44) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       

      The appendZoneText(TextStyle) method of DateTimeFormatteBuilder is not able to parse the + symbol in 2017-04-14 18:00:00 UTC+08:00 when running the test in Java 11 , while it is working fine with Java 8.

      According to the doc , appendZoneText(TextStyle) should be able to parse either the textual zone name, the zone ID or the offset and UTC+08:00 should come under offset as per the same doc.

      It seems, however, that "UTC" was explicitly removed when parsed as ZoneText for higher Java versions

      As a workaround, we can use appendZoneOrOffsetId() rather than appendZoneText().

      This ensures the tests are passing for Java 8+ and based on my testing, I didn’t see any regression of the change.

      Sample repro code - jdoodle.com/ia/D5e

       

      Attachments

        1. HIVE-27004.patch
          0.7 kB
          Anmol Sundaram

        Issue Links

          Activity

            People

              AnmolSun Anmol Sundaram
              AnmolSun Anmol Sundaram
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m