Я пытаюсь реализовать UDF Hive с параметром , поэтому я расширяю класс GenericUDF .
Проблема в том, что мой UDF работает с типом данных String, однако он выдает ошибку, если я запускаю другие типы данных. Я хочу, чтобы UDF работал независимо от типа данных.
Кто-нибудь, пожалуйста, дайте мне знать, что не так со следующим кодом.
@Description(name = "Encrypt", value = "Encrypt the Given Column", extended = "SELECT Encrypt('Hello World!', 'Key');")
public class Encrypt extends GenericUDF {
StringObjectInspector key;
StringObjectInspector col;
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
if (arguments.length != 2) {
throw new UDFArgumentLengthException("Encrypt only takes 2 arguments: T, String");
}
ObjectInspector keyObject = arguments[1];
ObjectInspector colObject = arguments[0];
if (!(keyObject instanceof StringObjectInspector)) {
throw new UDFArgumentException("Error: Key Type is Not String");
}
this.key = (StringObjectInspector) keyObject;
this.col = (StringObjectInspector) colObject;
return PrimitiveObjectInspectorFactory.javaStringObjectInspector;
}
@Override
public Object evaluate(DeferredObject[] deferredObjects) throws HiveException {
String keyString = key.getPrimitiveJavaObject(deferredObjects[1].get());
String colString = col.getPrimitiveJavaObject(deferredObjects[0].get());
return AES.encrypt(colString, keyString);
}
@Override
public String getDisplayString(String[] strings) {
return null;
}
}
Ошибка
java .lang.ClassCastException: org. apache .had oop .hive.serde2.objectinspector. primitive.JavaIntObjectInspector нельзя преобразовать в org. apache .had oop .hive.serde2.objectinspector.primitive.StringObjectInspector