thomasrebele commented on code in PR #6293:
URL: https://github.com/apache/hive/pull/6293#discussion_r2872733804
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java:
##########
@@ -226,43 +247,41 @@ private boolean isRemovableCast(RexNode exp,
HiveTableScan tableScan) {
return false;
}
- SqlTypeName type = cast.getType().getSqlTypeName();
- double min;
- double max;
- switch (type) {
- case TINYINT, SMALLINT, INTEGER, BIGINT:
- min = ((Number) type.getLimit(false, SqlTypeName.Limit.OVERFLOW, false,
-1, -1)).doubleValue();
- max = ((Number) type.getLimit(true, SqlTypeName.Limit.OVERFLOW, false,
-1, -1)).doubleValue();
- break;
- case TIMESTAMP, DATE:
- min = Long.MIN_VALUE;
- max = Long.MAX_VALUE;
- break;
- case FLOAT:
- min = -Float.MAX_VALUE;
- max = Float.MAX_VALUE;
- break;
- case DOUBLE, DECIMAL:
- min = -Double.MAX_VALUE;
- max = Double.MAX_VALUE;
- break;
- default:
- // unknown type, do not remove the cast
- return false;
- }
// are all values of the input column accepted by the cast?
+ double min = ((Number) targetType.getLimit(false,
SqlTypeName.Limit.OVERFLOW, false, -1, -1)).doubleValue();
+ double max = ((Number) targetType.getLimit(true,
SqlTypeName.Limit.OVERFLOW, false, -1, -1)).doubleValue();
return min < colRange.minValue.doubleValue() &&
colRange.maxValue.doubleValue() < max;
}
/**
- * Get the range of values that are rounded to valid values of a DECIMAL
type.
+ * Get the range of values that are rounded to valid values of a type.
*
- * @param type the DECIMAL type
+ * @param type the type
* @param lowerBound the lower bound type of the result
* @param upperBound the upper bound type of the result
* @return the range of the type
*/
+ private static Range<Float> getRangeOfType(RelDataType type, BoundType
lowerBound, BoundType upperBound) {
+ switch (type.getSqlTypeName()) {
+ // in case of integer types,
+ case TINYINT:
+ return Range.closed(-128.99998f, 127.99999f);
+ case SMALLINT:
+ return Range.closed(-32768.996f, 32767.998f);
+ case INTEGER:
+ return Range.closed(-2.1474836E9f, 2.1474836E9f);
+ case BIGINT, DATE, TIMESTAMP:
+ return Range.closed(-9.223372E18f, 9.223372E18f);
+ case DECIMAL:
+ return getRangeOfDecimalType(type, lowerBound, upperBound);
Review Comment:
The range depends on the precision and scale of the decimal type.
Additionally, values are rounded when CASTing them to decimal, see comment at
FilterSelectivityEstimator#getRangeOfDecimalType.
--
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]