mirror of https://github.com/apache/druid.git
Merge pull request #2482 from navis/lazy-init-boundfilter
Lazily initialize predicate for bound filter
This commit is contained in:
commit
5aa1164b1a
|
@ -34,35 +34,51 @@ public class BoundFilter extends DimensionPredicateFilter
|
||||||
super(
|
super(
|
||||||
boundDimFilter.getDimension(), new Predicate<String>()
|
boundDimFilter.getDimension(), new Predicate<String>()
|
||||||
{
|
{
|
||||||
|
private volatile Predicate<String> predicate;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(String input)
|
public boolean apply(String input)
|
||||||
{
|
{
|
||||||
if (input == null) {
|
return function().apply(input);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
Comparator<String> comparator;
|
|
||||||
if (boundDimFilter.isAlphaNumeric()) {
|
|
||||||
comparator = new AlphaNumericTopNMetricSpec(null).getComparator(null, null);
|
|
||||||
} else {
|
|
||||||
comparator = new LexicographicTopNMetricSpec(null).getComparator(null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
int lowerComparing = 1;
|
private Predicate<String> function()
|
||||||
int upperComparing = 1;
|
{
|
||||||
if (boundDimFilter.getLower() != null) {
|
if (predicate == null) {
|
||||||
lowerComparing = comparator.compare(input, boundDimFilter.getLower());
|
final Comparator<String> comparator;
|
||||||
|
if (boundDimFilter.isAlphaNumeric()) {
|
||||||
|
comparator = new AlphaNumericTopNMetricSpec(null).getComparator(null, null);
|
||||||
|
} else {
|
||||||
|
comparator = new LexicographicTopNMetricSpec(null).getComparator(null, null);
|
||||||
|
}
|
||||||
|
predicate = new Predicate<String>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean apply(String input)
|
||||||
|
{
|
||||||
|
if (input == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int lowerComparing = 1;
|
||||||
|
int upperComparing = 1;
|
||||||
|
if (boundDimFilter.getLower() != null) {
|
||||||
|
lowerComparing = comparator.compare(input, boundDimFilter.getLower());
|
||||||
|
}
|
||||||
|
if (boundDimFilter.getUpper() != null) {
|
||||||
|
upperComparing = comparator.compare(boundDimFilter.getUpper(), input);
|
||||||
|
}
|
||||||
|
if (boundDimFilter.isLowerStrict() && boundDimFilter.isUpperStrict()) {
|
||||||
|
return ((lowerComparing > 0)) && (upperComparing > 0);
|
||||||
|
} else if (boundDimFilter.isLowerStrict()) {
|
||||||
|
return (lowerComparing > 0) && (upperComparing >= 0);
|
||||||
|
} else if (boundDimFilter.isUpperStrict()) {
|
||||||
|
return (lowerComparing >= 0) && (upperComparing > 0);
|
||||||
|
}
|
||||||
|
return (lowerComparing >= 0) && (upperComparing >= 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (boundDimFilter.getUpper() != null) {
|
return predicate;
|
||||||
upperComparing = comparator.compare(boundDimFilter.getUpper(), input);
|
|
||||||
}
|
|
||||||
if (boundDimFilter.isLowerStrict() && boundDimFilter.isUpperStrict()) {
|
|
||||||
return ((lowerComparing > 0)) && ( upperComparing > 0);
|
|
||||||
} else if (boundDimFilter.isLowerStrict()) {
|
|
||||||
return (lowerComparing > 0) && (upperComparing >= 0);
|
|
||||||
} else if (boundDimFilter.isUpperStrict()) {
|
|
||||||
return (lowerComparing >= 0) && (upperComparing > 0);
|
|
||||||
}
|
|
||||||
return (lowerComparing >= 0) && (upperComparing >= 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue