【问题标题】:How to convert sequence file generated in mahout to text file如何将mahout中生成的序列文件转换为文本文件
【发布时间】:2015-02-22 11:31:38
【问题描述】:

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

【问题讨论】:

    标签: mahout sequencefile


    【解决方案1】:

    我认为您可以通过如下几行代码创建一个 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();
        }
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2012-08-07
        • 2014-04-03
        • 2012-06-24
        • 2012-10-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-23
        • 2021-05-03
        相关资源
        最近更新 更多