warriersruthi commented on a change in pull request #2550:
URL: https://github.com/apache/hive/pull/2550#discussion_r683601489



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFFromUnixTime.java
##########
@@ -87,89 +75,58 @@ public ObjectInspector initialize(ObjectInspector[] 
arguments) throws UDFArgumen
         inputLongOI = (LongObjectInspector) arguments[0];
         break;
       default:
-        throw new UDFArgumentException("The function " + 
getName().toUpperCase()
-            + " takes only int/long types for first argument. Got Type:" + 
arg0OI.getPrimitiveCategory().name());
+        throw new UDFArgumentException("The function from_unixtime takes only 
int/long types for first argument. Got Type:"
+            + arg0OI.getPrimitiveCategory().name());
     }
 
     if (arguments.length == 2) {
-      PrimitiveObjectInspector arg1OI = (PrimitiveObjectInspector) 
arguments[1];
-      switch (arg1OI.getPrimitiveCategory()) {
-        case CHAR:
-        case VARCHAR:
-        case STRING:
-          inputTextConverter = ObjectInspectorConverters.getConverter(arg1OI,
-              PrimitiveObjectInspectorFactory.javaStringObjectInspector);
-          break;
-        default:
-          throw new UDFArgumentException("The function " + 
getName().toUpperCase()
-              + " takes only string type for second argument. Got Type:" + 
arg1OI.getPrimitiveCategory().name());
-      }
+      checkArgGroups(arguments, 1, inputTypes, STRING_GROUP);
+      obtainStringConverter(arguments, 1, inputTypes, converters);
     }
 
-    if (timeZone == null) {
-      timeZone = SessionState.get() == null ? new 
HiveConf().getLocalTimeZone() : SessionState.get().getConf()
-              .getLocalTimeZone();
-      formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
-    }
+    timeZone = SessionState.get() == null ? new HiveConf().getLocalTimeZone() 
: SessionState.get().getConf()
+      .getLocalTimeZone();
+    FORMATTER.withZone(timeZone);
 
     return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
   }
 
-  @Override
-  public void configure(MapredContext context) {
-    if (context != null) {
-      String timeZoneStr = HiveConf.getVar(context.getJobConf(), 
HiveConf.ConfVars.HIVE_LOCAL_TIME_ZONE);
-      timeZone = TimestampTZUtil.parseTimeZone(timeZoneStr);
-      formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
-    }
-  }
-
   @Override
   public Object evaluate(DeferredObject[] arguments) throws HiveException {
     if (arguments[0].get() == null) {
       return null;
     }
 
-    if (inputTextConverter != null) {
-      if (arguments[1].get() == null) {
-        return null;
-      }
-      String format = (String) inputTextConverter.convert(arguments[1].get());
+    if(arguments.length == 2) {
+      String format = getStringValue(arguments, 1, converters);
       if (format == null) {
         return null;
       }
       if (!format.equals(lastFormat)) {
-        formatter = new SimpleDateFormat(format);
-        formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
+        FORMATTER = DateTimeFormatter.ofPattern(format);
         lastFormat = format;
       }
     }
 
     // convert seconds to milliseconds
     long unixtime;
+    Instant i;

Review comment:
       inoutIntOI is not required. So removed the whole check. 




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to