Skip to content

Commit ff00052

Browse files
author
Hendrik Muhs
committed
apply spotless code formatting
1 parent 8332ad4 commit ff00052

File tree

1 file changed

+58
-45
lines changed

1 file changed

+58
-45
lines changed

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/AggregationResultUtils.java

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ public final class AggregationResultUtils {
5959
* @param stats stats collector
6060
* @return a map containing the results of the aggregation in a consumable way
6161
*/
62-
public static Stream<Map<String, Object>> extractCompositeAggregationResults(CompositeAggregation agg,
63-
GroupConfig groups,
64-
Collection<AggregationBuilder> aggregationBuilders,
65-
Collection<PipelineAggregationBuilder> pipelineAggs,
66-
Map<String, String> fieldTypeMap,
67-
TransformIndexerStats stats) {
62+
public static Stream<Map<String, Object>> extractCompositeAggregationResults(
63+
CompositeAggregation agg,
64+
GroupConfig groups,
65+
Collection<AggregationBuilder> aggregationBuilders,
66+
Collection<PipelineAggregationBuilder> pipelineAggs,
67+
Map<String, String> fieldTypeMap,
68+
TransformIndexerStats stats
69+
) {
6870
return agg.getBuckets().stream().map(bucket -> {
6971
stats.incrementNumDocuments(bucket.getDocCount());
7072
Map<String, Object> document = new HashMap<>();
@@ -82,7 +84,7 @@ public static Stream<Map<String, Object>> extractCompositeAggregationResults(Com
8284
List<String> aggNames = aggregationBuilders.stream().map(AggregationBuilder::getName).collect(Collectors.toList());
8385
aggNames.addAll(pipelineAggs.stream().map(PipelineAggregationBuilder::getName).collect(Collectors.toList()));
8486

85-
for (String aggName: aggNames) {
87+
for (String aggName : aggNames) {
8688
Aggregation aggResult = bucket.getAggregations().get(aggName);
8789
// This indicates not that the value contained in the `aggResult` is null, but that the `aggResult` is not
8890
// present at all in the `bucket.getAggregations`. This could occur in the case of a `bucket_selector` agg, which
@@ -112,13 +114,14 @@ static AggValueExtractor getExtractor(Aggregation aggregation) {
112114
} else {
113115
// Execution should never reach this point!
114116
// Creating transforms with unsupported aggregations shall not be possible
115-
throw new AggregationExtractionException("unsupported aggregation [{}] with name [{}]",
117+
throw new AggregationExtractionException(
118+
"unsupported aggregation [{}] with name [{}]",
116119
aggregation.getType(),
117-
aggregation.getName());
120+
aggregation.getName()
121+
);
118122
}
119123
}
120124

121-
122125
@SuppressWarnings("unchecked")
123126
static void updateDocument(Map<String, Object> document, String fieldName, Object value) {
124127
String[] fieldTokens = fieldName.split("\\.");
@@ -132,23 +135,23 @@ static void updateDocument(Map<String, Object> document, String fieldName, Objec
132135
if (i == fieldTokens.length - 1) {
133136
if (internalMap.containsKey(token)) {
134137
if (internalMap.get(token) instanceof Map) {
135-
throw new AggregationExtractionException("mixed object types of nested and non-nested fields [{}]",
136-
fieldName);
138+
throw new AggregationExtractionException("mixed object types of nested and non-nested fields [{}]", fieldName);
137139
} else {
138-
throw new AggregationExtractionException("duplicate key value pairs key [{}] old value [{}] duplicate value [{}]",
140+
throw new AggregationExtractionException(
141+
"duplicate key value pairs key [{}] old value [{}] duplicate value [{}]",
139142
fieldName,
140143
internalMap.get(token),
141-
value);
144+
value
145+
);
142146
}
143147
}
144148
internalMap.put(token, value);
145149
} else {
146150
if (internalMap.containsKey(token)) {
147151
if (internalMap.get(token) instanceof Map) {
148-
internalMap = (Map<String, Object>)internalMap.get(token);
152+
internalMap = (Map<String, Object>) internalMap.get(token);
149153
} else {
150-
throw new AggregationExtractionException("mixed object types of nested and non-nested fields [{}]",
151-
fieldName);
154+
throw new AggregationExtractionException("mixed object types of nested and non-nested fields [{}]", fieldName);
152155
}
153156
} else {
154157
Map<String, Object> newMap = new HashMap<>();
@@ -172,15 +175,14 @@ interface AggValueExtractor {
172175
static class SingleValueAggExtractor implements AggValueExtractor {
173176
@Override
174177
public Object value(Aggregation agg, String fieldType) {
175-
SingleValue aggregation = (SingleValue)agg;
178+
SingleValue aggregation = (SingleValue) agg;
176179
// If the double is invalid, this indicates sparse data
177180
if (Numbers.isValidDouble(aggregation.value()) == false) {
178181
return null;
179182
}
180183
// If the type is numeric or if the formatted string is the same as simply making the value a string,
181-
// gather the `value` type, otherwise utilize `getValueAsString` so we don't lose formatted outputs.
182-
if (isNumericType(fieldType) ||
183-
aggregation.getValueAsString().equals(String.valueOf(aggregation.value()))){
184+
// gather the `value` type, otherwise utilize `getValueAsString` so we don't lose formatted outputs.
185+
if (isNumericType(fieldType) || aggregation.getValueAsString().equals(String.valueOf(aggregation.value()))) {
184186
return aggregation.value();
185187
} else {
186188
return aggregation.getValueAsString();
@@ -191,15 +193,15 @@ public Object value(Aggregation agg, String fieldType) {
191193
static class ScriptedMetricAggExtractor implements AggValueExtractor {
192194
@Override
193195
public Object value(Aggregation agg, String fieldType) {
194-
ScriptedMetric aggregation = (ScriptedMetric)agg;
196+
ScriptedMetric aggregation = (ScriptedMetric) agg;
195197
return aggregation.aggregation();
196198
}
197199
}
198200

199201
static class GeoCentroidAggExtractor implements AggValueExtractor {
200202
@Override
201203
public Object value(Aggregation agg, String fieldType) {
202-
GeoCentroid aggregation = (GeoCentroid)agg;
204+
GeoCentroid aggregation = (GeoCentroid) agg;
203205
// if the account is `0` iff there is no contained centroid
204206
return aggregation.count() > 0 ? aggregation.centroid().toString() : null;
205207
}
@@ -208,38 +210,49 @@ public Object value(Aggregation agg, String fieldType) {
208210
static class GeoBoundsAggExtractor implements AggValueExtractor {
209211
@Override
210212
public Object value(Aggregation agg, String fieldType) {
211-
GeoBounds aggregation = (GeoBounds)agg;
213+
GeoBounds aggregation = (GeoBounds) agg;
212214
if (aggregation.bottomRight() == null || aggregation.topLeft() == null) {
213215
return null;
214216
}
215217
final Map<String, Object> geoShape = new HashMap<>();
216218
// If the two geo_points are equal, it is a point
217219
if (aggregation.topLeft().equals(aggregation.bottomRight())) {
218220
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PointBuilder.TYPE.shapeName());
219-
geoShape.put(ShapeParser.FIELD_COORDINATES.getPreferredName(),
220-
Arrays.asList(aggregation.topLeft().getLon(), aggregation.bottomRight().getLat()));
221-
// If only the lat or the lon of the two geo_points are equal, than we know it should be a line
221+
geoShape.put(
222+
ShapeParser.FIELD_COORDINATES.getPreferredName(),
223+
Arrays.asList(aggregation.topLeft().getLon(), aggregation.bottomRight().getLat())
224+
);
225+
// If only the lat or the lon of the two geo_points are equal, than we know it should be a line
222226
} else if (Double.compare(aggregation.topLeft().getLat(), aggregation.bottomRight().getLat()) == 0
223227
|| Double.compare(aggregation.topLeft().getLon(), aggregation.bottomRight().getLon()) == 0) {
224-
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), LineStringBuilder.TYPE.shapeName());
225-
geoShape.put(ShapeParser.FIELD_COORDINATES.getPreferredName(),
226-
Arrays.asList(
227-
new Double[]{aggregation.topLeft().getLon(), aggregation.topLeft().getLat()},
228-
new Double[]{aggregation.bottomRight().getLon(), aggregation.bottomRight().getLat()}));
229-
} else {
230-
// neither points are equal, we have a polygon that is a square
231-
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName());
232-
final GeoPoint tl = aggregation.topLeft();
233-
final GeoPoint br = aggregation.bottomRight();
234-
geoShape.put(ShapeParser.FIELD_COORDINATES.getPreferredName(),
235-
Collections.singletonList(Arrays.asList(
236-
new Double[]{tl.getLon(), tl.getLat()},
237-
new Double[]{br.getLon(), tl.getLat()},
238-
new Double[]{br.getLon(), br.getLat()},
239-
new Double[]{tl.getLon(), br.getLat()},
240-
new Double[]{tl.getLon(), tl.getLat()})));
241-
}
228+
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), LineStringBuilder.TYPE.shapeName());
229+
geoShape.put(
230+
ShapeParser.FIELD_COORDINATES.getPreferredName(),
231+
Arrays.asList(
232+
new Double[] { aggregation.topLeft().getLon(), aggregation.topLeft().getLat() },
233+
new Double[] { aggregation.bottomRight().getLon(), aggregation.bottomRight().getLat() }
234+
)
235+
);
236+
} else {
237+
// neither points are equal, we have a polygon that is a square
238+
geoShape.put(ShapeParser.FIELD_TYPE.getPreferredName(), PolygonBuilder.TYPE.shapeName());
239+
final GeoPoint tl = aggregation.topLeft();
240+
final GeoPoint br = aggregation.bottomRight();
241+
geoShape.put(
242+
ShapeParser.FIELD_COORDINATES.getPreferredName(),
243+
Collections.singletonList(
244+
Arrays.asList(
245+
new Double[] { tl.getLon(), tl.getLat() },
246+
new Double[] { br.getLon(), tl.getLat() },
247+
new Double[] { br.getLon(), br.getLat() },
248+
new Double[] { tl.getLon(), br.getLat() },
249+
new Double[] { tl.getLon(), tl.getLat() }
250+
)
251+
)
252+
);
253+
}
242254
return geoShape;
243255
}
244256
}
257+
245258
}

0 commit comments

Comments
 (0)