Pig转换元组数据Map?

sgtfey8w  于 2021-06-25  发布在  Pig
关注(0)|答案(0)|浏览(241)

您好,有人能指导使用pig将元组数据转换成Map吗?
我的数据是

2013-09-24 19:58:04.440 server120 TRSID=20,RID=e7a8-244ce04-03b6k8962890k,EXTID=e7a8a921-244c-e043-03b6k8962890k

我试着把数据转换成下面的Map。但有些人怎么也无法将数据转换成Map,导致 Tupletomapfailed 错误。

package mymapudf;
import java.io.IOException;
import org.apache.pig.EvalFunc;

import java.util.Map;
import java.util.Map.Entry;

import org.apache.pig.data.Tuple;

public class udfmap extends EvalFunc<Map>
{
    public Map exec(Tuple input) throws IOException 
    {
        try 
        {
           //taBag values = (DataBag)input.get(1);
           //String value = (String)input.get(1);
           //Map<Object, Object> m = new HashMap<Object, Object>();
           Map<String,String> m2 = (Map<String, String>) input.get(1);
           for (Entry<String, String> entry:m2.entrySet()) 
           {
               m2.put(entry.getKey(),entry.getValue());
               //Tuple tuple = TupleFactory.newTuple(2);
           }
           return m2;
       } 
       catch(Exception e) 
       {
            throw new RuntimeException("Tupletomapfailed error", e);
       }
    }
}

请提供一些建议,以实现所需的Map转换为剩余的数据离开时间戳?
架构:

data_load = LOAD '/user/uk01/test.log'  USING PigStorage(' ') AS ( dt:chararray, nodes:tuple(servername:chararray,TRIS:chararray,EXTID:chararray));

gen_test = FOREACH data_load GENERATE mymapudf.udf(nodes);

清管器堆栈跟踪:

ERROR 2999: Unexpected internal error. Tupletomapfailed error

java.lang.RuntimeException: Tupletomapfailed error
        at mymapudf.udfmap.exec(udfmap.java:30)
        at mymapudf.udfmap.exec(udfmap.java:1)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc.getNext(POUserFunc.java:337)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POUserFunc.getNext(POUserFunc.java:428)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator.getNext(PhysicalOperator.java:352)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach.processPlan(POForEach.java:372)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach.getNext(POForEach.java:297)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator.processInput(PhysicalOperator.java:308)
        at org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POFilter.getNext(POFilter.java:95)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题