mirror of https://github.com/apache/druid.git
simplify code a bit
This commit is contained in:
parent
0785baf54c
commit
4ec1e6ef13
|
@ -21,6 +21,7 @@ package io.druid.query.aggregation;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.metamx.common.ISE;
|
||||||
import com.metamx.common.Pair;
|
import com.metamx.common.Pair;
|
||||||
import io.druid.query.filter.DimFilter;
|
import io.druid.query.filter.DimFilter;
|
||||||
import io.druid.query.filter.NotDimFilter;
|
import io.druid.query.filter.NotDimFilter;
|
||||||
|
@ -49,15 +50,10 @@ public class FilteredAggregatorFactory implements AggregatorFactory
|
||||||
Preconditions.checkNotNull(delegate);
|
Preconditions.checkNotNull(delegate);
|
||||||
Preconditions.checkNotNull(filter);
|
Preconditions.checkNotNull(filter);
|
||||||
Preconditions.checkArgument(
|
Preconditions.checkArgument(
|
||||||
filter instanceof SelectorDimFilter || filter instanceof NotDimFilter,
|
filter instanceof SelectorDimFilter ||
|
||||||
"FilteredAggregator currently only supports filters of type selector and not"
|
(filter instanceof NotDimFilter && ((NotDimFilter) filter).getField() instanceof SelectorDimFilter),
|
||||||
|
"FilteredAggregator currently only supports filters of type 'selector' and their negation"
|
||||||
);
|
);
|
||||||
if (filter instanceof NotDimFilter) {
|
|
||||||
Preconditions.checkArgument(
|
|
||||||
((NotDimFilter) filter).getField() instanceof SelectorDimFilter,
|
|
||||||
"FilteredAggregator currently only support not filter with selector filter"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
@ -189,43 +185,32 @@ public class FilteredAggregatorFactory implements AggregatorFactory
|
||||||
} else if (dimFilter instanceof SelectorDimFilter) {
|
} else if (dimFilter instanceof SelectorDimFilter) {
|
||||||
selector = (SelectorDimFilter) dimFilter;
|
selector = (SelectorDimFilter) dimFilter;
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException(
|
throw new ISE("Unsupported DimFilter type [%d]", dimFilter.getClass());
|
||||||
"FilteredAggregator does not support DimFilter of type "
|
|
||||||
+ dimFilter.getClass()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final DimensionSelector dimSelector = metricFactory.makeDimensionSelector(selector.getDimension());
|
final DimensionSelector dimSelector = metricFactory.makeDimensionSelector(selector.getDimension());
|
||||||
final int lookupId = dimSelector.lookupId(selector.getValue());
|
final int lookupId = dimSelector.lookupId(selector.getValue());
|
||||||
if (dimFilter instanceof SelectorDimFilter) {
|
final IntPredicate predicate;
|
||||||
|
if (dimFilter instanceof NotDimFilter) {
|
||||||
return Pair.<DimensionSelector, IntPredicate>of(
|
predicate = new IntPredicate()
|
||||||
dimSelector, new IntPredicate()
|
{
|
||||||
{
|
@Override
|
||||||
@Override
|
public boolean apply(int value)
|
||||||
public boolean apply(int value)
|
{
|
||||||
{
|
return lookupId != value;
|
||||||
return lookupId == value;
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
);
|
|
||||||
} else if (dimFilter instanceof NotDimFilter) {
|
|
||||||
return Pair.<DimensionSelector, IntPredicate>of(
|
|
||||||
dimSelector, new IntPredicate()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean apply(int value)
|
|
||||||
{
|
|
||||||
return lookupId != value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException(
|
predicate = new IntPredicate()
|
||||||
"FilteredAggregator does not support DimFilter of type "
|
{
|
||||||
+ dimFilter.getClass()
|
@Override
|
||||||
);
|
public boolean apply(int value)
|
||||||
|
{
|
||||||
|
return lookupId == value;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return Pair.of(dimSelector, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue