use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDTFParseUrlTuple method initialize.
@Override
public StructObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException {
inputOIs = args;
numCols = args.length - 1;
if (numCols < 1) {
throw new UDFArgumentException("parse_url_tuple() takes at least two arguments: " + "the url string and a part name");
}
for (int i = 0; i < args.length; ++i) {
if (args[i].getCategory() != ObjectInspector.Category.PRIMITIVE || !args[i].getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) {
throw new UDFArgumentException("parse_url_tuple()'s arguments have to be string type");
}
}
seenErrors = false;
pathParsed = false;
url = null;
p = null;
lastKey = null;
paths = new String[numCols];
partnames = new PARTNAME[numCols];
cols = new Text[numCols];
retCols = new Text[numCols];
nullCols = new Object[numCols];
for (int i = 0; i < numCols; ++i) {
cols[i] = new Text();
retCols[i] = cols[i];
nullCols[i] = null;
}
// construct output object inspector
ArrayList<String> fieldNames = new ArrayList<String>(numCols);
ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(numCols);
for (int i = 0; i < numCols; ++i) {
// column name can be anything since it will be named by UDTF as clause
fieldNames.add("c" + i);
// all returned type will be Text
fieldOIs.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector);
}
return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class TestGenericUDFGreatest method testOneArg.
@Test
public void testOneArg() throws HiveException {
@SuppressWarnings("resource") GenericUDFGreatest udf = new GenericUDFGreatest();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI1 };
UDFArgumentException ex = null;
try {
udf.initialize(arguments);
} catch (UDFArgumentException e) {
ex = e;
}
assertNotNull("greatest() test ", ex);
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class TestGenericUDFDate method testVoidToDate.
@Test
public void testVoidToDate() throws HiveException {
GenericUDFDate udf = new GenericUDFDate();
ObjectInspector valueOI = PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
ObjectInspector[] arguments = { valueOI };
udf.initialize(arguments);
DeferredObject[] args = { new DeferredJavaObject(null) };
DateWritableV2 output = (DateWritableV2) udf.evaluate(args);
// Try with null VOID
assertNull("to_date() with null DATE ", output);
// Try with erroneously generated VOID
DeferredObject[] junkArgs = { new DeferredJavaObject(new Text("2015-11-22")) };
try {
udf.evaluate(junkArgs);
fail("to_date() test with VOID non-null failed");
} catch (UDFArgumentException udfae) {
assertEquals("TO_DATE() received non-null object of VOID type", udfae.getMessage());
}
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFBaseCompare method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentException(opName + " requires two arguments.");
}
argumentOIs = arguments;
Category c1 = arguments[0].getCategory();
Category c2 = arguments[1].getCategory();
if (c1 != c2) {
throw new UDFArgumentException("Type mismatch in " + opName + "(" + c1 + "," + c2 + ")");
}
if (!supportsCategory(c1)) {
throw new UDFArgumentException(opName + " does not support " + c1 + " types");
}
switch(c1) {
case PRIMITIVE:
initForPrimitives(arguments[0], arguments[1]);
break;
case MAP:
case STRUCT:
case LIST:
initForNonPrimitives(arguments[0], arguments[1]);
break;
default:
throw new AssertionError("Missing init method for " + c1 + " types");
}
return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFBaseUnary method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentException(opName + " requires one argument.");
}
Category category = arguments[0].getCategory();
if (category != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found");
}
inputOI = (PrimitiveObjectInspector) arguments[0];
if (!FunctionRegistry.isNumericType(inputOI.getTypeInfo()) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalDayTimeTypeInfo) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalYearMonthTypeInfo)) {
throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to be a " + "numeric or interval type, but " + inputOI.getTypeName() + " is found");
}
PrimitiveTypeInfo resultTypeInfo = deriveResultTypeInfo(inputOI.getTypeInfo());
resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(resultTypeInfo);
converter = ObjectInspectorConverters.getConverter(inputOI, resultOI);
return resultOI;
}
Aggregations