From b7e9f5bc852f516e1ab1ce80b09572e7b473b277 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Fri, 19 Feb 2021 16:44:56 -0800 Subject: [PATCH] BoundDimFilter: Simplify the various DruidLongPredicates. (#10906) They all use Long.compare, but they don't need to. Changing to regular comparisons simplifies the code and also removes branches. (Internally, Long.compare has two branches.) --- .../druid/query/filter/BoundDimFilter.java | 84 ++----------------- 1 file changed, 8 insertions(+), 76 deletions(-) diff --git a/processing/src/main/java/org/apache/druid/query/filter/BoundDimFilter.java b/processing/src/main/java/org/apache/druid/query/filter/BoundDimFilter.java index 4b6fc879968..51ce29378a0 100644 --- a/processing/src/main/java/org/apache/druid/query/filter/BoundDimFilter.java +++ b/processing/src/main/java/org/apache/druid/query/filter/BoundDimFilter.java @@ -615,93 +615,25 @@ public class BoundDimFilter extends AbstractOptimizableDimFilter implements DimF { if (hasLowerLongBound && hasUpperLongBound) { if (upperStrict && lowerStrict) { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int lowerComparing = Long.compare(input, lowerLongBound); - final int upperComparing = Long.compare(upperLongBound, input); - return ((lowerComparing > 0)) && (upperComparing > 0); - } - }; + return input -> input > lowerLongBound && input < upperLongBound; } else if (lowerStrict) { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int lowerComparing = Long.compare(input, lowerLongBound); - final int upperComparing = Long.compare(upperLongBound, input); - return (lowerComparing > 0) && (upperComparing >= 0); - } - }; + return input -> input > lowerLongBound && input <= upperLongBound; } else if (upperStrict) { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int lowerComparing = Long.compare(input, lowerLongBound); - final int upperComparing = Long.compare(upperLongBound, input); - return (lowerComparing >= 0) && (upperComparing > 0); - } - }; + return input -> input >= lowerLongBound && input < upperLongBound; } else { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int lowerComparing = Long.compare(input, lowerLongBound); - final int upperComparing = Long.compare(upperLongBound, input); - return (lowerComparing >= 0) && (upperComparing >= 0); - } - }; + return input -> input >= lowerLongBound && input <= upperLongBound; } } else if (hasUpperLongBound) { if (upperStrict) { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int upperComparing = Long.compare(upperLongBound, input); - return upperComparing > 0; - } - }; + return input -> input < upperLongBound; } else { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int upperComparing = Long.compare(upperLongBound, input); - return upperComparing >= 0; - } - }; + return input -> input <= upperLongBound; } } else if (hasLowerLongBound) { if (lowerStrict) { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int lowerComparing = Long.compare(input, lowerLongBound); - return lowerComparing > 0; - } - }; + return input -> input > lowerLongBound; } else { - return new DruidLongPredicate() - { - @Override - public boolean applyLong(long input) - { - final int lowerComparing = Long.compare(input, lowerLongBound); - return lowerComparing >= 0; - } - }; + return input -> input >= lowerLongBound; } } else { return DruidLongPredicate.ALWAYS_TRUE;