Search in sources :

Example 1 with HiveStorageFormat

use of io.trino.plugin.hive.HiveStorageFormat in project trino by trinodb.

the class HiveUtil method getInputFormat.

public static InputFormat<?, ?> getInputFormat(Configuration configuration, Properties schema, boolean symlinkTarget) {
    String inputFormatName = getInputFormatName(schema);
    try {
        JobConf jobConf = toJobConf(configuration);
        configureCompressionCodecs(jobConf);
        Class<? extends InputFormat<?, ?>> inputFormatClass = getInputFormatClass(jobConf, inputFormatName);
        if (symlinkTarget && inputFormatClass == SymlinkTextInputFormat.class) {
            String serde = getDeserializerClassName(schema);
            // per Hive spec (https://hive.apache.org/javadocs/r2.1.1/api/org/apache/hadoop/hive/ql/io/SymlinkTextInputFormat.html)
            if (serde.equals(TEXTFILE.getSerde())) {
                inputFormatClass = getInputFormatClass(jobConf, TEXTFILE.getInputFormat());
                return ReflectionUtils.newInstance(inputFormatClass, jobConf);
            }
            for (HiveStorageFormat format : HiveStorageFormat.values()) {
                if (serde.equals(format.getSerde())) {
                    inputFormatClass = getInputFormatClass(jobConf, format.getInputFormat());
                    return ReflectionUtils.newInstance(inputFormatClass, jobConf);
                }
            }
            throw new TrinoException(HIVE_UNSUPPORTED_FORMAT, "Unknown SerDe for SymlinkTextInputFormat: " + serde);
        }
        return ReflectionUtils.newInstance(inputFormatClass, jobConf);
    } catch (ClassNotFoundException | RuntimeException e) {
        throw new TrinoException(HIVE_UNSUPPORTED_FORMAT, "Unable to create input format " + inputFormatName, e);
    }
}
Also used : HiveStorageFormat(io.trino.plugin.hive.HiveStorageFormat) TrinoException(io.trino.spi.TrinoException) ConfigurationUtils.toJobConf(io.trino.plugin.hive.util.ConfigurationUtils.toJobConf) JobConf(org.apache.hadoop.mapred.JobConf) SymlinkTextInputFormat(org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat)

Aggregations

HiveStorageFormat (io.trino.plugin.hive.HiveStorageFormat)1 ConfigurationUtils.toJobConf (io.trino.plugin.hive.util.ConfigurationUtils.toJobConf)1 TrinoException (io.trino.spi.TrinoException)1 SymlinkTextInputFormat (org.apache.hadoop.hive.ql.io.SymlinkTextInputFormat)1 JobConf (org.apache.hadoop.mapred.JobConf)1