Search in sources :

Example 6 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 7 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 8 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 9 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)

Example 10 with HCatException

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

the class HCatClientHMSImpl method listPartitionsByFilter.

@Override
public List<HCatPartition> listPartitionsByFilter(String dbName, String tblName, String filter) throws HCatException {
    List<HCatPartition> hcatPtns = new ArrayList<HCatPartition>();
    try {
        HCatTable table = getTable(dbName, tblName);
        List<Partition> hivePtns = hmsClient.listPartitionsByFilter(table.getDbName(), table.getTableName(), filter, (short) -1);
        for (Partition ptn : hivePtns) {
            hcatPtns.add(new HCatPartition(table, ptn));
        }
    } catch (MetaException e) {
        throw new HCatException("MetaException while fetching partitions.", e);
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("NoSuchObjectException while fetching partitions.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while fetching partitions.", e);
    }
    return hcatPtns;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) ArrayList(java.util.ArrayList) HCatException(org.apache.hive.hcatalog.common.HCatException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) 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 HCatRecord (org.apache.hive.hcatalog.data.HCatRecord)4 Map (java.util.Map)3