kasakrisz commented on code in PR #5637:
URL: https://github.com/apache/hive/pull/5637#discussion_r2166826440


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java:
##########
@@ -1130,16 +1130,19 @@ private long evaluateComparator(Statistics stats, 
AnnotateStatsProcCtx aspCtx, E
               }
             }
           } else if (colTypeLowerCase.equals(serdeConstants.INT_TYPE_NAME) ||
-              colTypeLowerCase.equals(serdeConstants.DATE_TYPE_NAME)) {
-            int value;
+              colTypeLowerCase.equals(serdeConstants.DATE_TYPE_NAME) ||
+              colTypeLowerCase.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) {
+            long value;
             if (colTypeLowerCase.equals(serdeConstants.DATE_TYPE_NAME)) {
               DateWritable writableVal = new 
DateWritable(java.sql.Date.valueOf(boundValue));
               value = writableVal.getDays();
+            } else if 
(colTypeLowerCase.equals(serdeConstants.TIMESTAMP_TYPE_NAME)) {
+              TimestampWritableV2 timestampWritable = new 
TimestampWritableV2(Timestamp.valueOf(boundValue));
+              value = timestampWritable.getTimestamp().toEpochSecond();
             } else {
               value = Integer.parseInt(boundValue);
             }
-            // Date is an integer internally
-            int maxValue = cs.getRange().maxValue.intValue();
+            long maxValue = cs.getRange().maxValue.longValue();
             int minValue = cs.getRange().minValue.intValue();

Review Comment:
   > I don't understand how the existing column statistics could fall outside 
the defined type ranges.
   
   ```
   create table t1(cts timestamp);
   insert into table t1 values ('2040-06-25 10:00:00.000'),('2040-06-25 
20:00:00.000'),('2040-06-25 10:30:00.000');
   analyze table t1 compute statistics for columns;
   ```
   min: 2040-06-25 10:00:00.000 - epoch: 2224231200
   max: 2040-06-25 20:00:00.000 - epoch: 2224267200
   
   Both should be long because the min value `2224231200` is higher than 
`Integer.MAX_VALUE` (2147483647)
   
   Probably this is only going to be a problem in 15 years in the future. :)
   
   To avoid overflow the operands could be converted to double: 
`((double)maxValue-minValue)`
   and similarly `((double)value - minValue)`



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to