use of org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent 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();
}
}
use of org.apache.hadoop.hive.metastore.events.UpdatePartitionColumnStatEvent in project hive by apache.
the class DbNotificationListener method onUpdatePartitionColumnStatInBatch.
@Override
public void onUpdatePartitionColumnStatInBatch(UpdatePartitionColumnStatEventBatch updatePartColStatEventBatch, Connection dbConn, SQLGenerator sqlGenerator) throws MetaException {
List<NotificationEvent> eventBatch = new ArrayList<>();
List<ListenerEvent> listenerEventBatch = new ArrayList<>();
for (int i = 0; i < updatePartColStatEventBatch.getNumEntries(); i++) {
UpdatePartitionColumnStatEvent updatePartColStatEvent = updatePartColStatEventBatch.getPartColStatEvent(i);
UpdatePartitionColumnStatMessage msg = MessageBuilder.getInstance().buildUpdatePartitionColumnStatMessage(updatePartColStatEvent.getPartColStats(), updatePartColStatEvent.getPartVals(), updatePartColStatEvent.getPartParameters(), updatePartColStatEvent.getTableObj(), updatePartColStatEvent.getWriteId());
ColumnStatisticsDesc statDesc = updatePartColStatEvent.getPartColStats().getStatsDesc();
NotificationEvent event = new NotificationEvent(0, now(), EventType.UPDATE_PARTITION_COLUMN_STAT.toString(), msgEncoder.getSerializer().serialize(msg));
event.setCatName(statDesc.isSetCatName() ? statDesc.getCatName() : DEFAULT_CATALOG_NAME);
event.setDbName(statDesc.getDbName());
event.setTableName(statDesc.getTableName());
eventBatch.add(event);
listenerEventBatch.add(updatePartColStatEvent);
}
try {
addNotificationLogBatch(eventBatch, listenerEventBatch, dbConn, sqlGenerator);
} catch (SQLException e) {
throw new MetaException("Unable to execute direct SQL " + StringUtils.stringifyException(e));
}
}
Aggregations