Search in sources :

Example 1 with StorageHandlerInfo

use of org.apache.hadoop.hive.ql.metadata.StorageHandlerInfo in project hive by apache.

the class KafkaStorageHandler method getStorageHandlerInfo.

@Override
public StorageHandlerInfo getStorageHandlerInfo(Table table) throws MetaException {
    String topic = table.getParameters().get(KafkaTableProperties.HIVE_KAFKA_TOPIC.getName());
    if (topic == null || topic.isEmpty()) {
        throw new MetaException("topic is null or empty");
    }
    String brokers = table.getParameters().get(KafkaTableProperties.HIVE_KAFKA_BOOTSTRAP_SERVERS.getName());
    if (brokers == null || brokers.isEmpty()) {
        throw new MetaException("kafka brokers string is null or empty");
    }
    final Properties properties = new Properties();
    properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteArrayDeserializer.class.getName());
    properties.setProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, brokers);
    properties.setProperty(CommonClientConfigs.CLIENT_ID_CONFIG, Utilities.getTaskId(getConf()));
    if (UserGroupInformation.isSecurityEnabled()) {
        KafkaUtils.addKerberosJaasConf(getConf(), properties);
    }
    table.getParameters().entrySet().stream().filter(objectObjectEntry -> objectObjectEntry.getKey().toLowerCase().startsWith(KafkaUtils.CONSUMER_CONFIGURATION_PREFIX)).forEach(entry -> {
        String key = entry.getKey().substring(KafkaUtils.CONSUMER_CONFIGURATION_PREFIX.length() + 1);
        if (KafkaUtils.FORBIDDEN_PROPERTIES.contains(key)) {
            throw new IllegalArgumentException("Not suppose to set Kafka Property " + key);
        }
        properties.put(key, entry.getValue());
    });
    return new KafkaStorageHandlerInfo(topic, properties);
}
Also used : LockType(org.apache.hadoop.hive.metastore.api.LockType) Arrays(java.util.Arrays) TableDesc(org.apache.hadoop.hive.ql.plan.TableDesc) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) FileSystem(org.apache.hadoop.fs.FileSystem) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) AbstractSerDe(org.apache.hadoop.hive.serde2.AbstractSerDe) Utilities(org.apache.hadoop.hive.ql.exec.Utilities) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) ByteArraySerializer(org.apache.kafka.common.serialization.ByteArraySerializer) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) InputFormat(org.apache.hadoop.mapred.InputFormat) Path(org.apache.hadoop.fs.Path) URI(java.net.URI) HiveStorageHandler(org.apache.hadoop.hive.ql.metadata.HiveStorageHandler) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) OutputFormat(org.apache.hadoop.mapred.OutputFormat) CommonClientConfigs(org.apache.kafka.clients.CommonClientConfigs) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) DefaultHiveAuthorizationProvider(org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider) Logger(org.slf4j.Logger) Properties(java.util.Properties) ImmutableMap(com.google.common.collect.ImmutableMap) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) Predicate(java.util.function.Predicate) HiveConf(org.apache.hadoop.hive.conf.HiveConf) HiveMetaHook(org.apache.hadoop.hive.metastore.HiveMetaHook) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) IOException(java.io.IOException) DefaultHiveMetaHook(org.apache.hadoop.hive.metastore.DefaultHiveMetaHook) Table(org.apache.hadoop.hive.metastore.api.Table) StorageHandlerInfo(org.apache.hadoop.hive.ql.metadata.StorageHandlerInfo) JobConf(org.apache.hadoop.mapred.JobConf) TimeUnit(java.util.concurrent.TimeUnit) HiveCustomStorageHandlerUtils(org.apache.hadoop.hive.ql.security.authorization.HiveCustomStorageHandlerUtils) ProducerFencedException(org.apache.kafka.common.errors.ProducerFencedException) TableType(org.apache.hadoop.hive.metastore.TableType) Preconditions(com.google.common.base.Preconditions) HiveAuthorizationProvider(org.apache.hadoop.hive.ql.security.authorization.HiveAuthorizationProvider) Properties(java.util.Properties) ByteArrayDeserializer(org.apache.kafka.common.serialization.ByteArrayDeserializer) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 Predicate (java.util.function.Predicate)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 DefaultHiveMetaHook (org.apache.hadoop.hive.metastore.DefaultHiveMetaHook)1 HiveMetaHook (org.apache.hadoop.hive.metastore.HiveMetaHook)1