You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by 张峰华 <zh...@gmail.com> on 2012/09/13 04:35:23 UTC

ERROR 1081: Cannot cast to map. Expected bytearray but received: chararray at org.apache.pig.backend.hadoop.executionengine.physicalLayer.

Hi all,

I'm currently working with Pig 0.9.2. I'd like to load some data using
myself define loader , but I encountered some problems. When I try to load
the data it seems to work:

/////////run_loaddhevent.pig
REGISTER /home/hdfs/report/commonscripts/mystorage.jar;
A = LOAD '$input' USING com.xxx.hadoop.pig.MyStorage() AS
(name:chararray,tags:map[chararray]);
B = foreach A generate name;
C = foreach A generate tags
describe A; --output:A: {name: chararray,tags: map[chararray]}
describe B; --output:B:{name: chararray}
describe C; --output:C:{tags:map[chararray]}

dump A;
dump B;
dump C;

when I  dump A; the result like below:
(john,[age#20,country#US])
(sam,[age#22,address#GE])
....(it's OK)

dump B:
(john)
(sam)
...(it's OK)

but when I dump C I get this exception:

org.apache.pig.backend.executionengine.ExecException: ERROR 1081: Cannot
cast to map. Expected bytearray but received: chararray at
org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.POCast.getNext(POCast.java:1269)
at
org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator.getNext(PhysicalOperator.java:332)
at
org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach.processPlan(POForEach.java:332)
at
org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POForEach.getNext(POForEach.java:284)
at
org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.runPipeline(PigGenericMapBase.java:267)
at
org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.map(PigGenericMapBase.java:262)
at
org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.map(PigGenericMapBase.java:64)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:140) a

I  am expecting the result like :
([age#20,country#US])
([age#22,address#GE])
....

anyone who encountered  the same issues?

//below is my UDF Storage
public class  MyStorage extends PigStorage {
private TupleFactory mTupleFactory = TupleFactory.getInstance();
       @Override
public Tuple getNext() throws IOException {
// TODO Auto-generated method stub
        Tuple t = mTupleFactory.newTuple();
                t.append(name);
                t.append(Map<String,Object>);
                return t;
        }
}