Skip to content

Commit 0e3db29

Browse files
committed
Adressing review comments
1 parent c6eeb47 commit 0e3db29

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

core/src/main/java/org/elasticsearch/search/aggregations/metrics/ParsedSingleValueNumericMetricsAggregation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected static double parseValue(XContentParser parser, double defaultNullValu
6363
}
6464
}
6565

66-
protected static void declareSingeValueFields(ObjectParser<? extends ParsedSingleValueNumericMetricsAggregation, Void> objectParser,
66+
protected static void declareSingleValueFields(ObjectParser<? extends ParsedSingleValueNumericMetricsAggregation, Void> objectParser,
6767
double defaultNullValue) {
6868
declareAggregationFields(objectParser);
6969
objectParser.declareField(ParsedSingleValueNumericMetricsAggregation::setValue,

core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/ParsedAvg.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params)
5353
private static final ObjectParser<ParsedAvg, Void> PARSER = new ObjectParser<>(ParsedAvg.class.getSimpleName(), true, ParsedAvg::new);
5454

5555
static {
56-
declareSingeValueFields(PARSER, Double.POSITIVE_INFINITY);
56+
declareSingleValueFields(PARSER, Double.POSITIVE_INFINITY);
5757
}
5858

5959
public static ParsedAvg fromXContent(XContentParser parser, final String name) {

core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/ParsedMax.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params)
5151
private static final ObjectParser<ParsedMax, Void> PARSER = new ObjectParser<>(ParsedMax.class.getSimpleName(), true, ParsedMax::new);
5252

5353
static {
54-
declareSingeValueFields(PARSER, Double.NEGATIVE_INFINITY);
54+
declareSingleValueFields(PARSER, Double.NEGATIVE_INFINITY);
5555
}
5656

5757
public static ParsedMax fromXContent(XContentParser parser, final String name) {

core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/ParsedMin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params)
5151
private static final ObjectParser<ParsedMin, Void> PARSER = new ObjectParser<>(ParsedMin.class.getSimpleName(), true, ParsedMin::new);
5252

5353
static {
54-
declareSingeValueFields(PARSER, Double.POSITIVE_INFINITY);
54+
declareSingleValueFields(PARSER, Double.POSITIVE_INFINITY);
5555
}
5656

5757
public static ParsedMin fromXContent(XContentParser parser, final String name) {

core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/ParsedSum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected XContentBuilder doXContentBody(XContentBuilder builder, Params params)
5050
private static final ObjectParser<ParsedSum, Void> PARSER = new ObjectParser<>(ParsedSum.class.getSimpleName(), true, ParsedSum::new);
5151

5252
static {
53-
declareSingeValueFields(PARSER, Double.NEGATIVE_INFINITY);
53+
declareSingleValueFields(PARSER, Double.NEGATIVE_INFINITY);
5454
}
5555

5656
public static ParsedSum fromXContent(XContentParser parser, final String name) {

core/src/main/java/org/elasticsearch/search/aggregations/pipeline/ParsedSimpleValue.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ protected String getType() {
3737
ParsedSimpleValue::new);
3838

3939
static {
40-
declareSingeValueFields(PARSER, Double.NaN);
40+
declareSingleValueFields(PARSER, Double.NaN);
4141
}
4242

4343
public static ParsedSimpleValue fromXContent(XContentParser parser, final String name) {
44-
ParsedSimpleValue min = PARSER.apply(parser, null);
45-
min.setName(name);
46-
return min;
44+
ParsedSimpleValue simpleValue = PARSER.apply(parser, null);
45+
simpleValue.setName(name);
46+
return simpleValue;
4747
}
4848

4949
@Override
5050
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
51-
boolean hasValue = !(Double.isInfinite(value) || Double.isNaN(value));
51+
boolean hasValue = Double.isNaN(value) == false;
5252
builder.field(CommonFields.VALUE.getPreferredName(), hasValue ? value : null);
5353
if (hasValue && valueAsString != null) {
5454
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), valueAsString);

core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/ParsedDerivative.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ParsedDerivative extends ParsedSimpleValue implements Derivative {
3232

3333
private double normalizedValue;
3434
private String normalizedAsString;
35-
private boolean valuePresent;
35+
private boolean hasNormalizationFactor;
3636
private static final ParseField NORMALIZED_AS_STRING = new ParseField("normalized_value_as_string");
3737
private static final ParseField NORMALIZED = new ParseField("normalized_value");
3838

@@ -50,29 +50,25 @@ protected String getType() {
5050
ParsedDerivative::new);
5151

5252
static {
53-
declareSingeValueFields(PARSER, Double.NaN);
53+
declareSingleValueFields(PARSER, Double.NaN);
5454
PARSER.declareField((agg, normalized) -> {
5555
agg.normalizedValue = normalized;
56-
agg.valuePresent = true;
57-
}, (parser, context) -> parseValue(parser, Double.NaN), NORMALIZED,
58-
ValueType.DOUBLE_OR_NULL);
59-
PARSER.declareString((agg, normalAsString) -> {
60-
agg.normalizedAsString = normalAsString;
61-
agg.valuePresent = true;
62-
}, NORMALIZED_AS_STRING);
56+
agg.hasNormalizationFactor = true;
57+
}, (parser, context) -> parseValue(parser, Double.NaN), NORMALIZED, ValueType.DOUBLE_OR_NULL);
58+
PARSER.declareString((agg, normalAsString) -> agg.normalizedAsString = normalAsString, NORMALIZED_AS_STRING);
6359
}
6460

6561
public static ParsedDerivative fromXContent(XContentParser parser, final String name) {
66-
ParsedDerivative min = PARSER.apply(parser, null);
67-
min.setName(name);
68-
return min;
62+
ParsedDerivative derivative = PARSER.apply(parser, null);
63+
derivative.setName(name);
64+
return derivative;
6965
}
7066

7167
@Override
7268
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
7369
super.doXContentBody(builder, params);
74-
if (valuePresent) {
75-
boolean hasValue = !(Double.isInfinite(normalizedValue) || Double.isNaN(normalizedValue));
70+
if (hasNormalizationFactor) {
71+
boolean hasValue = Double.isNaN(normalizedValue) == false;
7672
builder.field(NORMALIZED.getPreferredName(), hasValue ? normalizedValue : null);
7773
if (hasValue && normalizedAsString != null) {
7874
builder.field(NORMALIZED_AS_STRING.getPreferredName(), normalizedAsString);

core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
public class InternalSimpleValueTests extends InternalAggregationTestCase<InternalSimpleValue>{
3232

3333
@Override
34-
protected InternalSimpleValue createTestInstance(String name,
35-
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
34+
protected InternalSimpleValue createTestInstance(String name, List<PipelineAggregator> pipelineAggregators,
35+
Map<String, Object> metaData) {
3636
DocValueFormat formatter = randomNumericDocValueFormat();
3737
double value = frequently() ? randomDoubleBetween(0, 100000, true)
3838
: randomFrom(new Double[] { Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN });
@@ -59,12 +59,12 @@ protected Reader<InternalSimpleValue> instanceReader() {
5959
protected void assertFromXContent(InternalSimpleValue simpleValue, ParsedAggregation parsedAggregation) {
6060
ParsedSimpleValue parsed = ((ParsedSimpleValue) parsedAggregation);
6161
if (Double.isInfinite(simpleValue.getValue()) == false && Double.isNaN(simpleValue.getValue()) == false) {
62-
assertEquals(simpleValue.getValue(), parsed.value(), Double.MIN_VALUE);
62+
assertEquals(simpleValue.getValue(), parsed.value(), 0);
6363
assertEquals(simpleValue.getValueAsString(), parsed.getValueAsString());
6464
} else {
6565
// we write Double.NEGATIVE_INFINITY, Double.POSITIVE amd Double.NAN to xContent as 'null', so we
6666
// cannot differentiate between them. Also we cannot recreate the exact String representation
67-
assertEquals(parsed.value(), Double.NaN, Double.MIN_VALUE);
67+
assertEquals(parsed.value(), Double.NaN, 0);
6868
}
6969
}
7070
}

0 commit comments

Comments
 (0)