}
private Decimal128 castConstantToDecimal(Object scalar, TypeInfo type) throws HiveException {
PrimitiveTypeInfo ptinfo = (PrimitiveTypeInfo) type;
String typename = type.getTypeName();
Decimal128 d = new Decimal128();
int scale = HiveDecimalUtils.getScaleForType(ptinfo);
switch (ptinfo.getPrimitiveCategory()) {
case FLOAT:
float floatVal = ((Float) scalar).floatValue();
d.update(floatVal, (short) scale);
break;
case DOUBLE:
double doubleVal = ((Double) scalar).doubleValue();
d.update(doubleVal, (short) scale);
break;
case BYTE:
byte byteVal = ((Byte) scalar).byteValue();
d.update(byteVal, (short) scale);
break;
case SHORT:
short shortVal = ((Short) scalar).shortValue();
d.update(shortVal, (short) scale);
break;
case INT:
int intVal = ((Integer) scalar).intValue();
d.update(intVal, (short) scale);
break;
case LONG:
long longVal = ((Long) scalar).longValue();
d.update(longVal, (short) scale);
break;
case DECIMAL:
HiveDecimal decimalVal = (HiveDecimal) scalar;
d.update(decimalVal.unscaledValue(), (short) scale);
break;
default:
throw new HiveException("Unsupported type "+typename+" for cast to Decimal128");
}
return d;