vlsi commented on a change in pull request #2330:
URL: https://github.com/apache/calcite/pull/2330#discussion_r560953566
##########
File path: core/src/main/java/org/apache/calcite/util/RangeSets.java
##########
@@ -105,6 +110,45 @@ private RangeSets() {}
return 0;
}
+ /**
+ * Estimates the number of distinct values for a range (if possible).
+ * A null is returned if the number of distinct values is infinity or
unknown.
+ */
+ public static <C extends Comparable<C>> @Nullable Double numDistinctVals(
+ Range<C> range, RelDataType type) {
+ if (RangeSets.isPoint(range)) {
+ return 1.0;
+ }
+ if (!range.hasLowerBound() || !range.hasUpperBound()) {
+ // infinity range.
+ return null;
+ }
+ C lower = range.lowerEndpoint();
+ C upper = range.upperEndpoint();
+
+ if (lower instanceof Number && upper instanceof Number) {
+ Number lowerNum = (Number) lower;
+ Number upperNum = (Number) upper;
+
+ boolean discreteType = type.getSqlTypeName() ==
SqlTypeName.BOOLEAN.BOOLEAN
Review comment:
Is `.BOOLEAN.BOOLEAN` expected here?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]