use of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException in project hive by apache.
the class TestGenericUDFLevenshtein method testLevenshteinWrongType0.
public void testLevenshteinWrongType0() throws HiveException {
@SuppressWarnings("resource") GenericUDFLevenshtein udf = new GenericUDFLevenshtein();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
ObjectInspector[] arguments = { valueOI0, valueOI1 };
try {
udf.initialize(arguments);
assertTrue("levenshtein test. UDFArgumentTypeException is expected", false);
} catch (UDFArgumentTypeException e) {
assertEquals("levenshtein test", "levenshtein only takes STRING_GROUP, VOID_GROUP types as 1st argument, got INT", e.getMessage());
}
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException in project hive by apache.
the class TestGenericUDFLevenshtein method testLevenshteinWrongType1.
public void testLevenshteinWrongType1() throws HiveException {
@SuppressWarnings("resource") GenericUDFLevenshtein udf = new GenericUDFLevenshtein();
ObjectInspector valueOI0 = PrimitiveObjectInspectorFactory.writableHiveVarcharObjectInspector;
ObjectInspector valueOI1 = PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
ObjectInspector[] arguments = { valueOI0, valueOI1 };
try {
udf.initialize(arguments);
assertTrue("levenshtein test. UDFArgumentTypeException is expected", false);
} catch (UDFArgumentTypeException e) {
assertEquals("levenshtein test", "levenshtein only takes STRING_GROUP, VOID_GROUP types as 2nd argument, got FLOAT", e.getMessage());
}
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException in project hive by apache.
the class GenericUDF method obtainDateConverter.
protected void obtainDateConverter(ObjectInspector[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws UDFArgumentTypeException {
PrimitiveObjectInspector inOi = (PrimitiveObjectInspector) arguments[i];
PrimitiveCategory inputType = inOi.getPrimitiveCategory();
ObjectInspector outOi;
switch(inputType) {
case STRING:
case VARCHAR:
case CHAR:
outOi = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
break;
case TIMESTAMP:
case DATE:
case VOID:
case TIMESTAMPLOCALTZ:
outOi = PrimitiveObjectInspectorFactory.writableDateObjectInspector;
break;
default:
throw new UDFArgumentTypeException(i, getFuncName() + " only takes STRING_GROUP or DATE_GROUP types as " + getArgOrder(i) + " argument, got " + inputType);
}
converters[i] = ObjectInspectorConverters.getConverter(inOi, outOi);
inputTypes[i] = inputType;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException in project hive by apache.
the class GenericUDF method getDateValue.
protected Date getDateValue(DeferredObject[] arguments, int i, PrimitiveCategory[] inputTypes, Converter[] converters) throws HiveException {
Object obj;
if ((obj = arguments[i].get()) == null) {
return null;
}
Date date;
switch(inputTypes[i]) {
case STRING:
case VARCHAR:
case CHAR:
String dateStr = converters[i].convert(obj).toString();
try {
date = DateUtils.getDateFormat().parse(dateStr);
} catch (ParseException e) {
throw new UDFArgumentException("Unparsable date: " + dateStr);
}
break;
case TIMESTAMP:
case DATE:
case TIMESTAMPLOCALTZ:
Object writableValue = converters[i].convert(obj);
date = ((DateWritable) writableValue).get();
break;
default:
throw new UDFArgumentTypeException(0, getFuncName() + " only takes STRING_GROUP and DATE_GROUP types, got " + inputTypes[i]);
}
return date;
}
use of org.apache.hadoop.hive.ql.exec.UDFArgumentTypeException in project hive by apache.
the class GenericUDFAssertTrueOOM method initialize.
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
HiveConf conf = SessionState.getSessionConf();
if (!conf.getBoolVar(HiveConf.ConfVars.HIVE_IN_TEST)) {
throw new RuntimeException("this UDF is only available in testmode");
}
if (arguments.length != 1) {
throw new UDFArgumentLengthException("ASSERT_TRUE_OOM() expects one argument.");
}
if (arguments[0].getCategory() != Category.PRIMITIVE) {
throw new UDFArgumentTypeException(0, "Argument to ASSERT_TRUE_OOM() should be primitive.");
}
conditionConverter = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.writableBooleanObjectInspector);
return PrimitiveObjectInspectorFactory.writableVoidObjectInspector;
}
Aggregations