You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by GitBox <gi...@apache.org> on 2021/08/19 18:32:02 UTC

[GitHub] [hive] sankarh commented on a change in pull request #2590: HIVE-25458: Unix_timestamp() with string input give wrong result

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



---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org