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.)
This commit is contained in:
Gian Merlino 2021-02-19 16:44:56 -08:00 committed by GitHub
parent f5bfccc720
commit b7e9f5bc85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 76 deletions

View File

@ -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;