0

我有不同长度的元组。我正在尝试将它们转换为只有一个字段的元组(每个字段都是一个地图)。
原始数据:

dump entryArray;
([symbol#HIG,security_type#EQUITY,foreign_entry_id#743094])
([symbol#PEW,security_type#EQUITY,foreign_entry_id#743084])
([symbol#AFFY,security_type#EQUITY,foreign_entry_id#5585],[symbol#RFG,security_type#ETF,foreign_entry_id#5586],[symbol#SCHW,security_type#EQUITY,foreign_entry_id#5587],[symbol#VWO,security_type#ETF,foreign_entry_id#5588])

我希望输出是(每个字段仍然是地图):

([symbol#HIG,security_type#EQUITY,foreign_entry_id#743094])
([symbol#PEW,security_type#EQUITY,foreign_entry_id#743084])
([symbol#AFFY,security_type#EQUITY,foreign_entry_id#5585])   
([symbol#RFG,security_type#ETF,foreign_entry_id#5586])
([symbol#SCHW,security_type#EQUITY,foreign_entry_id#5587])
([symbol#VWO,security_type#ETF,foreign_entry_id#5588])


我试过entry = FOREACH entryArray GENERATE FLATTEN(TOBAG());了:输出格式相同,但该字段似乎不再是 MAP:

entry = FOREACH entryArray GENERATE FLATTEN(TOBAG());
dump entry;
([symbol#HIG,security_type#EQUITY,foreign_entry_id#743094])
([symbol#PEW,security_type#EQUITY,foreign_entry_id#743084])
([symbol#AFFY,security_type#EQUITY,foreign_entry_id#5585])   
([symbol#RFG,security_type#ETF,foreign_entry_id#5586])
([symbol#SCHW,security_type#EQUITY,foreign_entry_id#5587])
([symbol#VWO,security_type#ETF,foreign_entry_id#5588])

security_type = FOREACH entry GENERATE FLATTEN($0#'security_type');
it throws:
ERROR 1052: Cannot cast bytearray to map with schema :map
org.apache.pig.impl.logicalLayer.validators.TypeCheckerException: ERROR 1059: <line 18, column 16> Problem while reconciling output schema of ForEach
at org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.throwTypeCheckerException(TypeCheckingRelVisitor.java:141)
at org.apache.pig.newplan.logical.visitor.TypeCheckingRelVisitor.visit(TypeCheckingRelVisitor.java:181)
at org.apache.pig.newplan.logical.relational.LOForEach.accept(LOForEach.java:75)
......

任何建议将不胜感激。谢谢!

4

0 回答 0