1

我一直在寻找解析器将生成的序列文件(.seq)转换为普通文本文件以了解中间输出。我很高兴知道是否有人遇到过如何做到这一点。

4

2 回答 2

2

我认为您可以在几行代码中创建一个 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();
    }
}
于 2015-02-13T16:12:09.127 回答
0

假设您在 /ex-seqdata/part-000... 中的 hdfs 中有序列数据,因此 part-* 数据是二进制格式。现在您可以在命令提示符下运行命令 hadoop fs -text /ex-seqdata/part* 以获取人类可读格式的数据。

于 2015-01-05T07:16:25.963 回答