我有一个Pig脚本,其中包含一些计算繁重的部分;我想摘下这些部分,并通过一些优化的MapReduce作业来运行它们。
我认为,对于MapReduce作业而言,直接读取和写入Pig用于存储中间结果的相同数据格式将是完美的,以避免不必要的转换。
我当时正在考虑使用org.apache.pig.builtin.BinStorage
存储功能存储数据。
我的问题是我不知道如何从MapReduce作业中读取该格式。
我尝试使用以下代码:
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<NullWritable, BinSedesTuple, Text, IntWritable> {
public void map(NullWritable key, BinSedesTuple value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
//do something
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
//do something
}
}
public static void main(String[] args) throws Exception {
//......
conf.setInputFormat(SequenceFileInputFormat.class);
conf.setOutputFormat(SequenceFileOutputFormat.class);
//.....
}
}
但是我得到这个错误:
java.io.IOException: hdfs://localhost:54310/user/path/to/part-m-00000 not a SequenceFile
at org.apache.hadoop.io.SequenceFile$Reader.init(SequenceFile.java:1517)
at org.apache.hadoop.io.SequenceFile$Reader.<init>(SequenceFile.java:1490)
at org.apache.hadoop.io.SequenceFile$Reader.<init>(SequenceFile.java:1479)
at org.apache.hadoop.io.SequenceFile$Reader.<init>(SequenceFile.java:1474)
at org.apache.hadoop.mapred.SequenceFileRecordReader.<init>(SequenceFileRecordReader.java:43)
at org.apache.hadoop.mapred.SequenceFileInputFormat.getRecordReader(SequenceFileInputFormat.java:59)
at org.apache.hadoop.mapred.MapTask$TrackedRecordReader.<init>(MapTask.java:191)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:412)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:366)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)
有人知道如何使其工作吗?
最佳答案
Pig默认情况下不输出序列文件,因此有两种选择:
hadoop fs -text /user/path/to/part-m-00000 | head
)关于hadoop - 读取BinStorage存储的数据集(从外部工具),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26637435/