[ 
https://issues.apache.org/jira/browse/HIVE-25458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17748628#comment-17748628
 ] 

Jason Phelps edited comment on HIVE-25458 at 7/28/23 2:20 PM:
--------------------------------------------------------------

FYI. 

Prior to this change, if an incorrect/invalid string pattern [1] was used in 
unix_timestamp, it would return a timestamp that was likely correct, but not 
guaranteed. After this change, unix_timestamp will now return an error when an 
incorrect pattern is used. For an example of this, please see below:

from_unixtime(UNIX_TIMESTAMP(), 'yyyy-MM-dd hh:mm:ss.sss')
Earlier:
The below would be parsed to second precision, compile and return a value, but 
the incorrect pattern is given for milliseconds (should be SSS).

Now:
Query fails with "IllegalArgumentException Too many pattern letters: s"

*The only fix is to update the query to use a valid string pattern.*

[1]
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
See Patterns for Formatting and Parsing section



was (Author: jphelps):
FYI. 

Prior to this change, if an incorrect/invalid string pattern [1] was used in 
unix_timestamp, it would return a timestamp that was likely correct, but not 
guaranteed. After this change, unix_timestamp will now return an error when an 
incorrect pattern is used. For an example of this, please see below:

from_unixtime(UNIX_TIMESTAMP(), 'yyyy-MM-dd hh:mm:ss.sss')
Earlier:
The below would be parsed to second precision, compile and return a value, but 
the incorrect pattern is given for milliseconds (should be SSS).

Now:
Query fails with "IllegalArgumentException Too many pattern letters: s"

*The only fix is to update the query to use a valid string pattern.*

> unix_timestamp() with string input give wrong result
> ----------------------------------------------------
>
>                 Key: HIVE-25458
>                 URL: https://issues.apache.org/jira/browse/HIVE-25458
>             Project: Hive
>          Issue Type: Bug
>          Components: UDF
>    Affects Versions: 3.1.2
>            Reporter: Ashish Sharma
>            Assignee: Ashish Sharma
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 4.0.0-alpha-1
>
>          Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> Description - 
> unix_timestamp() accept 4 value string/date/timestamp/timestamptz. Out of 
> which date/timestamp/timestamptz use DateTimeFormatter.class where as string 
> type use SimpleDateTimeformatter.class which cause difference is value.
> Example - 
> select from_unixtime(unix_timestamp('1800-11-08 01:53:11'));
> 1800-11-08 01:35:15
> select from_unixtime(unix_timestamp(cast('1800-11-08 01:53:11' as 
> timestamp)));
> 1800-11-08 01:53:11
>   



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to