use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFMacro method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
checkNotNull(colTypes, "colTypes");
checkNotNull(arguments, "arguments");
checkNotNull(bodyDesc, "bodyDesc");
if (colTypes.size() != arguments.length) {
throw new UDFArgumentLengthException("The macro " + macroName + " accepts exactly " + colTypes.size() + " arguments.");
}
try {
body = ExprNodeEvaluatorFactory.get(bodyDesc);
} catch (HiveException ex) {
throw new UDFArgumentException(ex);
}
converters = new ObjectInspectorConverters.Converter[arguments.length];
ArrayList<ObjectInspector> colObjectInspectors = new ArrayList<ObjectInspector>(colTypes.size());
for (int index = 0; index < arguments.length; ++index) {
ObjectInspector objectInspector = TypeInfoUtils.getStandardWritableObjectInspectorFromTypeInfo(colTypes.get(index));
colObjectInspectors.add(objectInspector);
converters[index] = ObjectInspectorConverters.getConverter(arguments[index], objectInspector);
}
evaluatedArguments = new ArrayList<Object>(arguments.length);
ObjectInspector structOI = ObjectInspectorFactory.getStandardStructObjectInspector(colNames, colObjectInspectors);
try {
return body.initialize(structOI);
} catch (HiveException ex) {
throw new UDFArgumentException(ex);
}
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFOctetLength method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentLengthException("OCTET_LENGTH requires 1 argument, got " + arguments.length);
}
if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
throw new UDFArgumentException("OCTET_LENGTH only takes primitive types, got " + argumentOI.getTypeName());
}
argumentOI = (PrimitiveObjectInspector) arguments[0];
stringConverter = new PrimitiveObjectInspectorConverter.StringConverter(argumentOI);
PrimitiveObjectInspector.PrimitiveCategory inputType = argumentOI.getPrimitiveCategory();
ObjectInspector outputOI = null;
switch(inputType) {
case CHAR:
case VARCHAR:
case STRING:
isInputString = true;
break;
case BINARY:
isInputString = false;
break;
default:
throw new UDFArgumentException(" OCTET_LENGTH() only takes STRING/CHAR/VARCHAR/BINARY types as first argument, got " + inputType);
}
outputOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
return outputOI;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFQuote method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentException("QUOTE() requires one value argument. Found :" + arguments.length);
}
PrimitiveObjectInspector argumentOI;
if (arguments[0] instanceof PrimitiveObjectInspector) {
argumentOI = (PrimitiveObjectInspector) arguments[0];
} else {
throw new UDFArgumentException("QUOTE() takes only primitive types. Found " + arguments[0].getTypeName());
}
converter = new TextConverter(argumentOI);
return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFPower method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentException(opName + " requires two arguments.");
}
for (int i = 0; i < 2; i++) {
Category category = arguments[i].getCategory();
if (category != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(i, "The " + GenericUDFUtils.getOrdinal(i + 1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found");
}
}
baseOI = (PrimitiveObjectInspector) arguments[0];
if (!FunctionRegistry.isNumericType(baseOI.getTypeInfo())) {
throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + "numeric type, but " + baseOI.getTypeName() + " is found");
}
powerOI = (PrimitiveObjectInspector) arguments[1];
if (!FunctionRegistry.isNumericType(powerOI.getTypeInfo())) {
throw new UDFArgumentTypeException(1, "The " + GenericUDFUtils.getOrdinal(2) + " argument of " + opName + " is expected to a " + "numeric type, but " + powerOI.getTypeName() + " is found");
}
baseConverter = ObjectInspectorConverters.getConverter(baseOI, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
powerConverter = ObjectInspectorConverters.getConverter(powerOI, PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
return resultOI;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFReflect2 method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length < 2) {
throw new UDFArgumentLengthException("The function GenericUDFReflect2(arg0,method[,arg1[,arg2]...])" + " accepts 2 or more arguments.");
}
if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) {
throw new UDFArgumentTypeException(1, "The target instance should be a primitive type.");
}
targetOI = (PrimitiveObjectInspector) arguments[0];
if (!(arguments[1] instanceof StringObjectInspector)) {
throw new UDFArgumentTypeException(1, "The method name should be string type.");
}
if (!(arguments[1] instanceof ConstantObjectInspector)) {
throw new UDFArgumentTypeException(1, "The method name should be a constant.");
}
Text methodName = (Text) ((ConstantObjectInspector) arguments[1]).getWritableConstantValue();
if (methodName.toString().equals("hashCode") && arguments.length == 2) {
// it's non-deterministic
throw new UDFArgumentTypeException(1, "Use hash() UDF instead of this.");
}
setupParameterOIs(arguments, 2);
Class<?> targetClass = PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveCategory(targetOI.getPrimitiveCategory()).primitiveJavaClass;
try {
method = findMethod(targetClass, methodName.toString(), null, true);
// Note: type param is not available here.
PrimitiveTypeEntry typeEntry = getTypeFor(method.getReturnType());
returnOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeEntry.primitiveCategory);
returnObj = (Writable) returnOI.getPrimitiveWritableClass().newInstance();
} catch (Exception e) {
throw new UDFArgumentException(e);
}
return returnOI;
}
Aggregations