Search in sources :

Example 1 with HiveConfFactory

use of org.apache.gobblin.hive.HiveConfFactory in project incubator-gobblin by apache.

the class HiveMetaStoreUtils method getDeserializer.

/**
 * Returns a Deserializer from HiveRegistrationUnit if present and successfully initialized. Else returns null.
 */
private static Deserializer getDeserializer(HiveRegistrationUnit unit) {
    Optional<String> serdeClass = unit.getSerDeType();
    if (!serdeClass.isPresent()) {
        return null;
    }
    String serde = serdeClass.get();
    HiveConf hiveConf;
    Deserializer deserializer;
    try {
        hiveConf = SharedResourcesBrokerFactory.getImplicitBroker().getSharedResource(new HiveConfFactory<>(), SharedHiveConfKey.INSTANCE);
        deserializer = ReflectionUtils.newInstance(hiveConf.getClassByName(serde).asSubclass(Deserializer.class), hiveConf);
    } catch (ClassNotFoundException e) {
        LOG.warn("Serde class " + serde + " not found!", e);
        return null;
    } catch (NotConfiguredException nce) {
        LOG.error("Implicit broker is not configured properly", nce);
        return null;
    }
    Properties props = new Properties();
    props.putAll(unit.getProps().getProperties());
    props.putAll(unit.getStorageProps().getProperties());
    props.putAll(unit.getSerDeProps().getProperties());
    try {
        SerDeUtils.initializeSerDe(deserializer, hiveConf, props, null);
        // handling in AvroSerDe added in HIVE-7868.
        if (deserializer instanceof AvroSerDe) {
            try {
                inVokeDetermineSchemaOrThrowExceptionMethod(props, new Configuration());
            } catch (SchemaParseException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
                LOG.warn("Failed to initialize AvroSerDe.");
                throw new SerDeException(e);
            }
        }
    } catch (SerDeException e) {
        LOG.warn("Failed to initialize serde " + serde + " with properties " + props + " for table " + unit.getDbName() + "." + unit.getTableName());
        return null;
    }
    return deserializer;
}
Also used : NotConfiguredException(org.apache.gobblin.broker.iface.NotConfiguredException) Configuration(org.apache.hadoop.conf.Configuration) HiveConfFactory(org.apache.gobblin.hive.HiveConfFactory) Properties(java.util.Properties) InvocationTargetException(java.lang.reflect.InvocationTargetException) AvroSerDe(org.apache.hadoop.hive.serde2.avro.AvroSerDe) Deserializer(org.apache.hadoop.hive.serde2.Deserializer) SchemaParseException(org.apache.avro.SchemaParseException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) SerDeException(org.apache.hadoop.hive.serde2.SerDeException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Properties (java.util.Properties)1 SchemaParseException (org.apache.avro.SchemaParseException)1 NotConfiguredException (org.apache.gobblin.broker.iface.NotConfiguredException)1 HiveConfFactory (org.apache.gobblin.hive.HiveConfFactory)1 Configuration (org.apache.hadoop.conf.Configuration)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 Deserializer (org.apache.hadoop.hive.serde2.Deserializer)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 AvroSerDe (org.apache.hadoop.hive.serde2.avro.AvroSerDe)1