use of org.apache.hadoop.hive.ql.exec.vector.expressions.TruncStringOutput in project hive by apache.
the class VectorizationContext method instantiateExpression.
public VectorExpression instantiateExpression(Class<?> vclass, TypeInfo returnTypeInfo, DataTypePhysicalVariation returnDataTypePhysicalVariation, Object... args) throws HiveException {
VectorExpression ve = null;
Constructor<?> ctor = getConstructor(vclass);
int numParams = ctor.getParameterTypes().length;
int argsLength = (args == null) ? 0 : args.length;
if (numParams == 0) {
try {
ve = (VectorExpression) ctor.newInstance();
} catch (Exception ex) {
throw new HiveException("Could not instantiate " + vclass.getSimpleName() + " with 0 arguments, exception: " + getStackTraceAsSingleLine(ex));
}
} else if (numParams == argsLength) {
try {
ve = (VectorExpression) ctor.newInstance(args);
} catch (Exception ex) {
throw new HiveException("Could not instantiate " + vclass.getSimpleName() + " with " + getNewInstanceArgumentString(args) + ", exception: " + getStackTraceAsSingleLine(ex));
}
} else if (numParams == argsLength + 1) {
// Additional argument is needed, which is the outputcolumn.
Object[] newArgs = null;
try {
if (returnTypeInfo == null) {
throw new HiveException("Missing output type information");
}
String returnTypeName = returnTypeInfo.getTypeName();
// Special handling for decimal because decimal types need scale and precision parameter.
// This special handling should be avoided by using returnType uniformly for all cases.
final int outputColumnNum = ocm.allocateOutputColumn(returnTypeInfo, returnDataTypePhysicalVariation);
newArgs = Arrays.copyOf(Objects.requireNonNull(args), numParams);
newArgs[numParams - 1] = outputColumnNum;
ve = (VectorExpression) ctor.newInstance(newArgs);
/*
* Caller is responsible for setting children and input type information.
*/
ve.setOutputTypeInfo(returnTypeInfo);
ve.setOutputDataTypePhysicalVariation(returnDataTypePhysicalVariation);
} catch (Exception ex) {
throw new HiveException("Could not instantiate " + vclass.getSimpleName() + " with arguments " + getNewInstanceArgumentString(newArgs) + ", exception: " + getStackTraceAsSingleLine(ex));
}
}
// Add maxLength parameter to UDFs that have CHAR or VARCHAR output.
if (ve instanceof TruncStringOutput) {
TruncStringOutput truncStringOutput = (TruncStringOutput) ve;
if (returnTypeInfo instanceof BaseCharTypeInfo) {
BaseCharTypeInfo baseCharTypeInfo = (BaseCharTypeInfo) returnTypeInfo;
truncStringOutput.setMaxLength(baseCharTypeInfo.getLength());
}
}
return ve;
}
Aggregations