use of org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEventBatch in project hive by apache.
the class DirectSqlUpdateStat method updatePartitionColumnStatistics.
/**
* Update the statistics for the given partitions. Add the notification logs also.
* @return map of partition key to column stats if successful, null otherwise.
*/
public Map<String, Map<String, String>> updatePartitionColumnStatistics(Map<String, ColumnStatistics> partColStatsMap, Table tbl, long csId, String validWriteIds, long writeId, List<TransactionalMetaStoreEventListener> transactionalListeners) throws MetaException {
JDOConnection jdoConn = null;
Connection dbConn = null;
boolean committed = false;
try {
lockInternal();
jdoConn = pm.getDataStoreConnection();
dbConn = (Connection) (jdoConn.getNativeConnection());
setAnsiQuotes(dbConn);
Map<PartitionInfo, ColumnStatistics> partitionInfoMap = getPartitionInfo(dbConn, tbl.getId(), partColStatsMap);
Map<String, Map<String, String>> result = updatePartitionParamTable(dbConn, partitionInfoMap, validWriteIds, writeId, TxnUtils.isAcidTable(tbl));
Map<PartColNameInfo, MPartitionColumnStatistics> insertMap = new HashMap<>();
Map<PartColNameInfo, MPartitionColumnStatistics> updateMap = new HashMap<>();
populateInsertUpdateMap(partitionInfoMap, updateMap, insertMap, dbConn);
LOG.info("Number of stats to insert " + insertMap.size() + " update " + updateMap.size());
if (insertMap.size() != 0) {
insertIntoPartColStatTable(insertMap, csId, dbConn);
}
if (updateMap.size() != 0) {
updatePartColStatTable(updateMap, dbConn);
}
if (transactionalListeners != null) {
UpdatePartitionColumnStatEventBatch eventBatch = new UpdatePartitionColumnStatEventBatch(null);
for (Map.Entry entry : result.entrySet()) {
Map<String, String> parameters = (Map<String, String>) entry.getValue();
ColumnStatistics colStats = partColStatsMap.get(entry.getKey());
List<String> partVals = getPartValsFromName(tbl, colStats.getStatsDesc().getPartName());
UpdatePartitionColumnStatEvent event = new UpdatePartitionColumnStatEvent(colStats, partVals, parameters, tbl, writeId, null);
eventBatch.addPartColStatEvent(event);
}
MetaStoreListenerNotifier.notifyEventWithDirectSql(transactionalListeners, EventMessage.EventType.UPDATE_PARTITION_COLUMN_STAT_BATCH, eventBatch, dbConn, sqlGenerator);
}
dbConn.commit();
committed = true;
return result;
} catch (Exception e) {
LOG.error("Unable to update Column stats for " + tbl.getTableName(), e);
throw new MetaException("Unable to update Column stats for " + tbl.getTableName() + " due to: " + e.getMessage());
} finally {
if (!committed) {
rollbackDBConn(dbConn);
}
closeDbConn(jdoConn);
unlockInternal();
}
}
Aggregations