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 StringUtils.EMPTY;
  }
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)
ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java