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/06/20 04:56:32 UTC

[GitHub] [hive] ashish-kumar-sharma commented on a change in pull request #2409: HIVE-25268: Restore the functionality of date_format UDF

ashish-kumar-sharma commented on a change in pull request #2409:
URL: https://github.com/apache/hive/pull/2409#discussion_r654876476



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDateFormat.java
##########
@@ -85,21 +87,31 @@ public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumen
       String fmtStr = getConstantStringValue(arguments, 1);
       if (fmtStr != null) {
         try {
-          formatter = new SimpleDateFormat(fmtStr);
-          formatter.setCalendar(DateTimeMath.getTimeZonedProlepticGregorianCalendar());
+          if (timeZone == null) {
+            timeZone = SessionState.get() == null ? new HiveConf().getLocalTimeZone() : SessionState.get().getConf()
+                .getLocalTimeZone();
+          }
+          formatter = DateTimeFormatter.ofPattern(fmtStr).withZone(timeZone);
         } catch (IllegalArgumentException e) {
           // ignore
         }
       }
     } else {
-      throw new UDFArgumentTypeException(1, getFuncName() + " only takes constant as "
-          + getArgOrder(1) + " argument");
+      throw new UDFArgumentTypeException(1, getFuncName() + " only takes constant as " + getArgOrder(1) + " argument");
     }
 
     ObjectInspector outputOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
     return outputOI;
   }
 
+  @Override

Review comment:
       This method is not required. Because idea is to first check the session for config "hive.local.time.zone" and then fall back to cluster default.

##########
File path: ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFDateFormat.java
##########
@@ -176,7 +176,6 @@ public void testWrongFmt() throws HiveException {
 

Review comment:
       Add test for date older then 1900 with timestamp.

##########
File path: ql/src/test/queries/clientpositive/udf_date_format.q
##########
@@ -78,3 +78,8 @@ select date_format("2015-04-08 10:30:45","yyyy-MM-dd HH:mm:ss.SSS z");
 --julian date
 set hive.local.time.zone=UTC;
 select date_format("1001-01-05","dd---MM--yyyy");
+
+--dates prior to 1900 in another time zone
+set hive.local.time.zone=Asia/Bangkok;

Review comment:
       Add multiple query with different time zone.




-- 
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.

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