thomasrebele commented on code in PR #6505:
URL: https://github.com/apache/hive/pull/6505#discussion_r4681299741


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java:
##########
@@ -1519,14 +1537,12 @@ public Object process(Node nd, Stack<Node> stack, 
NodeProcessorCtx procCtx,
         // compute product of distinct values of grouping columns
         long ndvProduct =
             StatsUtils.computeNDVGroupingColumns(colStats, parentStats, false);
-        // if ndvProduct is 0 then column stats state must be partial and we 
are missing
-        // column stats for a group by column
-        if (ndvProduct == 0) {
+        if (ndvProduct < 0) {

Review Comment:
   The ndvProduct is calculated by computeNDVGroupingColumns which calls 
StatsUtils#safeMult, but the latter only handles positive saturation correctly.
   
   ```
   long a = Integer.MIN_VALUE;
   long b = 2000L * Integer.MAX_VALUE;
   System.out.println(a + " * " + b + " = " + StatsUtils.safeMult(a, b) + " ?");
   ```
   prints
   ```
   -2147483648 * 4294967294000 = 9223372036854775807 ?
   ```
   
   I think StatsUtils#safeMult should use LongMath.saturatedMultiply instead of 
catching the exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to