diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java index 069f7ae..9c851fd 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java @@ -1099,6 +1099,10 @@ public static NodeProcessor getDefaultRule() { */ static void updateStats(Statistics stats, long newNumRows, boolean useColStats) { long oldRowCount = stats.getNumRows(); + if (oldRowCount == 0) { + // there is nothing to update + return; + } double ratio = (double) newNumRows / (double) oldRowCount; stats.setNumRows(newNumRows); @@ -1115,7 +1119,7 @@ static void updateStats(Statistics stats, long newNumRows, boolean useColStats) // number of distincts should not change. Update the distinct count only when // the output number of rows is less than input number of rows. if (ratio <= 1.0) { - newDV = Math.round(ratio * oldDV); + newDV = (long) Math.ceil(ratio * oldDV); } cs.setNumNulls(newNumNulls); cs.setCountDistint(newDV);