adesh-rao commented on a change in pull request #2482:
URL: https://github.com/apache/hive/pull/2482#discussion_r677126600



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTimestamp.java
##########
@@ -63,61 +71,44 @@
    * otherwise, it's interpreted as timestamp in seconds.
    */
   private boolean intToTimestampInSeconds = false;
+  private boolean strict = true;
 
   @Override
   public ObjectInspector initialize(ObjectInspector[] arguments) throws 
UDFArgumentException {
-    if (arguments.length < 1) {
-      throw new UDFArgumentLengthException(
-          "The function TIMESTAMP requires at least one argument, got "
-          + arguments.length);
-    }
-
-    SessionState ss = SessionState.get();
-    if (ss != null) {
-      intToTimestampInSeconds = 
ss.getConf().getBoolVar(ConfVars.HIVE_INT_TIMESTAMP_CONVERSION_IN_SECONDS);
-    }
+    checkArgsSize(arguments, 1, 1);
+    checkArgPrimitive(arguments, 0);
+    checkArgGroups(arguments, 0, tsInputTypes, STRING_GROUP, DATE_GROUP, 
NUMERIC_GROUP, VOID_GROUP, BOOLEAN_GROUP);
 
-    try {
-      argumentOI = (PrimitiveObjectInspector) arguments[0];
-    } catch (ClassCastException e) {
-      throw new UDFArgumentException(
-          "The function TIMESTAMP takes only primitive types");
-    }
+    strict = SessionState.get() != null ? SessionState.get().getConf()
+        .getBoolVar(ConfVars.HIVE_STRICT_TIMESTAMP_CONVERSION) : new HiveConf()
+        .getBoolVar(ConfVars.HIVE_STRICT_TIMESTAMP_CONVERSION);
+    intToTimestampInSeconds = SessionState.get() != null ? 
SessionState.get().getConf()
+        .getBoolVar(ConfVars.HIVE_INT_TIMESTAMP_CONVERSION_IN_SECONDS) : new 
HiveConf()
+        .getBoolVar(ConfVars.HIVE_INT_TIMESTAMP_CONVERSION_IN_SECONDS);
 
-    if (ss != null && 
ss.getConf().getBoolVar(ConfVars.HIVE_STRICT_TIMESTAMP_CONVERSION)) {
-      PrimitiveCategory category = argumentOI.getPrimitiveCategory();
-      PrimitiveGrouping group = 
PrimitiveObjectInspectorUtils.getPrimitiveGrouping(category);
-      if (group == PrimitiveGrouping.NUMERIC_GROUP) {
+    if (strict) {

Review comment:
       nit: Move this condition above intToTimestampInSeconds initialization? 
If we have to throw exception, let's do it without computing anything else.




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