apache pig UDF java超出索引
我的UDF在pig遇到了访问问题。我在收到一个输出(Andi,19495)时进行了分组“分组”,pig将其描述为
C: {group: chararray, long}
。
现在我想将输出格式化为字符串(Andi 19495)。但我的UDF报告如下
"Caught error from UDF: pigUDF.Output, Out of bounds access [Index: 1, Size: 1]"
我不明白为什么会这样
以下是我的java UDF:
package pigUDF;
import java.io.IOException;
import org.apache.pig.EvalFunc;
import org.apache.pig.data.BagFactory;
import org.apache.pig.data.DataType;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
import org.apache.pig.impl.logicalLayer.schema.Schema;
import org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema;
public class Output extends EvalFunc<Tuple>{
TupleFactory tupleFactory = TupleFactory.getInstance();
BagFactory mBagFactory = BagFactory.getInstance();
private static Tuple nullValue=TupleFactory.getInstance().newTuple(2);
@Override
public Tuple exec(Tuple input) throws IOException {
if (input==null) return nullValue;
Tuple t= tupleFactory.newTuple(1);
String o = (String) input.get(0);
int o1 = (Integer) input.get(1);
String myString=o+" "+String.valueOf(o1);
System.out.println(myString);
t.set(0,myString);
return t;
}
@Override
public Schema outputSchema(Schema input){
Schema tupleSchema = new Schema();
tupleSchema.add(new FieldSchema("group", DataType.CHARARRAY));
Schema s = new Schema (new FieldSchema(null, tupleSchema));
return s;
}
}
共 (0) 个答案