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);
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations