我正在尝试通过 Pig 程序使用 Amazon 的 Elastic Map Reduce 解析我们的服务生成的制表符分隔数据文件。一切进展顺利,除了我们所有的数据文件都包含一个定义每一列用途的标题行。显然,(字符串) header 不能转换为数字数据值,因此我从 Pig 收到如下警告:
2011-03-17 22:49:55,378 [main] WARN org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigHadoopLogger - org.apache.pig.builtin.PigStorage: Unable to interpret value [<snip>] in field being converted to double, caught NumberFormatException <For input string: "headerName"> field discarded
我在加载语句之后有一个过滤器,它试图确保我以后不会对任何标题行进行操作(通过过滤掉标题术语),但我想摆脱警告噪音以避免掩盖任何潜在问题(例如未正确转换的实际数据字段)。
这可能吗?
最佳答案
如果您不习惯编写 UDF,另一种选择可能是这样的:
示例数据:
MyIntVal
123
456
脚本:
A = load 's3://blah/myFile' USING PigStorage() as (myintval: chararray);
B = filter A by myintval neq 'MyIntVal';
C = foreach B generate (int)$0;
这将过滤掉标题行,然后将剩余的值转换为 int。
并不是说这是最好的方法,但如果适合您的情况,这是另一种非常简单的选择。
关于hadoop - 如何从 Hadoop 的 Pig 处理的文件中修剪标题行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5346348/