Skip to content

Commit

Permalink
Make InternalNumericMetricsAggregation.format field final. (#84623)
Browse files Browse the repository at this point in the history
  • Loading branch information
przemekwitek committed Mar 4, 2022
1 parent cf151b5 commit e7c4e8c
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ abstract class AbstractInternalHDRPercentiles extends InternalNumericMetricsAggr
DocValueFormat format,
Map<String, Object> metadata
) {
super(name, metadata);
super(name, format, metadata);
this.keys = keys;
this.state = state;
this.keyed = keyed;
this.format = format;
}

/**
* Read from a stream.
*/
protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
keys = in.readDoubleArray();
long minBarForHighestToLowestValueRatio = in.readLong();
final int serializedLen = in.readVInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ abstract class AbstractInternalTDigestPercentiles extends InternalNumericMetrics
DocValueFormat formatter,
Map<String, Object> metadata
) {
super(name, metadata);
super(name, formatter, metadata);
this.keys = keys;
this.state = state;
this.keyed = keyed;
this.format = formatter;
}

/**
* Read from a stream.
*/
protected AbstractInternalTDigestPercentiles(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
keys = in.readDoubleArray();
state = TDigestState.read(in);
keyed = in.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
private final long count;

public InternalAvg(String name, double sum, long count, DocValueFormat format, Map<String, Object> metadata) {
super(name, metadata);
super(name, format, metadata);
this.sum = sum;
this.count = count;
this.format = format;
}

/**
* Read from a stream.
*/
public InternalAvg(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
sum = in.readDouble();
count = in.readVLong();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationReduceContext;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.xcontent.XContentBuilder;
Expand All @@ -25,7 +24,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
private final AbstractHyperLogLogPlusPlus counts;

InternalCardinality(String name, AbstractHyperLogLogPlusPlus counts, Map<String, Object> metadata) {
super(name, metadata);
super(name, null, metadata);
this.counts = counts;
}

Expand All @@ -34,7 +33,6 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
*/
public InternalCardinality(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
if (in.readBoolean()) {
counts = AbstractHyperLogLogPlusPlus.readFrom(in, BigArrays.NON_RECYCLING_INSTANCE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ static double computeMedianAbsoluteDeviation(TDigestState valuesSketch) {
private final double medianAbsoluteDeviation;

InternalMedianAbsoluteDeviation(String name, Map<String, Object> metadata, DocValueFormat format, TDigestState valuesSketch) {
super(name, metadata);
this.format = Objects.requireNonNull(format);
super(name, Objects.requireNonNull(format), metadata);
this.valuesSketch = Objects.requireNonNull(valuesSketch);

this.medianAbsoluteDeviation = computeMedianAbsoluteDeviation(this.valuesSketch);
}

public InternalMedianAbsoluteDeviation(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
valuesSketch = TDigestState.read(in);
medianAbsoluteDeviation = in.readDouble();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ public class InternalMin extends InternalNumericMetricsAggregation.SingleValue i
private final double min;

public InternalMin(String name, double min, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, metadata);
super(name, formatter, metadata);
this.min = min;
this.format = formatter;
}

/**
* Read from a stream.
*/
public InternalMin(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
min = in.readDouble();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public abstract class InternalNumericMetricsAggregation extends InternalAggregat

private static final DocValueFormat DEFAULT_FORMAT = DocValueFormat.RAW;

protected DocValueFormat format = DEFAULT_FORMAT;
protected final DocValueFormat format;

public abstract static class SingleValue extends InternalNumericMetricsAggregation implements NumericMetricsAggregation.SingleValue {
protected SingleValue(String name, Map<String, Object> metadata) {
super(name, metadata);
protected SingleValue(String name, DocValueFormat format, Map<String, Object> metadata) {
super(name, format, metadata);
}

/**
Expand All @@ -36,6 +36,15 @@ protected SingleValue(StreamInput in) throws IOException {
super(in);
}

/**
* Read from a stream.
*
* @param readFormat whether to read the "format" field
*/
protected SingleValue(StreamInput in, boolean readFormat) throws IOException {
super(in, readFormat);
}

@Override
public String getValueAsString() {
return format.format(value()).toString();
Expand Down Expand Up @@ -68,8 +77,8 @@ public final double sortValue(String key) {
}

public abstract static class MultiValue extends InternalNumericMetricsAggregation implements NumericMetricsAggregation.MultiValue {
protected MultiValue(String name, Map<String, Object> metadata) {
super(name, metadata);
protected MultiValue(String name, DocValueFormat format, Map<String, Object> metadata) {
super(name, format, metadata);
}

/**
Expand All @@ -79,6 +88,15 @@ protected MultiValue(StreamInput in) throws IOException {
super(in);
}

/**
* Read from a stream.
*
* @param readFormat whether to read the "format" field
*/
protected MultiValue(StreamInput in, boolean readFormat) throws IOException {
super(in, readFormat);
}

public abstract double value(String name);

public String valueAsString(String name) {
Expand All @@ -105,15 +123,26 @@ public final double sortValue(String key) {
}
}

private InternalNumericMetricsAggregation(String name, Map<String, Object> metadata) {
private InternalNumericMetricsAggregation(String name, DocValueFormat format, Map<String, Object> metadata) {
super(name, metadata);
this.format = format != null ? format : DEFAULT_FORMAT;
}

/**
* Read from a stream.
*/
protected InternalNumericMetricsAggregation(StreamInput in) throws IOException {
this(in, true);
}

/**
* Read from a stream.
* @param readFormat whether to read the "format" field
* Should be {@code true} iff the "format" field is being written to the wire by the agg
*/
protected InternalNumericMetricsAggregation(StreamInput in, boolean readFormat) throws IOException {
super(in);
this.format = readFormat ? in.readNamedWriteable(DocValueFormat.class) : DEFAULT_FORMAT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ public InternalStats(
DocValueFormat formatter,
Map<String, Object> metadata
) {
super(name, metadata);
super(name, formatter, metadata);
this.count = count;
this.sum = sum;
this.min = min;
this.max = max;
this.format = formatter;
}

/**
* Read from a stream.
*/
public InternalStats(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
count = in.readVLong();
min = in.readDouble();
max = in.readDouble();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public class InternalValueCount extends InternalNumericMetricsAggregation.Single
private final long value;

public InternalValueCount(String name, long value, Map<String, Object> metadata) {
super(name, metadata);
super(name, null, metadata);
this.value = value;
}

/**
* Read from a stream.
*/
public InternalValueCount(StreamInput in) throws IOException {
super(in);
super(in, false);
value = in.readVLong();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ public class InternalWeightedAvg extends InternalNumericMetricsAggregation.Singl
private final double weight;

InternalWeightedAvg(String name, double sum, double weight, DocValueFormat format, Map<String, Object> metadata) {
super(name, metadata);
super(name, format, metadata);
this.sum = sum;
this.weight = weight;
this.format = format;
}

/**
* Read from a stream.
*/
public InternalWeightedAvg(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
sum = in.readDouble();
weight = in.readDouble();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class Max extends InternalNumericMetricsAggregation.SingleValue {
private final double max;

public Max(String name, double max, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, metadata);
this.format = formatter;
super(name, formatter, metadata);
this.max = max;
}

Expand All @@ -34,7 +33,6 @@ public Max(String name, double max, DocValueFormat formatter, Map<String, Object
*/
public Max(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
max = in.readDouble();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ public class Sum extends InternalNumericMetricsAggregation.SingleValue {
private final double sum;

public Sum(String name, double sum, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, metadata);
super(name, formatter, metadata);
this.sum = sum;
this.format = formatter;
}

/**
* Read from a stream.
*/
public Sum(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
sum = in.readDouble();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ public class InternalBucketMetricValue extends InternalNumericMetricsAggregation
private String[] keys;

public InternalBucketMetricValue(String name, String[] keys, double value, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, metadata);
super(name, formatter, metadata);
this.keys = keys;
this.value = value;
this.format = formatter;
}

/**
* Read from a stream.
*/
public InternalBucketMetricValue(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
value = in.readDouble();
keys = in.readStringArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class InternalPercentilesBucket extends InternalNumericMetricsAggregation
DocValueFormat formatter,
Map<String, Object> metadata
) {
super(name, metadata);
super(name, formatter, metadata);
if ((percentiles.length == percents.length) == false) {
throw new IllegalArgumentException(
"The number of provided percents and percentiles didn't match. percents: "
Expand All @@ -51,7 +51,6 @@ public class InternalPercentilesBucket extends InternalNumericMetricsAggregation
+ Arrays.toString(percentiles)
);
}
this.format = formatter;
this.percentiles = percentiles;
this.percents = percents;
this.keyed = keyed;
Expand All @@ -69,7 +68,6 @@ private void computeLookup() {
*/
public InternalPercentilesBucket(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
percentiles = in.readDoubleArray();
percents = in.readDoubleArray();
keyed = in.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class InternalSimpleValue extends InternalNumericMetricsAggregation.Singl
protected final double value;

public InternalSimpleValue(String name, double value, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, metadata);
this.format = formatter;
super(name, formatter, metadata);
this.value = value;
}

Expand All @@ -36,7 +35,6 @@ public InternalSimpleValue(String name, double value, DocValueFormat formatter,
*/
public InternalSimpleValue(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
value = in.readDouble();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,15 @@ public static double[] whiskers(TDigestState state) {
private final TDigestState state;

InternalBoxplot(String name, TDigestState state, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, metadata);
super(name, formatter, metadata);
this.state = state;
this.format = formatter;
}

/**
* Read from a stream.
*/
public InternalBoxplot(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
state = TDigestState.read(in);
}

Expand Down

0 comments on commit e7c4e8c

Please sign in to comment.