Search in sources :

Example 1 with FosterStorageHandler

use of org.apache.hive.hcatalog.mapreduce.FosterStorageHandler in project hive by apache.

the class HCatUtil method getStorageHandler.

/**
   * Create an instance of a storage handler. If storageHandler == null,
   * then surrrogate StorageHandler is used to encapsulate the InputFormat, OutputFormat and SerDe.
   * This StorageHandler assumes the other supplied storage artifacts are for a file-based storage system.
   * @param conf job's configuration will be used to configure the Configurable StorageHandler
   * @param storageHandler fully qualified class name of the desired StorageHandle instance
   * @param serDe fully qualified class name of the desired SerDe instance
   * @param inputFormat fully qualified class name of the desired InputFormat instance
   * @param outputFormat fully qualified class name of the desired outputFormat instance
   * @return storageHandler instance
   * @throws IOException
   */
public static HiveStorageHandler getStorageHandler(Configuration conf, String storageHandler, String serDe, String inputFormat, String outputFormat) throws IOException {
    if ((storageHandler == null) || (storageHandler.equals(FosterStorageHandler.class.getName()))) {
        try {
            FosterStorageHandler fosterStorageHandler = new FosterStorageHandler(inputFormat, outputFormat, serDe);
            fosterStorageHandler.setConf(conf);
            return fosterStorageHandler;
        } catch (ClassNotFoundException e) {
            throw new IOException("Failed to load " + "foster storage handler", e);
        }
    }
    try {
        Class<? extends HiveStorageHandler> handlerClass = (Class<? extends HiveStorageHandler>) Class.forName(storageHandler, true, Utilities.getSessionSpecifiedClassLoader());
        return (HiveStorageHandler) ReflectionUtils.newInstance(handlerClass, conf);
    } catch (ClassNotFoundException e) {
        throw new IOException("Error in loading storage handler." + e.getMessage(), e);
    }
}
Also used : HiveStorageHandler(org.apache.hadoop.hive.ql.metadata.HiveStorageHandler) FosterStorageHandler(org.apache.hive.hcatalog.mapreduce.FosterStorageHandler) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 HiveStorageHandler (org.apache.hadoop.hive.ql.metadata.HiveStorageHandler)1 FosterStorageHandler (org.apache.hive.hcatalog.mapreduce.FosterStorageHandler)1