Skip to content

Commit 5d521a0

Browse files
committed
typos and renaming
1 parent 0c87d60 commit 5d521a0

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/ExponentialHistogramParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private record ParsedZeroBucket(long count, double threshold) {
113113

114114
/**
115115
* Parses an XContent object into an exponential histogram.
116-
* The parse is expected to point at the next token after {@link XContentParser.Token#START_OBJECT}.
116+
* The parser is expected to point at the next token after {@link XContentParser.Token#START_OBJECT}.
117117
*
118118
* @param mappedFieldName the name of the field being parsed, used for error messages
119119
* @param parser the parser to use

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/HistogramParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public record ParsedHistogram(List<Double> values, List<Long> counts) {}
3131

3232
/**
3333
* Parses an XContent object into a histogram.
34-
* The parse is expected to point at the next token after {@link XContentParser.Token#START_OBJECT}.
34+
* The parser is expected to point at the next token after {@link XContentParser.Token#START_OBJECT}.
3535
*
3636
* @param mappedFieldName the name of the field being parsed, used for error messages
3737
* @param parser the parser to use

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/TDigestFieldMapper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
public class TDigestFieldMapper extends FieldMapper {
6666
public static final FeatureFlag TDIGEST_FIELD_MAPPER = new FeatureFlag("tdigest_field_mapper");
6767

68+
public static final String CENTROIDS_NAME = "centroids";
69+
public static final String COUNTS_NAME = "counts";
6870
public static final String CONTENT_TYPE = "tdigest";
6971

7072
private static TDigestFieldMapper toType(FieldMapper in) {
@@ -338,13 +340,13 @@ public void parse(DocumentParserContext context) throws IOException {
338340
TDigestParser.ParsedHistogram parsedHistogram = TDigestParser.parse(fullPath(), subParser);
339341

340342
BytesStreamOutput streamOutput = new BytesStreamOutput();
341-
for (int i = 0; i < parsedHistogram.values().size(); i++) {
343+
for (int i = 0; i < parsedHistogram.centroids().size(); i++) {
342344
long count = parsedHistogram.counts().get(i);
343345
assert count >= 0;
344346
// we do not add elements with count == 0
345347
if (count > 0) {
346348
streamOutput.writeVLong(count);
347-
streamOutput.writeLong(Double.doubleToRawLongBits(parsedHistogram.values().get(i)));
349+
streamOutput.writeLong(Double.doubleToRawLongBits(parsedHistogram.centroids().get(i)));
348350
}
349351
}
350352
BytesRef docValue = streamOutput.bytes().toBytesRef();
@@ -486,14 +488,14 @@ public void write(XContentBuilder b) throws IOException {
486488
b.startObject();
487489

488490
value.reset(binaryValue);
489-
b.startArray("centroids");
491+
b.startArray(CENTROIDS_NAME);
490492
while (value.next()) {
491493
b.value(value.value());
492494
}
493495
b.endArray();
494496

495497
value.reset(binaryValue);
496-
b.startArray("counts");
498+
b.startArray(COUNTS_NAME);
497499
while (value.next()) {
498500
b.value(value.count());
499501
}

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/mapper/TDigestParser.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,64 @@
1616
import java.util.List;
1717

1818
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
19+
import static org.elasticsearch.xpack.analytics.mapper.TDigestFieldMapper.CENTROIDS_NAME;
20+
import static org.elasticsearch.xpack.analytics.mapper.TDigestFieldMapper.COUNTS_NAME;
1921

2022
public class TDigestParser {
2123

22-
private static final ParseField COUNTS_FIELD = new ParseField("counts");
23-
private static final ParseField VALUES_FIELD = new ParseField("centroids");
24+
private static final ParseField COUNTS_FIELD = new ParseField(COUNTS_NAME);
25+
private static final ParseField CENTROIDS_FIELD = new ParseField(CENTROIDS_NAME);
2426

2527
/**
26-
* A parsed histogram field, can represent either a T-Digest or a HDR histogram.
27-
* @param values the centroids, guaranteed to be distinct and in increasing order
28-
* @param counts the counts, guaranteed to be non-negative and of the same length as values
28+
* A parsed histogram field, can represent either a T-Digest
29+
* @param centroids the centroids, guaranteed to be distinct and in increasing order
30+
* @param counts the counts, guaranteed to be non-negative and of the same length as the centroids array
2931
*/
30-
public record ParsedHistogram(List<Double> values, List<Long> counts) {}
32+
public record ParsedHistogram(List<Double> centroids, List<Long> counts) {}
3133

3234
/**
3335
* Parses an XContent object into a histogram.
34-
* The parse is expected to point at the next token after {@link XContentParser.Token#START_OBJECT}.
36+
* The parser is expected to point at the next token after {@link XContentParser.Token#START_OBJECT}.
3537
*
3638
* @param mappedFieldName the name of the field being parsed, used for error messages
3739
* @param parser the parser to use
3840
* @return the parsed histogram
3941
*/
4042
public static ParsedHistogram parse(String mappedFieldName, XContentParser parser) throws IOException {
41-
ArrayList<Double> values = null;
43+
ArrayList<Double> centroids = null;
4244
ArrayList<Long> counts = null;
4345
XContentParser.Token token = parser.currentToken();
4446
while (token != XContentParser.Token.END_OBJECT) {
4547
// should be a field
4648
ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser);
4749
String fieldName = parser.currentName();
48-
if (fieldName.equals(VALUES_FIELD.getPreferredName())) {
50+
if (fieldName.equals(CENTROIDS_FIELD.getPreferredName())) {
4951
token = parser.nextToken();
5052
// should be an array
5153
ensureExpectedToken(XContentParser.Token.START_ARRAY, token, parser);
52-
values = new ArrayList<>();
54+
centroids = new ArrayList<>();
5355
token = parser.nextToken();
5456
double previousVal = -Double.MAX_VALUE;
5557
while (token != XContentParser.Token.END_ARRAY) {
5658
// should be a number
5759
ensureExpectedToken(XContentParser.Token.VALUE_NUMBER, token, parser);
5860
double val = parser.doubleValue();
5961
if (val < previousVal) {
60-
// values must be in increasing order
62+
// centroids must be in increasing order
6163
throw new DocumentParsingException(
6264
parser.getTokenLocation(),
6365
"error parsing field ["
6466
+ mappedFieldName
6567
+ "], ["
66-
+ VALUES_FIELD
67-
+ "] values must be in increasing order, got ["
68+
+ CENTROIDS_FIELD
69+
+ "] centroids must be in increasing order, got ["
6870
+ val
6971
+ "] but previous value was ["
7072
+ previousVal
7173
+ "]"
7274
);
7375
}
74-
values.add(val);
76+
centroids.add(val);
7577
previousVal = val;
7678
token = parser.nextToken();
7779
}
@@ -102,10 +104,10 @@ public static ParsedHistogram parse(String mappedFieldName, XContentParser parse
102104
}
103105
token = parser.nextToken();
104106
}
105-
if (values == null) {
107+
if (centroids == null) {
106108
throw new DocumentParsingException(
107109
parser.getTokenLocation(),
108-
"error parsing field [" + mappedFieldName + "], expected field called [" + VALUES_FIELD.getPreferredName() + "]"
110+
"error parsing field [" + mappedFieldName + "], expected field called [" + CENTROIDS_FIELD.getPreferredName() + "]"
109111
);
110112
}
111113
if (counts == null) {
@@ -114,24 +116,24 @@ public static ParsedHistogram parse(String mappedFieldName, XContentParser parse
114116
"error parsing field [" + mappedFieldName + "], expected field called [" + COUNTS_FIELD.getPreferredName() + "]"
115117
);
116118
}
117-
if (values.size() != counts.size()) {
119+
if (centroids.size() != counts.size()) {
118120
throw new DocumentParsingException(
119121
parser.getTokenLocation(),
120122
"error parsing field ["
121123
+ mappedFieldName
122124
+ "], expected same length from ["
123-
+ VALUES_FIELD.getPreferredName()
125+
+ CENTROIDS_FIELD.getPreferredName()
124126
+ "] and "
125127
+ "["
126128
+ COUNTS_FIELD.getPreferredName()
127129
+ "] but got ["
128-
+ values.size()
130+
+ centroids.size()
129131
+ " != "
130132
+ counts.size()
131133
+ "]"
132134
);
133135
}
134-
return new ParsedHistogram(values, counts);
136+
return new ParsedHistogram(centroids, counts);
135137
}
136138

137139
}

0 commit comments

Comments
 (0)