thomasrebele commented on code in PR #6293:
URL: https://github.com/apache/hive/pull/6293#discussion_r2872824790
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java:
##########
@@ -218,6 +218,27 @@ private boolean isRemovableCast(RexNode exp, HiveTableScan
tableScan) {
return false;
}
+ SqlTypeName targetType = cast.getType().getSqlTypeName();
+ SqlTypeName sourceType = op0.getType().getSqlTypeName();
+
+ switch (sourceType) {
+ case TINYINT, SMALLINT, INTEGER, BIGINT:
+ // additional checks are needed
+ break;
+ case FLOAT, DOUBLE, DECIMAL, TIMESTAMP, DATE:
+ return true;
+ default:
+ // unknown type, do not remove the cast
+ return false;
+ }
+
+ // If the source type is completely within the target type, the cast is
lossless
+ Range<Float> targetRange = getRangeOfType(cast.getType(),
BoundType.CLOSED, BoundType.CLOSED);
+ Range<Float> sourceRange = getRangeOfType(op0.getType(), BoundType.CLOSED,
BoundType.CLOSED);
+ if (sourceRange.equals(targetRange.intersection(sourceRange))) {
+ return true;
+ }
Review Comment:
Indeed, I did not expect that the intersection will throw an exception. I've
replaced it with the `encloses` method which does not throw.
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/stats/FilterSelectivityEstimator.java:
##########
@@ -218,6 +218,27 @@ private boolean isRemovableCast(RexNode exp, HiveTableScan
tableScan) {
return false;
}
+ SqlTypeName targetType = cast.getType().getSqlTypeName();
+ SqlTypeName sourceType = op0.getType().getSqlTypeName();
+
+ switch (sourceType) {
+ case TINYINT, SMALLINT, INTEGER, BIGINT:
+ // additional checks are needed
+ break;
+ case FLOAT, DOUBLE, DECIMAL, TIMESTAMP, DATE:
+ return true;
+ default:
+ // unknown type, do not remove the cast
+ return false;
+ }
+
+ // If the source type is completely within the target type, the cast is
lossless
+ Range<Float> targetRange = getRangeOfType(cast.getType(),
BoundType.CLOSED, BoundType.CLOSED);
+ Range<Float> sourceRange = getRangeOfType(op0.getType(), BoundType.CLOSED,
BoundType.CLOSED);
+ if (sourceRange.equals(targetRange.intersection(sourceRange))) {
+ return true;
+ }
Review Comment:
Indeed, I did not expect that the intersection will throw an exception. I'll
replace it with the `encloses` method which does not throw.
--
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]