Hive で UDTF を開発しているときに ClassCastException が発生します。
詳細は次のとおりです。
- for_each(start,stop,increment) のような 3 つのパラメーターを渡すことができる for ループのような機能を実装しようとしています。
- すべてのパラメーターを for_each(1 , 10 , 1) のような値として渡すと、正常に機能します。
- 一方、停止値パラメータについては、UDF 関数の 1 つの結果を渡そうとしています (例: for_each(1 , stopvalue() , 1 のような stopvlaue() 値)。stopo dovalue() 関数は IntWritable を返します。これを行うと、次の例外が発生します。
ここに私のUDTFがあります:
public class GenerateSeries extends GenericUDTF {
IntWritable start;
IntWritable end;
IntWritable inc;
Object[] forwardObj = null;
@Override
public StructObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException
{
start=((WritableConstantIntObjectInspector) args[0]).getWritableConstantValue();
end=((WritableConstantIntObjectInspector) args[1]).getWritableConstantValue();
if (args.length == 3)
{
inc =((WritableConstantIntObjectInspector) args[2]).getWritableConstantValue();
} else {
inc = new IntWritable(1);
}
this.forwardObj = new Object[1];
ArrayList<String> fieldNames = new ArrayList<String>();
ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>();
fieldNames.add("col0");
fieldOIs.add(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(PrimitiveCategory.INT));
return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
}
@Override
public void process(Object[] args) throws HiveException, UDFArgumentException
{
for (int i = start.get(); i < end.get(); i = i + inc.get())
{
this.forwardObj[0] = new Integer(i);
forward(forwardObj);
}
}
@Override
public void close() throws HiveException {
// TODO Auto-generated method stub
}
}
この問題を解決するにはどうすればよいですか?
前もって感謝します