}
return HiveDecimalUtils.getPrecisionForType(typeInfo);
}
private GenericUDF getGenericUDFForCast(TypeInfo castType) throws HiveException {
UDF udfClass = null;
GenericUDF genericUdf = null;
switch (((PrimitiveTypeInfo) castType).getPrimitiveCategory()) {
case BYTE:
udfClass = new UDFToByte();
break;
case SHORT:
udfClass = new UDFToShort();
break;
case INT:
udfClass = new UDFToInteger();
break;
case LONG:
udfClass = new UDFToLong();
break;
case FLOAT:
udfClass = new UDFToFloat();
break;
case DOUBLE:
udfClass = new UDFToDouble();
break;
case STRING:
udfClass = new UDFToString();
break;
case CHAR:
genericUdf = new GenericUDFToChar();
break;
case VARCHAR:
genericUdf = new GenericUDFToVarchar();
break;
case BOOLEAN:
udfClass = new UDFToBoolean();
break;
case DATE:
genericUdf = new GenericUDFToDate();
break;
case TIMESTAMP:
genericUdf = new GenericUDFToUnixTimeStamp();
break;
case BINARY:
genericUdf = new GenericUDFToBinary();
break;
case DECIMAL:
genericUdf = new GenericUDFToDecimal();
break;
}
if (genericUdf == null) {
if (udfClass == null) {
throw new HiveException("Could not add implicit cast for type "+castType.getTypeName());
}
genericUdf = new GenericUDFBridge();
((GenericUDFBridge) genericUdf).setUdfClassName(udfClass.getClass().getName());
}
if (genericUdf instanceof SettableUDF) {
((SettableUDF) genericUdf).setTypeInfo(castType);
}
return genericUdf;