private void publishStats() throws HiveException {
boolean isStatsReliable = conf.isStatsReliable();
// Initializing a stats publisher
StatsPublisher statsPublisher = Utilities.getStatsPublisher(jc);
if (statsPublisher == null) {
// just return, stats gathering should not block the main query
LOG.error("StatsPublishing error: StatsPublisher is not initialized.");
if (isStatsReliable) {
throw new HiveException(ErrorMsg.STATSPUBLISHER_NOT_OBTAINED.getErrorCodedMsg());
}
return;
}
if (!statsPublisher.connect(hconf)) {
// just return, stats gathering should not block the main query
LOG.error("StatsPublishing error: cannot connect to database");
if (isStatsReliable) {
throw new HiveException(ErrorMsg.STATSPUBLISHER_CONNECTION_ERROR.getErrorCodedMsg());
}
return;
}
String taskID = Utilities.getTaskIdFromFilename(Utilities.getTaskId(hconf));
String spSpec = conf.getStaticSpec() != null ? conf.getStaticSpec() : "";
for (String fspKey : valToPaths.keySet()) {
FSPaths fspValue = valToPaths.get(fspKey);
String key;
// construct the key(fileID) to insert into the intermediate stats table
if (fspKey == "") {
// for non-partitioned/static partitioned table, the key for temp storage is
// common key prefix + static partition spec + taskID
String keyPrefix = Utilities.getHashedStatsPrefix(
conf.getStatsAggPrefix() + spSpec, conf.getMaxStatsKeyPrefixLength());
key = keyPrefix + taskID;
} else {
// for partitioned table, the key is
// common key prefix + static partition spec + DynamicPartSpec + taskID
key = createKeyForStatsPublisher(taskID, spSpec, fspKey);
}
Map<String, String> statsToPublish = new HashMap<String, String>();
for (String statType : fspValue.stat.getStoredStats()) {
statsToPublish.put(statType, Long.toString(fspValue.stat.getStat(statType)));
}
if (!statsPublisher.publishStat(key, statsToPublish)) {
// The original exception is lost.
// Not changing the interface to maintain backward compatibility
if (isStatsReliable) {
throw new HiveException(ErrorMsg.STATSPUBLISHER_PUBLISHING_ERROR.getErrorCodedMsg());
}
}
}
if (!statsPublisher.closeConnection()) {
// The original exception is lost.
// Not changing the interface to maintain backward compatibility
if (isStatsReliable) {
throw new HiveException(ErrorMsg.STATSPUBLISHER_CLOSING_ERROR.getErrorCodedMsg());
}