use of org.apache.hadoop.hive.metastore.api.Partition in project hive by apache.
the class TestHiveMetaStore method adjust.
private static void adjust(HiveMetaStoreClient client, Partition part, String dbName, String tblName) throws TException {
Partition part_get = client.getPartition(dbName, tblName, part.getValues());
part.setCreateTime(part_get.getCreateTime());
part.putToParameters(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.DDL_TIME, Long.toString(part_get.getCreateTime()));
}
use of org.apache.hadoop.hive.metastore.api.Partition in project hive by apache.
the class HiveAlterHandler method alterPartitions.
@Override
public List<Partition> alterPartitions(final RawStore msdb, Warehouse wh, final String dbname, final String name, final List<Partition> new_parts, EnvironmentContext environmentContext, IHMSHandler handler) throws InvalidOperationException, InvalidObjectException, AlreadyExistsException, MetaException {
List<Partition> oldParts = new ArrayList<>();
List<List<String>> partValsList = new ArrayList<>();
List<TransactionalMetaStoreEventListener> transactionalListeners = null;
if (handler != null) {
transactionalListeners = handler.getTransactionalListeners();
}
boolean success = false;
try {
msdb.openTransaction();
Table tbl = msdb.getTable(dbname, name);
if (tbl == null) {
throw new InvalidObjectException("Unable to alter partitions because table or database does not exist.");
}
for (Partition tmpPart : new_parts) {
// Set DDL time to now if not specified
if (tmpPart.getParameters() == null || tmpPart.getParameters().get(hive_metastoreConstants.DDL_TIME) == null || Integer.parseInt(tmpPart.getParameters().get(hive_metastoreConstants.DDL_TIME)) == 0) {
tmpPart.putToParameters(hive_metastoreConstants.DDL_TIME, Long.toString(System.currentTimeMillis() / 1000));
}
Partition oldTmpPart = msdb.getPartition(dbname, name, tmpPart.getValues());
oldParts.add(oldTmpPart);
partValsList.add(tmpPart.getValues());
if (MetaStoreUtils.requireCalStats(oldTmpPart, tmpPart, tbl, environmentContext)) {
// Check if stats are same, no need to update
if (MetaStoreUtils.isFastStatsSame(oldTmpPart, tmpPart)) {
MetaStoreUtils.updateBasicState(environmentContext, tmpPart.getParameters());
} else {
MetaStoreUtils.updatePartitionStatsFast(tmpPart, tbl, wh, false, true, environmentContext, false);
}
}
// PartitionView does not have SD and we do not need to update its column stats
if (oldTmpPart.getSd() != null) {
updateOrGetPartitionColumnStats(msdb, dbname, name, oldTmpPart.getValues(), oldTmpPart.getSd().getCols(), tbl, tmpPart, null);
}
}
msdb.alterPartitions(dbname, name, partValsList, new_parts);
Iterator<Partition> oldPartsIt = oldParts.iterator();
for (Partition newPart : new_parts) {
Partition oldPart;
if (oldPartsIt.hasNext()) {
oldPart = oldPartsIt.next();
} else {
throw new InvalidOperationException("Missing old partition corresponding to new partition " + "when invoking MetaStoreEventListener for alterPartitions event.");
}
if (transactionalListeners != null && !transactionalListeners.isEmpty()) {
MetaStoreListenerNotifier.notifyEvent(transactionalListeners, EventMessage.EventType.ALTER_PARTITION, new AlterPartitionEvent(oldPart, newPart, tbl, false, true, handler));
}
}
success = msdb.commitTransaction();
} catch (InvalidObjectException | NoSuchObjectException e) {
throw new InvalidOperationException("Alter partition operation failed: " + e);
} finally {
if (!success) {
msdb.rollbackTransaction();
}
}
return oldParts;
}
use of org.apache.hadoop.hive.metastore.api.Partition in project incubator-gobblin by apache.
the class HiveConvertPublisher method getPartitionObject.
@VisibleForTesting
public Optional<Partition> getPartitionObject(String completePartitionName) {
try (AutoReturnableObject<IMetaStoreClient> client = pool.getClient()) {
List<String> partitionList = At_SPLITTER.splitToList(completePartitionName);
if (partitionList.size() != 3) {
log.warn("Invalid partition name " + completePartitionName);
return Optional.<Partition>absent();
}
Partition sourcePartition = client.get().getPartition(partitionList.get(0), partitionList.get(1), partitionList.get(2));
return Optional.fromNullable(sourcePartition);
} catch (IOException | TException e) {
log.warn("Unable to get partition object from metastore for partition " + completePartitionName);
}
return Optional.<Partition>absent();
}
use of org.apache.hadoop.hive.metastore.api.Partition in project incubator-gobblin by apache.
the class HiveMetaStoreBasedRegister method getPartitionWithCreateTime.
/**
* Sets create time if not already set.
*/
private Partition getPartitionWithCreateTime(Partition partition, int createTime) {
if (partition.isSetCreateTime() && partition.getCreateTime() > 0) {
return partition;
}
Partition actualPartition = partition.deepCopy();
actualPartition.setCreateTime(createTime);
return actualPartition;
}
use of org.apache.hadoop.hive.metastore.api.Partition in project incubator-gobblin by apache.
the class HiveMetaStoreUtils method getPartition.
/**
* Convert a {@link HivePartition} into a {@link Partition}.
*/
public static Partition getPartition(HivePartition hivePartition) {
State props = hivePartition.getProps();
Partition partition = new Partition();
partition.setDbName(hivePartition.getDbName());
partition.setTableName(hivePartition.getTableName());
partition.setValues(hivePartition.getValues());
partition.setParameters(getParameters(props));
if (hivePartition.getCreateTime().isPresent()) {
partition.setCreateTime(Ints.checkedCast(hivePartition.getCreateTime().get()));
} else if (props.contains(HiveConstants.CREATE_TIME)) {
partition.setCreateTime(props.getPropAsInt(HiveConstants.CREATE_TIME));
}
if (props.contains(HiveConstants.LAST_ACCESS_TIME)) {
partition.setLastAccessTime(props.getPropAsInt(HiveConstants.LAST_ACCESS_TIME));
}
partition.setSd(getStorageDescriptor(hivePartition));
return partition;
}
Aggregations