Search in sources :

Example 1 with HiveIgnoreKeyTextOutputFormat

use of org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat in project hive by apache.

the class Utilities method getFileExtension.

/**
   * Based on compression option, output format, and configured output codec -
   * get extension for output file. Text files require an extension, whereas
   * others, like sequence files, do not.
   * <p>
   * The property <code>hive.output.file.extension</code> is used to determine
   * the extension - if set, it will override other logic for choosing an
   * extension.
   *
   * @param jc
   *          Job Configuration
   * @param isCompressed
   *          Whether the output file is compressed or not
   * @param hiveOutputFormat
   *          The output format, used to detect if the format is text
   * @return the required file extension (example: .gz)
   */
public static String getFileExtension(JobConf jc, boolean isCompressed, HiveOutputFormat<?, ?> hiveOutputFormat) {
    String extension = HiveConf.getVar(jc, HiveConf.ConfVars.OUTPUT_FILE_EXTENSION);
    if (!StringUtils.isEmpty(extension)) {
        return extension;
    }
    if ((hiveOutputFormat instanceof HiveIgnoreKeyTextOutputFormat) && isCompressed) {
        Class<? extends CompressionCodec> codecClass = FileOutputFormat.getOutputCompressorClass(jc, DefaultCodec.class);
        CompressionCodec codec = ReflectionUtil.newInstance(codecClass, jc);
        return codec.getDefaultExtension();
    }
    return "";
}
Also used : CompressionCodec(org.apache.hadoop.io.compress.CompressionCodec) HiveIgnoreKeyTextOutputFormat(org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat)

Aggregations

HiveIgnoreKeyTextOutputFormat (org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat)1 CompressionCodec (org.apache.hadoop.io.compress.CompressionCodec)1