julianhyde commented on a change in pull request #2212:
URL: https://github.com/apache/calcite/pull/2212#discussion_r504308699
##########
File path: core/src/main/java/org/apache/calcite/util/Sarg.java
##########
@@ -149,4 +150,33 @@ public boolean isComplementedPoints() {
&& rangeSet.complement().asRanges().stream()
.allMatch(RangeSets::isPoint);
}
+
+ /** Returns a measure of the complexity of this expression.
+ *
+ * <p>It is basically the number of values that need to be checked against
+ * (including NULL).
+ *
+ * <p>Examples:
+ * <ul>
+ * <li>{@code x = 1}, {@code x <> 1}, {@code x > 1} have complexity 1
+ * <li>{@code x > 1 or x is null} has complexity 2
+ * <li>{@code x in (2, 4, 6) or x > 20} has complexity 4
+ * <li>{@code x between 3 and 8 or x between 10 and 20} has complexity 2
+ * </ul>
+ */
+ public int complexity() {
+ int complexity;
+ if (rangeSet.asRanges().size() == 2
+ && rangeSet.complement().asRanges().size() == 1
+ && RangeSets.isPoint(
+ Iterables.getOnlyElement(rangeSet.complement().asRanges()))) {
Review comment:
Yeah, there aren't many comments in the code. But there are reasonable
method javadoc comments. Also a test, `testSargComplexity`. Run the test, and
all will become clear.
I moved the code so that I could add a test.
----------------------------------------------------------------
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]