Search in sources :

Example 1 with HCatException

use of org.apache.hive.hcatalog.common.HCatException in project hive by apache.

the class MetadataJSONSerializer method deserializeTable.

@Override
public HCatTable deserializeTable(String hcatTableStringRep) throws HCatException {
    try {
        Table table = new Table();
        new TDeserializer(new TJSONProtocol.Factory()).deserialize(table, hcatTableStringRep, "UTF-8");
        return new HCatTable(table);
    } catch (TException exception) {
        if (LOG.isDebugEnabled())
            LOG.debug("Could not de-serialize from: " + hcatTableStringRep);
        throw new HCatException("Could not de-serialize HCatTable.", exception);
    }
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) TDeserializer(org.apache.thrift.TDeserializer) HCatException(org.apache.hive.hcatalog.common.HCatException) LoggerFactory(org.slf4j.LoggerFactory)

Example 2 with HCatException

use of org.apache.hive.hcatalog.common.HCatException in project hive by apache.

the class MetadataJSONSerializer method serializePartitionSpec.

@Override
@InterfaceAudience.LimitedPrivate({ "Hive" })
@InterfaceStability.Evolving
public List<String> serializePartitionSpec(HCatPartitionSpec hcatPartitionSpec) throws HCatException {
    try {
        List<String> stringReps = new ArrayList<String>();
        TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
        for (PartitionSpec partitionSpec : hcatPartitionSpec.partitionSpecProxy.toPartitionSpec()) {
            stringReps.add(serializer.toString(partitionSpec, "UTF-8"));
        }
        return stringReps;
    } catch (TException serializationException) {
        throw new HCatException("Failed to serialize!", serializationException);
    }
}
Also used : TException(org.apache.thrift.TException) TSerializer(org.apache.thrift.TSerializer) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) ArrayList(java.util.ArrayList) HCatException(org.apache.hive.hcatalog.common.HCatException) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec)

Example 3 with HCatException

use of org.apache.hive.hcatalog.common.HCatException in project hive by apache.

the class MetadataJSONSerializer method deserializePartition.

@Override
public HCatPartition deserializePartition(String hcatPartitionStringRep) throws HCatException {
    try {
        Partition partition = new Partition();
        new TDeserializer(new TJSONProtocol.Factory()).deserialize(partition, hcatPartitionStringRep, "UTF-8");
        return new HCatPartition(null, partition);
    } catch (TException exception) {
        if (LOG.isDebugEnabled())
            LOG.debug("Could not de-serialize partition from: " + hcatPartitionStringRep);
        throw new HCatException("Could not de-serialize HCatPartition.", exception);
    }
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) TDeserializer(org.apache.thrift.TDeserializer) HCatException(org.apache.hive.hcatalog.common.HCatException) LoggerFactory(org.slf4j.LoggerFactory)

Example 4 with HCatException

use of org.apache.hive.hcatalog.common.HCatException in project hive by apache.

the class HCatClient method create.

/**
   * Creates an instance of HCatClient.
   *
   * @param conf An instance of configuration.
   * @return An instance of HCatClient.
   * @throws HCatException
   */
public static HCatClient create(Configuration conf) throws HCatException {
    HCatClient client = null;
    String className = conf.get(HCAT_CLIENT_IMPL_CLASS, HCatClientHMSImpl.class.getName());
    try {
        Class<? extends HCatClient> clientClass = Class.forName(className, true, Utilities.getSessionSpecifiedClassLoader()).asSubclass(HCatClient.class);
        client = (HCatClient) clientClass.newInstance();
    } catch (ClassNotFoundException e) {
        throw new HCatException("ClassNotFoundException while creating client class.", e);
    } catch (InstantiationException e) {
        throw new HCatException("InstantiationException while creating client class.", e);
    } catch (IllegalAccessException e) {
        throw new HCatException("IllegalAccessException while creating client class.", e);
    }
    if (client != null) {
        client.initialize(conf);
    }
    return client;
}
Also used : HCatException(org.apache.hive.hcatalog.common.HCatException)

Example 5 with HCatException

use of org.apache.hive.hcatalog.common.HCatException in project hive by apache.

the class HCatClientHMSImpl method dropPartitions.

@Override
public void dropPartitions(String dbName, String tableName, Map<String, String> partitionSpec, boolean ifExists, boolean deleteData) throws HCatException {
    LOG.info("HCatClient dropPartitions(db=" + dbName + ",table=" + tableName + ", partitionSpec: [" + partitionSpec + "]).");
    try {
        dbName = checkDB(dbName);
        Table table = hmsClient.getTable(dbName, tableName);
        if (hiveConfig.getBoolVar(HiveConf.ConfVars.METASTORE_CLIENT_DROP_PARTITIONS_WITH_EXPRESSIONS)) {
            try {
                dropPartitionsUsingExpressions(table, partitionSpec, ifExists, deleteData);
            } catch (SemanticException parseFailure) {
                LOG.warn("Could not push down partition-specification to back-end, for dropPartitions(). Resorting to iteration.", parseFailure);
                dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData);
            }
        } else {
            // Not using expressions.
            dropPartitionsIteratively(dbName, tableName, partitionSpec, ifExists, deleteData);
        }
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("NoSuchObjectException while dropping partition. " + "Either db(" + dbName + ") or table(" + tableName + ") missing.", e);
    } catch (MetaException e) {
        throw new HCatException("MetaException while dropping partition.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while dropping partition.", e);
    }
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) HCatException(org.apache.hive.hcatalog.common.HCatException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

HCatException (org.apache.hive.hcatalog.common.HCatException)52 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)20 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)19 TException (org.apache.thrift.TException)14 HCatFieldSchema (org.apache.hive.hcatalog.data.schema.HCatFieldSchema)13 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)10 Configuration (org.apache.hadoop.conf.Configuration)9 Path (org.apache.hadoop.fs.Path)9 Partition (org.apache.hadoop.hive.metastore.api.Partition)8 Table (org.apache.hadoop.hive.metastore.api.Table)8 HCatSchema (org.apache.hive.hcatalog.data.schema.HCatSchema)7 Job (org.apache.hadoop.mapreduce.Job)6 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)5 FileSystem (org.apache.hadoop.fs.FileSystem)4 HiveConf (org.apache.hadoop.hive.conf.HiveConf)4 CommandNeedRetryException (org.apache.hadoop.hive.ql.CommandNeedRetryException)4 Map (java.util.Map)3