[ https://issues.apache.org/jira/browse/HIVE-25334?focusedWorklogId=636792&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-636792 ]
ASF GitHub Bot logged work on HIVE-25334: ----------------------------------------- Author: ASF GitHub Bot Created on: 11/Aug/21 07:56 Start Date: 11/Aug/21 07:56 Worklog Time Spent: 10m Work Description: ashish-kumar-sharma commented on a change in pull request #2482: URL: https://github.com/apache/hive/pull/2482#discussion_r686586962 ########## 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) { + if (PrimitiveObjectInspectorUtils.getPrimitiveGrouping(tsInputTypes[0]) == PrimitiveGrouping.NUMERIC_GROUP) { Review comment: We do support timestamp to numeric conversion. checkout https://github.com/apache/hive/blob/7b3ecf617a6d46f48a3b6f77e0339fd4ad95a420/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java#L1177. due to which we need to allow NUMERIC in checkArgGroups(). Also this behaviour is controlled by https://github.com/apache/hive/blob/master/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java#L1827. -- 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-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 636792) Time Spent: 1h 40m (was: 1.5h) > Refactor UDF CAST(<Date string> as TIMESTAMP) > --------------------------------------------- > > Key: HIVE-25334 > URL: https://issues.apache.org/jira/browse/HIVE-25334 > Project: Hive > Issue Type: Sub-task > Reporter: Ashish Sharma > Assignee: Ashish Sharma > Priority: Major > Labels: pull-request-available > Time Spent: 1h 40m > Remaining Estimate: 0h > > Description > Refactor GenericUDFTimestamp.class > DOD > Refactor -- This message was sent by Atlassian Jira (v8.3.4#803005)