我是新来的Hiveudtf。我需要在udtf中传递字符串值作为parameter,返回的列应该是arraylist。
我编写了以下代码:
public StructObjectInspector initialize(ObjectInspector[] arg0)
throws UDFArgumentException {
ArrayList<String> fieldNames = new ArrayList<String>();
ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
fieldNames.add("col1");
stringOI = (PrimitiveObjectInspector) arg0[0];
listOi=(ListObjectInspector) arg0[0];
fieldOIs.add(listOi.getListElementObjectInspector());
return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
@Override
public void process(Object[] record) throws HiveException {
// TODO Auto-generated method stub
String document = (String) stringOI.getPrimitiveJavaObject(record[0]);
if (document == null) {
return;
}
firstColumn=(String) stringOI.getPrimitiveJavaObject(record[0]);
secondColumn=(String) stringOI.getPrimitiveJavaObject(record[1]);
if(outputMapper.containsKey(firstColumn))
{
ArrayList<String> tempList=new ArrayList<String>();
tempList=outputMapper.get(firstColumn);
tempList.add(secondColumn);
outputMapper.put(firstColumn,tempList);
}
else
{
childVendorList=new ArrayList<String>();
childVendorList.add(secondColumn);
outputMapper.put(firstColumn,childVendorList);
}
forward(outputMapper.get(firstColumn));
}
}
我得到以下例外:
java.lang.classcastexception:org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.lazystringobjectinspector不能转换为org.apache.hadoop.hive.serde2.objectinspector.listobjectinspector
有人能帮忙吗???
1条答案
按热度按时间zujrkrfu1#
此arg0[0]是基本对象检查器。对于listoi.getlistelementobjectinspector(),只需获取一个类似的primitiveobjectinspector(与string类似,integer不是列表)。应该的
这将用stringoi类型的列表指定输出列。