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/07/27 05:23:26 UTC
[GitHub] [hive] adesh-rao commented on a change in pull request #2482: HIVE-25334: refactor timestamp UDF
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: 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