mdayakar commented on code in PR #3808:
URL: https://github.com/apache/hive/pull/3808#discussion_r1033436345
##########
hplsql/src/main/java/org/apache/hive/hplsql/udf/Udf.java:
##########
@@ -128,27 +127,96 @@ public Object evaluate(DeferredObject[] arguments) throws
HiveException {
void setParameters(DeferredObject[] arguments) throws HiveException {
for (int i = 1; i < arguments.length; i++) {
String name = ":" + i;
- if (argumentsOI[i] instanceof StringObjectInspector) {
- String value =
((StringObjectInspector)argumentsOI[i]).getPrimitiveJavaObject(arguments[i].get());
- if (value != null) {
- exec.setVariable(name, value);
- }
+ Object inputObject = arguments[i].get();
+ ObjectInspector objectInspector = argumentsOI[i];
+ if (objectInspector.getCategory() == ObjectInspector.Category.PRIMITIVE)
{
+ setParameterForPrimitiveTypeArgument(name, inputObject,
objectInspector);
+ } else {
+ exec.setVariableToNull(name);
}
- else if (argumentsOI[i] instanceof IntObjectInspector) {
- Integer value =
(Integer)((IntObjectInspector)argumentsOI[i]).getPrimitiveJavaObject(arguments[i].get());
- if (value != null) {
- exec.setVariable(name, new Var(new Long(value)));
- }
+ }
+ }
+
+ private void setParameterForPrimitiveTypeArgument(String name, Object
inputObject, ObjectInspector objectInspector) {
+ PrimitiveObjectInspector.PrimitiveCategory primitiveCategory =
+ ((PrimitiveObjectInspector) objectInspector).getPrimitiveCategory();
+ switch (primitiveCategory) {
+ case BOOLEAN:
+ Boolean booleanValue = (Boolean) ((BooleanObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (booleanValue != null) {
+ exec.setVariable(name, new Var(booleanValue));
}
- else if (argumentsOI[i] instanceof LongObjectInspector) {
- Long value =
(Long)((LongObjectInspector)argumentsOI[i]).getPrimitiveJavaObject(arguments[i].get());
- if (value != null) {
- exec.setVariable(name, new Var(value));
- }
+ break;
+ case SHORT:
+ Short shortValue = (Short) ((ShortObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (shortValue != null) {
+ exec.setVariable(name, new Var(shortValue.longValue()));
}
- else {
- exec.setVariableToNull(name);
+ break;
+ case INT:
+ Integer intValue = (Integer) ((IntObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (intValue != null) {
+ exec.setVariable(name, new Var(intValue.longValue()));
+ }
+ break;
+ case LONG:
+ Long longValue = (Long) ((LongObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (longValue != null) {
+ exec.setVariable(name, new Var(longValue));
+ }
+ break;
+ case FLOAT:
+ Float floatValue = (Float) ((FloatObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (floatValue != null) {
+ exec.setVariable(name, new Var(floatValue.doubleValue()));
+ }
+ break;
+ case DOUBLE:
+ Double doubleValue = (Double) ((DoubleObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (doubleValue != null) {
+ exec.setVariable(name, new Var(doubleValue));
+ }
+ break;
+ case STRING:
+ String strValue = ((StringObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (strValue != null) {
+ exec.setVariable(name, strValue);
+ }
+ break;
+ case DATE:
+ Date dateValue = ((DateObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (dateValue != null) {
+ exec.setVariable(name, new
Var(java.sql.Date.valueOf(dateValue.toString())));
+ }
+ break;
+ case TIMESTAMP:
+ Timestamp timestampValue = ((TimestampObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (timestampValue != null) {
+ java.sql.Timestamp timestamp =
java.sql.Timestamp.valueOf(timestampValue.toString());
+ timestamp.setNanos(timestampValue.getNanos());
+ exec.setVariable(name, new Var(timestamp, 0));
+ }
+ break;
+ case DECIMAL:
+ HiveDecimal decimalValue = ((HiveDecimalObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (decimalValue != null) {
+ exec.setVariable(name, new Var(decimalValue.bigDecimalValue()));
+ }
+ break;
+ case VARCHAR:
+ HiveVarchar varcharValue = ((HiveVarcharObjectInspector)
objectInspector).getPrimitiveJavaObject(inputObject);
+ if (varcharValue != null) {
+ exec.setVariable(name, varcharValue.getValue());
Review Comment:
Fixed
--
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]