use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFToVarchar method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentException("VARCHAR cast requires a value argument");
}
try {
argumentOI = (PrimitiveObjectInspector) arguments[0];
} catch (ClassCastException e) {
throw new UDFArgumentException("The function VARCHAR takes only primitive types");
}
// Check if this UDF has been provided with type params for the output varchar type
SettableHiveVarcharObjectInspector outputOI;
outputOI = (SettableHiveVarcharObjectInspector) PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
converter = new HiveVarcharConverter(argumentOI, outputOI);
return outputOI;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFToChar method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentException("CHAR cast requires a value argument");
}
try {
argumentOI = (PrimitiveObjectInspector) arguments[0];
} catch (ClassCastException e) {
throw new UDFArgumentException("The function CHAR takes only primitive types");
}
// Check if this UDF has been provided with type params for the output char type
SettableHiveCharObjectInspector outputOI;
outputOI = (SettableHiveCharObjectInspector) PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo);
converter = new HiveCharConverter(argumentOI, outputOI);
return outputOI;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class TestGenericUDFDeserialize method testOneArg.
@Test
public void testOneArg() throws HiveException {
GenericUDFDeserialize udf = new GenericUDFDeserialize();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector valueOI2 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
UDFArgumentException ex = null;
try {
udf.initialize(new ObjectInspector[] { valueOI1 });
} catch (UDFArgumentException e) {
ex = e;
}
assertTrue(ex.getMessage().contains("The function deserialize accepts 2 arguments."));
assertNotNull("The function deserialize() accepts 2 argument.", ex);
ex = null;
try {
udf.initialize(new ObjectInspector[] { valueOI2, valueOI1 });
} catch (UDFArgumentException e) {
ex = e;
}
assertNull("The function deserialize() accepts 2 argument.", ex);
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class TestGenericUDFLeast method testOneArg.
@Test
public void testOneArg() throws HiveException {
@SuppressWarnings("resource") GenericUDFLeast udf = new GenericUDFLeast();
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI1 };
UDFArgumentException ex = null;
try {
udf.initialize(arguments);
} catch (UDFArgumentException e) {
ex = e;
}
assertNotNull("least() test ", ex);
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentException in project hive by apache.
the class GenericUDFBaseTrim method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 1) {
throw new UDFArgumentException(udfName + " requires one value argument. Found :" + arguments.length);
}
PrimitiveObjectInspector argumentOI;
if (arguments[0] instanceof PrimitiveObjectInspector) {
argumentOI = (PrimitiveObjectInspector) arguments[0];
} else {
throw new UDFArgumentException(udfName + " takes only primitive types. found " + arguments[0].getTypeName());
}
switch(argumentOI.getPrimitiveCategory()) {
case STRING:
case CHAR:
case VARCHAR:
break;
default:
throw new UDFArgumentException(udfName + " takes only STRING/CHAR/VARCHAR types. Found " + argumentOI.getPrimitiveCategory());
}
converter = new TextConverter(argumentOI);
return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
}
Aggregations