在Hadoop程序中,我尝试压缩结果,我编写了以下代码:

FileOutputFormat.setCompressOutput(job, true);
FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);

结果被压缩,当我删除第一行时:
FileOutputFormat.setCompressOutput(job, true);

然后再次执行该程序,结果是上面的代码



可选的?该代码的功能是什么?

最佳答案

请在FileOutPutFormat.java中查看以下方法,该方法内部调用您已删除的方法调用。



这意味着您正在尝试应用Gzip编解码器类,然后显然是其指针,该指针指向应压缩输出的代码。是不是

/**
   * Set whether the output of the job is compressed.
   * @param conf the {@link JobConf} to modify
   * @param compress should the output of the job be compressed?
   */
  public static void setCompressOutput(JobConf conf, boolean compress) {
    conf.setBoolean("mapred.output.compress", compress);
  }
  /**
   * Set the {@link CompressionCodec} to be used to compress job outputs.
   * @param conf the {@link JobConf} to modify
   * @param codecClass the {@link CompressionCodec} to be used to
   *                   compress the job outputs
   */
  public static void
  setOutputCompressorClass(JobConf conf,
                           Class<? extends CompressionCodec> codecClass) {
    setCompressOutput(conf, true);
    conf.setClass("mapred.output.compression.codec", codecClass,
                  CompressionCodec.class);
  }

关于hadoop - 是FileOutputFormat.setCompressOutput(job,true);可选的?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37474967/

10-09 09:19