Skip to content

Commit

Permalink
Deprecate Aggregator.getName and AggregatorFactory.getAggregatorStart…
Browse files Browse the repository at this point in the history
…Value. (apache#3572)
  • Loading branch information
gianm authored and fjy committed Oct 31, 2016
1 parent 32c5494 commit 89d9c61
Show file tree
Hide file tree
Showing 63 changed files with 159 additions and 363 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@
public class DistinctCountAggregator implements Aggregator
{

private final String name;
private final DimensionSelector selector;
private final MutableBitmap mutableBitmap;

public DistinctCountAggregator(
String name,
DimensionSelector selector,
MutableBitmap mutableBitmap
)
{
this.name = name;
this.selector = selector;
this.mutableBitmap = mutableBitmap;
}
Expand Down Expand Up @@ -70,7 +67,7 @@ public float getFloat()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ public Aggregator factorize(ColumnSelectorFactory columnFactory)
{
DimensionSelector selector = makeDimensionSelector(columnFactory);
if (selector == null) {
return new EmptyDistinctCountAggregator(name);
return new EmptyDistinctCountAggregator();
} else {
return new DistinctCountAggregator(
name,
selector,
bitMapFactory.makeEmptyMutableBitmap()
);
Expand Down Expand Up @@ -197,12 +196,6 @@ public int getMaxIntermediateSize()
return Longs.BYTES;
}

@Override
public Object getAggregatorStartValue()
{
return 0;
}

@Override
public boolean equals(Object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
public class EmptyDistinctCountAggregator implements Aggregator
{

private final String name;

public EmptyDistinctCountAggregator(String name)
public EmptyDistinctCountAggregator()
{
this.name = name;
}

@Override
Expand Down Expand Up @@ -56,7 +53,7 @@ public float getFloat()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@

public class EmptySketchAggregator implements Aggregator
{
private final String name;

public EmptySketchAggregator(String name)
public EmptySketchAggregator()
{
this.name = name;
}

@Override
Expand Down Expand Up @@ -61,7 +58,7 @@ public long getLong()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,12 @@ public class SketchAggregator implements Aggregator
private static final Logger logger = new Logger(SketchAggregator.class);

private final ObjectColumnSelector selector;
private final String name;
private final int size;

private Union union;

public SketchAggregator(String name, ObjectColumnSelector selector, int size)
public SketchAggregator(ObjectColumnSelector selector, int size)
{
this.name = name;
this.selector = selector;
this.size = size;
union = new SynchronizedUnion((Union) SetOperation.builder().build(size, Family.UNION));
}

Expand Down Expand Up @@ -93,7 +89,7 @@ public long getLong()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.yahoo.sketches.memory.Memory;
import com.yahoo.sketches.theta.SetOperation;
import com.yahoo.sketches.theta.Sketch;
import com.yahoo.sketches.theta.Sketches;
import com.yahoo.sketches.theta.Union;
import io.druid.java.util.common.IAE;
import io.druid.query.aggregation.Aggregator;
Expand Down Expand Up @@ -82,9 +81,9 @@ public Aggregator factorize(ColumnSelectorFactory metricFactory)
{
ObjectColumnSelector selector = metricFactory.makeObjectColumnSelector(fieldName);
if (selector == null) {
return new EmptySketchAggregator(name);
return new EmptySketchAggregator();
} else {
return new SketchAggregator(name, selector, size);
return new SketchAggregator(selector, size);
}
}

Expand Down Expand Up @@ -172,12 +171,6 @@ public int getMaxIntermediateSize()
return SetOperation.getMaxUnionBytes(size);
}

@Override
public Object getAggregatorStartValue()
{
return Sketches.updateSketchBuilder().build(size);
}

@Override
public List<String> requiredFields()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static Object combineHistograms(Object lhs, Object rhs)
return ((ApproximateHistogram) lhs).foldFast((ApproximateHistogram) rhs);
}

private final String name;
private final FloatColumnSelector selector;
private final int resolution;
private final float lowerLimit;
Expand All @@ -50,14 +49,12 @@ static Object combineHistograms(Object lhs, Object rhs)
private ApproximateHistogram histogram;

public ApproximateHistogramAggregator(
String name,
FloatColumnSelector selector,
int resolution,
float lowerLimit,
float upperLimit
)
{
this.name = name;
this.selector = selector;
this.resolution = resolution;
this.lowerLimit = lowerLimit;
Expand Down Expand Up @@ -98,7 +95,7 @@ public long getLong()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public ApproximateHistogramAggregatorFactory(
public Aggregator factorize(ColumnSelectorFactory metricFactory)
{
return new ApproximateHistogramAggregator(
name,
metricFactory.makeFloatColumnSelector(fieldName),
resolution,
lowerLimit,
Expand Down Expand Up @@ -254,12 +253,6 @@ public int getMaxIntermediateSize()
return new ApproximateHistogram(resolution).getMaxStorageSize();
}

@Override
public Object getAggregatorStartValue()
{
return new ApproximateHistogram(resolution);
}

@Override
public boolean equals(Object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

public class ApproximateHistogramFoldingAggregator implements Aggregator
{
private final String name;
private final ObjectColumnSelector<ApproximateHistogram> selector;
private final int resolution;
private final float lowerLimit;
Expand All @@ -36,14 +35,12 @@ public class ApproximateHistogramFoldingAggregator implements Aggregator
private long[] tmpBufferB;

public ApproximateHistogramFoldingAggregator(
String name,
ObjectColumnSelector<ApproximateHistogram> selector,
int resolution,
float lowerLimit,
float upperLimit
)
{
this.name = name;
this.selector = selector;
this.resolution = resolution;
this.lowerLimit = lowerLimit;
Expand Down Expand Up @@ -96,7 +93,7 @@ public long getLong()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public ApproximateHistogram get()
final Class cls = selector.classOfObject();
if (cls.equals(Object.class) || ApproximateHistogram.class.isAssignableFrom(cls)) {
return new ApproximateHistogramFoldingAggregator(
name,
selector,
resolution,
lowerLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public void testCompute()
ApproximateHistogram ah = buildHistogram(10, VALUES);
final TestFloatColumnSelector selector = new TestFloatColumnSelector(VALUES);

ApproximateHistogramAggregator agg = new ApproximateHistogramAggregator("price", selector, 10, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
ApproximateHistogramAggregator agg = new ApproximateHistogramAggregator(selector, 10, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
for (int i = 0; i < VALUES.length; i++) {
agg.aggregate();
selector.increment();
}

Map<String, Object> metricValues = new HashMap<String, Object>();
metricValues.put(agg.getName(), agg.get());
metricValues.put("price", agg.get());

ApproximateHistogramPostAggregator approximateHistogramPostAggregator = new EqualBucketsPostAggregator(
"approxHist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@
*/
public abstract class VarianceAggregator implements Aggregator
{
protected final String name;

protected final VarianceAggregatorCollector holder = new VarianceAggregatorCollector();

public VarianceAggregator(String name)
public VarianceAggregator()
{
this.name = name;
}

@Override
Expand All @@ -52,7 +49,7 @@ public Object get()
@Override
public String getName()
{
return name;
throw new UnsupportedOperationException("getName is deprecated");
}

@Override
Expand All @@ -76,9 +73,9 @@ public static final class FloatVarianceAggregator extends VarianceAggregator
{
private final FloatColumnSelector selector;

public FloatVarianceAggregator(String name, FloatColumnSelector selector)
public FloatVarianceAggregator(FloatColumnSelector selector)
{
super(name);
super();
this.selector = selector;
}

Expand All @@ -93,9 +90,9 @@ public static final class LongVarianceAggregator extends VarianceAggregator
{
private final LongColumnSelector selector;

public LongVarianceAggregator(String name, LongColumnSelector selector)
public LongVarianceAggregator(LongColumnSelector selector)
{
super(name);
super();
this.selector = selector;
}

Expand All @@ -110,9 +107,9 @@ public static final class ObjectVarianceAggregator extends VarianceAggregator
{
private final ObjectColumnSelector selector;

public ObjectVarianceAggregator(String name, ObjectColumnSelector selector)
public ObjectVarianceAggregator(ObjectColumnSelector selector)
{
super(name);
super();
this.selector = selector;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,11 @@ public Aggregator factorize(ColumnSelectorFactory metricFactory)
}

if ("float".equalsIgnoreCase(inputType)) {
return new VarianceAggregator.FloatVarianceAggregator(
name,
metricFactory.makeFloatColumnSelector(fieldName)
);
return new VarianceAggregator.FloatVarianceAggregator(metricFactory.makeFloatColumnSelector(fieldName));
} else if ("long".equalsIgnoreCase(inputType)) {
return new VarianceAggregator.LongVarianceAggregator(
name,
metricFactory.makeLongColumnSelector(fieldName)
);
return new VarianceAggregator.LongVarianceAggregator(metricFactory.makeLongColumnSelector(fieldName));
} else if ("variance".equalsIgnoreCase(inputType)) {
return new VarianceAggregator.ObjectVarianceAggregator(name, selector);
return new VarianceAggregator.ObjectVarianceAggregator(selector);
}
throw new IAE(
"Incompatible type for metric[%s], expected a float, long or variance, got a %s", fieldName, inputType
Expand Down Expand Up @@ -169,12 +163,6 @@ public Comparator getComparator()
return VarianceAggregatorCollector.COMPARATOR;
}

@Override
public Object getAggregatorStartValue()
{
return new VarianceAggregatorCollector();
}

@Override
public Object combine(Object lhs, Object rhs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ public void testDoubleVarianceAggregator()
{
VarianceAggregator agg = (VarianceAggregator) aggFactory.factorize(colSelectorFactory);

Assert.assertEquals("billy", agg.getName());

assertValues((VarianceAggregatorCollector) agg.get(), 0, 0d, 0d);
aggregate(selector, agg);
assertValues((VarianceAggregatorCollector) agg.get(), 1, 1.1d, 0d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public InputRow get()
catch (ParseException e) {
// "aggregate" can throw ParseExceptions if a selector expects something but gets something else.
if (reportParseExceptions) {
throw new ParseException(e, "Encountered parse error for aggregator[%s]", agg.getName());
throw new ParseException(e, "Encountered parse error for aggregator[%s]", k);
}
log.debug(e, "Encountered parse error, skipping aggregator[%s].", agg.getName());
log.debug(e, "Encountered parse error, skipping aggregator[%s].", k);
}

String t = aggFactory.getTypeName();
Expand Down
11 changes: 0 additions & 11 deletions processing/src/main/java/io/druid/query/QueryRunnerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ public class QueryRunnerHelper
{
private static final Logger log = new Logger(QueryRunnerHelper.class);

public static Aggregator[] makeAggregators(Cursor cursor, List<AggregatorFactory> aggregatorSpecs)
{
Aggregator[] aggregators = new Aggregator[aggregatorSpecs.size()];
int aggregatorIndex = 0;
for (AggregatorFactory spec : aggregatorSpecs) {
aggregators[aggregatorIndex] = spec.factorize(cursor);
++aggregatorIndex;
}
return aggregators;
}

public static <T> Sequence<Result<T>> makeCursorBasedQuery(
final StorageAdapter adapter,
List<Interval> queryIntervals,
Expand Down
Loading

0 comments on commit 89d9c61

Please sign in to comment.