use of org.apache.hadoop.hive.common.ndv.NumDistinctValueEstimator in project hive by apache.
the class LongColumnStatsMerger method merge.
@Override
public void merge(ColumnStatisticsObj aggregateColStats, ColumnStatisticsObj newColStats) {
LongColumnStatsDataInspector aggregateData = (LongColumnStatsDataInspector) aggregateColStats.getStatsData().getLongStats();
LongColumnStatsDataInspector newData = (LongColumnStatsDataInspector) newColStats.getStatsData().getLongStats();
aggregateData.setLowValue(Math.min(aggregateData.getLowValue(), newData.getLowValue()));
aggregateData.setHighValue(Math.max(aggregateData.getHighValue(), newData.getHighValue()));
aggregateData.setNumNulls(aggregateData.getNumNulls() + newData.getNumNulls());
if (aggregateData.getNdvEstimator() == null || newData.getNdvEstimator() == null) {
aggregateData.setNumDVs(Math.max(aggregateData.getNumDVs(), newData.getNumDVs()));
} else {
NumDistinctValueEstimator oldEst = aggregateData.getNdvEstimator();
NumDistinctValueEstimator newEst = newData.getNdvEstimator();
long ndv = -1;
if (oldEst.canMerge(newEst)) {
oldEst.mergeEstimators(newEst);
ndv = oldEst.estimateNumDistinctValues();
aggregateData.setNdvEstimator(oldEst);
} else {
ndv = Math.max(aggregateData.getNumDVs(), newData.getNumDVs());
}
LOG.debug("Use bitvector to merge column " + aggregateColStats.getColName() + "'s ndvs of " + aggregateData.getNumDVs() + " and " + newData.getNumDVs() + " to be " + ndv);
aggregateData.setNumDVs(ndv);
}
}
Aggregations