【发布时间】:2015-02-22 11:31:38
【问题描述】:
我一直在寻找解析器将生成的序列文件(.seq)转换为普通文本文件以了解中间输出。我很高兴知道是否有人遇到过如何做到这一点。
【问题讨论】:
标签: mahout sequencefile
我一直在寻找解析器将生成的序列文件(.seq)转换为普通文本文件以了解中间输出。我很高兴知道是否有人遇到过如何做到这一点。
【问题讨论】:
标签: mahout sequencefile
我认为您可以通过如下几行代码创建一个 SequenceFile Reader
public static void main(String[] args) throws IOException {
String uri = "path/to/your/sequence/file";
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
Path path = new Path(uri);
SequenceFile.Reader reader = null;
try {
reader = new SequenceFile.Reader(fs, path, conf);
Writable key = (Writable) ReflectionUtils.newInstance(
reader.getKeyClass(), conf);
Writable value = (Writable) ReflectionUtils.newInstance(
reader.getValueClass(), conf);
long position = reader.getPosition();
while (reader.next(key, value)) {
System.out.println("Key: " + key + " value:" + value);
position = reader.getPosition();
}
} finally {
reader.close();
}
}
【讨论】:
假设您在 /ex-seqdata/part-000 的 hdfs 中有序列数据... 所以part-*数据是二进制格式。 现在你可以运行命令 hadoop fs -text /ex-seqdata/part* 在命令提示符中获取人类可读格式的数据。
【讨论】: