【问题标题】:Convert HDFS SequenceFile from SnappyCodec to DefaultCodec将 HDFS SequenceFile 从 SnappyCodec 转换为 DefaultCodec
【发布时间】:2013-05-03 07:01:33
【问题描述】:

如果可以选择,我会喜欢可以从 Hadoop shell 运行的东西而不是 MR 作业。我只有几个文件需要转换。

【问题讨论】:

    标签: hadoop hdfs


    【解决方案1】:

    一些未经测试但应该可以解决问题的代码(显然文件名是由组成的 - 序列文件通常没有扩展名):

    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    
    Path inputPath = new Path("part-r-00000.snappy");
    Path outputPath = new Path("part-r-00000.deflate");
    FSDataOutputStream dos = fs.create(outputPath);
    
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, inputPath,
            conf);
    Writable key = (Writable) ReflectionUtils.newInstance(
            reader.getKeyClass(), conf);
    Writable value = (Writable) ReflectionUtils.newInstance(
            reader.getValueClass(), conf);
    
    CompressionCodecFactory ccf = new CompressionCodecFactory(conf);
    CompressionCodec codec = ccf.getCodecByClassName(DefaultCodec.class
            .getName());
    SequenceFile.Writer writer = SequenceFile.createWriter(conf, dos,
            key.getClass(), value.getClass(), reader.getCompressionType(),
            codec);
    
    while (reader.next(key, value)) {
        writer.append(key, value);
    }
    
    reader.close();
    dos.close();
    

    您还应该通过 ToolRunner / Tool 模式获取配置 - 这是一个类似的问题,概述了它,以防它为您提供新的主体:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      • 2019-05-30
      • 1970-01-01
      • 2016-09-29
      • 2018-02-18
      • 1970-01-01
      相关资源
      最近更新 更多