}
private int aggregateStats() {
try {
// Stats setup:
Warehouse wh = new Warehouse(conf);
FileSystem fileSys;
FileStatus[] fileStatus;
// manufacture a StatsAggregator
StatsAggregator statsAggregator;
String statsImplementationClass = HiveConf.getVar(conf, HiveConf.ConfVars.HIVESTATSDBCLASS);
StatsFactory.setImplementation(statsImplementationClass, conf);
statsAggregator = StatsFactory.getStatsAggregator();
if (!statsAggregator.connect(conf)) {
// this should not fail the whole job, return 0 so that the job won't fail.
console.printInfo("[WARNING] Could not update table/partition level stats.",
"StatsAggregator.connect() failed: stats class = " +
statsImplementationClass);
return 0;
}
TableStatistics tblStats = new TableStatistics();
//
// For partitioned table get the old table statistics for incremental update
//
if (table.isPartitioned()) {
org.apache.hadoop.hive.metastore.api.Table tTable = table.getTTable();
Map<String, String> parameters = tTable.getParameters();
if (parameters.containsKey(StatsSetupConst.ROW_COUNT)) {
tblStats.setNumRows(Long.parseLong(parameters.get(StatsSetupConst.ROW_COUNT)));
}
if (parameters.containsKey(StatsSetupConst.NUM_PARTITIONS)) {
tblStats.setNumPartitions(Integer.parseInt(parameters.get(StatsSetupConst.NUM_PARTITIONS)));
}
if (parameters.containsKey(StatsSetupConst.NUM_FILES)) {
tblStats.setNumFiles(Integer.parseInt(parameters.get(StatsSetupConst.NUM_FILES)));
}
if (parameters.containsKey(StatsSetupConst.TOTAL_SIZE)) {
tblStats.setSize(Long.parseLong(parameters.get(StatsSetupConst.TOTAL_SIZE)));
}
}
List<Partition> partitions = getPartitionsList();
if (partitions == null) {
// non-partitioned tables:
Path tablePath = wh.getDefaultTablePath(table.getDbName(), table.getTableName());
fileSys = tablePath.getFileSystem(conf);
fileStatus = Utilities.getFileStatusRecurse(tablePath, 1, fileSys);
tblStats.setNumFiles(fileStatus.length);
long tableSize = 0L;
for (int i = 0; i < fileStatus.length; i++) {