[ 
https://issues.apache.org/jira/browse/HIVE-25576?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ashish Sharma updated HIVE-25576:
---------------------------------
    Description: 
*History*

*Hive 1.2* - 

VM time zone set to Asia/Bangkok

Query - SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('1800-01-01 00:00:00 
UTC','yyyy-MM-dd HH:mm:ss z'));

Result - 1800-01-01 07:00:00

implementation details - 

SimpleDateFormat formatter = new SimpleDateFormat(pattern);
Long unixtime = formatter.parse(textval).getTime() / 1000;
Date date = new Date(unixtime * 1000L);

https://docs.oracle.com/javase/8/docs/api/java/util/Date.html . In official 
documentation they have mention that "Unfortunately, the API for these 
functions was not amenable to internationalization and The corresponding 
methods in Date are deprecated" . Due to that this is producing wrong result

*Master branch* - 

set hive.local.time.zone=Asia/Bangkok;

*Query *- SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('1800-01-01 00:00:00 
UTC','yyyy-MM-dd HH:mm:ss z'));

*Result *- 1800-01-01 06:42:04

implementation details - 

DateTimeFormatter dtformatter = new DateTimeFormatterBuilder()
        .parseCaseInsensitive()
        .appendPattern(pattern)
        .toFormatter();

    ZonedDateTime zonedDateTime = 
ZonedDateTime.parse(textval,dtformatter).withZoneSameInstant(ZoneId.of(timezone));
    Long dttime = zonedDateTime.toInstant().getEpochSecond();


*Problem*- 

Now *SimpleDateFormat* has been replaced with *DateTimeFormatter* which is 
giving the correct result but it is not backword compatible. Which is causing 
issue at time for migration to new version. Because the older data written is 
using Hive 1.x or 2.x is not compatible with *DateTimeFormatter*.

*Solution*

Introduce an config "hive.legacy.timeParserPolicy" with following values -
EXCEPTION - compare value of both *SimpleDateFormat* & *DateTimeFormatter* 
raise exception if doesn't match 
LEGACY - use *SimpleDateFormat* 
CORRECTED  - use *DateTimeFormatter*

This will help hive user in following manner - 
1. Migrate to new version using *LEGACY*
2. Find values which are not compatible with new version - *EXCEPTION*
3. Use latest date apis - *CORRECTED*



  was:
*History *

*Hive 1.2* - 

VM time zone set to Asia/Bangkok

Query - SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('1800-01-01 00:00:00 
UTC','yyyy-MM-dd HH:mm:ss z'));

Result - 1800-01-01 07:00:00

implementation details - 

SimpleDateFormat formatter = new SimpleDateFormat(pattern);
Long unixtime = formatter.parse(textval).getTime() / 1000;
Date date = new Date(unixtime * 1000L);

https://docs.oracle.com/javase/8/docs/api/java/util/Date.html . In official 
documentation they have mention that "Unfortunately, the API for these 
functions was not amenable to internationalization and The corresponding 
methods in Date are deprecated" . Due to that this is producing wrong result

*Master branch* - 

set hive.local.time.zone=Asia/Bangkok;

*Query *- SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('1800-01-01 00:00:00 
UTC','yyyy-MM-dd HH:mm:ss z'));

*Result *- 1800-01-01 06:42:04

implementation details - 

DateTimeFormatter dtformatter = new DateTimeFormatterBuilder()
        .parseCaseInsensitive()
        .appendPattern(pattern)
        .toFormatter();

    ZonedDateTime zonedDateTime = 
ZonedDateTime.parse(textval,dtformatter).withZoneSameInstant(ZoneId.of(timezone));
    Long dttime = zonedDateTime.toInstant().getEpochSecond();


*Problem*- 

Now *SimpleDateFormat* has been replaced with *DateTimeFormatter* which is 
giving the correct result but it is not backword compatible. Which is causing 
issue at time for migration to new version. Because the older data written is 
using Hive 1.x or 2.x is not compatible with *DateTimeFormatter*.

*Solution*

Introduce an config "hive.legacy.timeParserPolicy" with following values -
EXCEPTION - compare value of both *SimpleDateFormat* & *DateTimeFormatter* 
raise exception if doesn't match 
LEGACY - use *SimpleDateFormat* 
CORRECTED  - use *DateTimeFormatter*

This will help hive user in following manner - 
1. Migrate to new version using *LEGACY*
2. Find values which are not compatible with new version - *EXCEPTION*
3. Use latest date apis - *CORRECTED*




> Raise exception instead of silent change for new DateFormatter
> --------------------------------------------------------------
>
>                 Key: HIVE-25576
>                 URL: https://issues.apache.org/jira/browse/HIVE-25576
>             Project: Hive
>          Issue Type: Improvement
>    Affects Versions: 4.0.0
>            Reporter: Ashish Sharma
>            Assignee: Ashish Sharma
>            Priority: Major
>
> *History*
> *Hive 1.2* - 
> VM time zone set to Asia/Bangkok
> Query - SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('1800-01-01 00:00:00 
> UTC','yyyy-MM-dd HH:mm:ss z'));
> Result - 1800-01-01 07:00:00
> implementation details - 
> SimpleDateFormat formatter = new SimpleDateFormat(pattern);
> Long unixtime = formatter.parse(textval).getTime() / 1000;
> Date date = new Date(unixtime * 1000L);
> https://docs.oracle.com/javase/8/docs/api/java/util/Date.html . In official 
> documentation they have mention that "Unfortunately, the API for these 
> functions was not amenable to internationalization and The corresponding 
> methods in Date are deprecated" . Due to that this is producing wrong result
> *Master branch* - 
> set hive.local.time.zone=Asia/Bangkok;
> *Query *- SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('1800-01-01 00:00:00 
> UTC','yyyy-MM-dd HH:mm:ss z'));
> *Result *- 1800-01-01 06:42:04
> implementation details - 
> DateTimeFormatter dtformatter = new DateTimeFormatterBuilder()
>         .parseCaseInsensitive()
>         .appendPattern(pattern)
>         .toFormatter();
>     ZonedDateTime zonedDateTime = 
> ZonedDateTime.parse(textval,dtformatter).withZoneSameInstant(ZoneId.of(timezone));
>     Long dttime = zonedDateTime.toInstant().getEpochSecond();
> *Problem*- 
> Now *SimpleDateFormat* has been replaced with *DateTimeFormatter* which is 
> giving the correct result but it is not backword compatible. Which is causing 
> issue at time for migration to new version. Because the older data written is 
> using Hive 1.x or 2.x is not compatible with *DateTimeFormatter*.
> *Solution*
> Introduce an config "hive.legacy.timeParserPolicy" with following values -
> EXCEPTION - compare value of both *SimpleDateFormat* & *DateTimeFormatter* 
> raise exception if doesn't match 
> LEGACY - use *SimpleDateFormat* 
> CORRECTED  - use *DateTimeFormatter*
> This will help hive user in following manner - 
> 1. Migrate to new version using *LEGACY*
> 2. Find values which are not compatible with new version - *EXCEPTION*
> 3. Use latest date apis - *CORRECTED*



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to