You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/08/19 18:33:00 UTC

[jira] [Work logged] (HIVE-25458) unix_timestamp() with string input give wrong result

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

ASF GitHub Bot logged work on HIVE-25458:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 19/Aug/21 18:32
            Start Date: 19/Aug/21 18:32
    Worklog Time Spent: 10m 
      Work Description: sankarh commented on a change in pull request #2590:
URL: https://github.com/apache/hive/pull/2590#discussion_r692384102



##########
File path: ql/src/test/queries/clientpositive/udf5.q
##########
@@ -45,3 +45,24 @@ select from_unixtime(to_unix_timestamp(cast('0000-00-00' as date)));
 set time zone Europe/Rome;
 
 SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-11-01'), month('2008-11-01'), year('2008-11-01'), day('2008-11-01 15:32:20'), month('2008-11-01 15:32:20'), year('2008-11-01 15:32:20') FROM dest1_n14;
+
+set hive.local.time.zone=Asia/Bangkok;
+
+select from_unixtime(unix_timestamp('1400-11-08 01:53:11'));
+select from_unixtime(unix_timestamp('1800-11-08 01:53:11'));
+select from_unixtime(unix_timestamp('1400-11-08 08:00:00 ICT', 'yyyy-MM-dd HH:mm:ss z'));
+select from_unixtime(unix_timestamp('1800-11-08 08:00:00 ICT', 'yyyy-MM-dd HH:mm:ss z'));
+select from_unixtime(unix_timestamp('0000-00-00', 'uuuu-MM-dd'));
+select from_unixtime(unix_timestamp("2001.07.04 AD at 12:08:56 ICT","yyyy.MM.dd G 'at' HH:mm:ss z"));
+
+set hive.local.time.zone=Europe/London;
+
+select from_unixtime(unix_timestamp('1400-11-08 01:53:11'));
+select from_unixtime(unix_timestamp('1400-11-08', 'yyyy-MM-dd'));
+select from_unixtime(unix_timestamp("Wed, Jul 4, '01", "EEE, MMM d, ''yy"));
+
+set hive.local.time.zone=US/Hawaii;
+
+select from_unixtime(unix_timestamp('1400-11-08 01:53:11'));
+select from_unixtime(unix_timestamp('1800-11-08 01:53:11'));
+select from_unixtime(to_unix_timestamp('0000-00-00'));

Review comment:
       Nit: Add extra line at EOF.

##########
File path: ql/src/test/queries/clientpositive/udf5.q
##########
@@ -9,24 +9,24 @@ SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-
 SELECT from_unixtime(1226446340), to_date(from_unixtime(1226446340)), day('2008-11-01'), month('2008-11-01'), year('2008-11-01'), day('2008-11-01 15:32:20'), month('2008-11-01 15:32:20'), year('2008-11-01 15:32:20') FROM dest1_n14;
 
 EXPLAIN
-SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'yyyy-MM-dd HH:mm:ss'), 'MM/dd/yy HH:mm:ss'), from_unixtime(unix_timestamp('2010-01-13 11:57:40')) from dest1_n14;
+SELECT from_unixtime(unix_timestamp('2010-01-13 11:57:40', 'uuuu-MM-dd HH:mm:ss'), 'MM/dd/yy HH:mm:ss'), from_unixtime(unix_timestamp('2010-01-13 11:57:40')) from dest1_n14;

Review comment:
       Instead of changing existing tests, can we add new ones with "uuuu"?

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFToUnixTimeStamp.java
##########
@@ -164,15 +164,32 @@ public Object evaluate(DeferredObject[] arguments) throws HiveException {
           return null;
         }
         if (!patternVal.equals(lasPattern)) {
-          formatter.applyPattern(patternVal);
+          formatter = DateTimeFormatter.ofPattern(patternVal);
           lasPattern = patternVal;
         }
+
+        try {
+          LocalDateTime localDateTime = LocalDateTime.parse(textVal, formatter);
+          timestamp = new Timestamp(localDateTime);
+        } catch (DateTimeException e) {
+          try {
+            LocalDate localDate = LocalDate.parse(textVal, formatter);
+            timestamp = new Timestamp(localDate.atStartOfDay());
+          } catch (DateTimeException ex) {
+            return null;
+          }
+        }
+

Review comment:
       Nit: Remove extra line.

##########
File path: ql/src/test/queries/clientpositive/vector_unix_timestamp.q
##########
@@ -1,6 +1,6 @@
 
 create table t (d string);
-insert into t values('2020-11-16 22:18:40 UTC');
+insert into t values('2020-11-16 22:18:40');

Review comment:
       Why is it changed?

##########
File path: ql/src/test/queries/clientpositive/udf_to_unix_timestamp.q
##########
@@ -18,8 +18,8 @@ SELECT
 FROM oneline_n0;
 
 SELECT
-  '2009 Mar 20 11:30:01 am',
-  to_unix_timestamp('2009 Mar 20 11:30:01 am', 'yyyy MMM dd h:mm:ss a')
+  '2009 Mar 20 11:30:01 AM',

Review comment:
       Why is this change required? Lower case doesn't work?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 639984)
    Time Spent: 50m  (was: 40m)

> 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
>            Reporter: Ashish Sharma
>            Assignee: Ashish Sharma
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 50m
>  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.3.4#803005)