Search in sources :

Example 31 with HCatException

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

the class HCatClientHMSImpl method updateTableSchema.

@Override
public void updateTableSchema(String dbName, String tableName, List<HCatFieldSchema> columnSchema) throws HCatException {
    try {
        Table table = hmsClient.getTable(dbName, tableName);
        table.getSd().setCols(HCatSchemaUtils.getFieldSchemas(columnSchema));
        hmsClient.alter_table(dbName, tableName, table);
    } catch (InvalidOperationException e) {
        throw new HCatException("InvalidOperationException while updating table schema.", e);
    } catch (MetaException e) {
        throw new HCatException("MetaException while updating table schema.", e);
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("NoSuchObjectException while updating table schema.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while updating table schema.", e);
    }
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) HCatException(org.apache.hive.hcatalog.common.HCatException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 32 with HCatException

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

the class HCatClientHMSImpl method getPartition.

@Override
public HCatPartition getPartition(String dbName, String tableName, Map<String, String> partitionSpec) throws HCatException {
    HCatPartition partition = null;
    try {
        HCatTable hcatTable = getTable(dbName, tableName);
        List<HCatFieldSchema> partitionColumns = hcatTable.getPartCols();
        if (partitionColumns.size() != partitionSpec.size()) {
            throw new HCatException("Partition-spec doesn't have the right number of partition keys.");
        }
        ArrayList<String> ptnValues = new ArrayList<String>();
        for (HCatFieldSchema partitionColumn : partitionColumns) {
            String partKey = partitionColumn.getName();
            if (partitionSpec.containsKey(partKey)) {
                // Partition-keys added in order.
                ptnValues.add(partitionSpec.get(partKey));
            } else {
                throw new HCatException("Invalid partition-key specified: " + partKey);
            }
        }
        Partition hivePartition = hmsClient.getPartition(checkDB(dbName), tableName, ptnValues);
        if (hivePartition != null) {
            partition = new HCatPartition(hcatTable, hivePartition);
        }
    } catch (MetaException e) {
        throw new HCatException("MetaException while retrieving partition.", e);
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("NoSuchObjectException while retrieving partition.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while retrieving partition.", e);
    }
    return partition;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) HCatException(org.apache.hive.hcatalog.common.HCatException) ArrayList(java.util.ArrayList) HCatFieldSchema(org.apache.hive.hcatalog.data.schema.HCatFieldSchema) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 33 with HCatException

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

the class HCatClientHMSImpl method addPartitions.

/*
   * @param partInfoList
   *  @return The size of the list of partitions.
   * @throws HCatException,ConnectionFailureException
   * @see org.apache.hive.hcatalog.api.HCatClient#addPartitions(java.util.List)
   */
@Override
public int addPartitions(List<HCatAddPartitionDesc> partInfoList) throws HCatException {
    int numPartitions = -1;
    if ((partInfoList == null) || (partInfoList.size() == 0)) {
        throw new HCatException("The partition list is null or empty.");
    }
    Table tbl = null;
    try {
        tbl = hmsClient.getTable(partInfoList.get(0).getDatabaseName(), partInfoList.get(0).getTableName());
        HCatTable hcatTable = new HCatTable(tbl);
        ArrayList<Partition> ptnList = new ArrayList<Partition>();
        for (HCatAddPartitionDesc desc : partInfoList) {
            HCatPartition hCatPartition = desc.getHCatPartition();
            // This is required only to support the deprecated HCatAddPartitionDesc.Builder interfaces.
            if (hCatPartition == null) {
                hCatPartition = desc.getHCatPartition(hcatTable);
            }
            ptnList.add(hCatPartition.toHivePartition());
        }
        numPartitions = hmsClient.add_partitions(ptnList);
    } catch (InvalidObjectException e) {
        throw new HCatException("InvalidObjectException while adding partition.", e);
    } catch (AlreadyExistsException e) {
        throw new HCatException("AlreadyExistsException while adding partition.", e);
    } catch (MetaException e) {
        throw new HCatException("MetaException while adding partition.", e);
    } catch (NoSuchObjectException e) {
        throw new ObjectNotFoundException("The table " + partInfoList.get(0).getTableName() + " is could not be found.", e);
    } catch (TException e) {
        throw new ConnectionFailureException("TException while adding partition.", e);
    }
    return numPartitions;
}
Also used : TException(org.apache.thrift.TException) Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) HCatException(org.apache.hive.hcatalog.common.HCatException) ArrayList(java.util.ArrayList) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 34 with HCatException

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

the class HCatClientHMSImpl method initialize.

/*
   * @param conf /* @throws HCatException,ConnectionFailureException
   *
   * @see
   * org.apache.hive.hcatalog.api.HCatClient#initialize(org.apache.hadoop.conf.
   * Configuration)
   */
@Override
void initialize(Configuration conf) throws HCatException {
    this.config = conf;
    try {
        hiveConfig = HCatUtil.getHiveConf(config);
        hmsClient = HCatUtil.getHiveMetastoreClient(hiveConfig);
    } catch (MetaException exp) {
        throw new HCatException("MetaException while creating HMS client", exp);
    } catch (IOException exp) {
        throw new HCatException("IOException while creating HMS client", exp);
    }
}
Also used : HCatException(org.apache.hive.hcatalog.common.HCatException) IOException(java.io.IOException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 35 with HCatException

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

the class HCatClientHMSImpl method getHiveTableLike.

private Table getHiveTableLike(String dbName, String existingTblName, String newTableName, boolean isExternal, String location) throws HCatException {
    Table oldtbl = null;
    Table newTable = null;
    try {
        oldtbl = hmsClient.getTable(checkDB(dbName), existingTblName);
    } catch (MetaException e1) {
        throw new HCatException("MetaException while retrieving existing table.", e1);
    } catch (NoSuchObjectException e1) {
        throw new ObjectNotFoundException("NoSuchObjectException while retrieving existing table.", e1);
    } catch (TException e1) {
        throw new ConnectionFailureException("TException while retrieving existing table.", e1);
    }
    if (oldtbl != null) {
        newTable = new Table();
        newTable.setTableName(newTableName);
        newTable.setDbName(dbName);
        StorageDescriptor sd = new StorageDescriptor(oldtbl.getSd());
        newTable.setSd(sd);
        newTable.setParameters(oldtbl.getParameters());
        if (location == null) {
            newTable.getSd().setLocation(oldtbl.getSd().getLocation());
        } else {
            newTable.getSd().setLocation(location);
        }
        if (isExternal) {
            newTable.putToParameters("EXTERNAL", "TRUE");
            newTable.setTableType(TableType.EXTERNAL_TABLE.toString());
        } else {
            newTable.getParameters().remove("EXTERNAL");
        }
        // set create time
        newTable.setCreateTime((int) (System.currentTimeMillis() / 1000));
        newTable.setLastAccessTimeIsSet(false);
    }
    return newTable;
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hive.metastore.api.Table) HCatException(org.apache.hive.hcatalog.common.HCatException) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) 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