Skip to content

Commit f74663f

Browse files
author
Hendrik Muhs
committed
code formating
1 parent 589e033 commit f74663f

File tree

2 files changed

+99
-102
lines changed
  • x-pack/plugin/core/src

2 files changed

+99
-102
lines changed

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,30 @@ public class PivotConfig implements Writeable, ToXContentObject {
4242
private static final ConstructingObjectParser<PivotConfig, Void> LENIENT_PARSER = createParser(true);
4343

4444
private static ConstructingObjectParser<PivotConfig, Void> createParser(boolean lenient) {
45-
ConstructingObjectParser<PivotConfig, Void> parser = new ConstructingObjectParser<>(NAME, lenient,
46-
args -> {
47-
GroupConfig groups = (GroupConfig) args[0];
48-
49-
// allow "aggs" and "aggregations" but require one to be specified
50-
// if somebody specifies both: throw
51-
AggregationConfig aggregationConfig = null;
52-
if (args[1] != null) {
53-
aggregationConfig = (AggregationConfig) args[1];
54-
}
55-
56-
if (args[2] != null) {
57-
if (aggregationConfig != null) {
58-
throw new IllegalArgumentException("Found two aggregation definitions: [aggs] and [aggregations]");
59-
}
60-
aggregationConfig = (AggregationConfig) args[2];
61-
}
62-
if (aggregationConfig == null) {
63-
throw new IllegalArgumentException("Required [aggregations]");
64-
}
65-
66-
return new PivotConfig(groups, aggregationConfig, (Integer)args[3]);
67-
});
68-
69-
parser.declareObject(constructorArg(),
70-
(p, c) -> (GroupConfig.fromXContent(p, lenient)), TransformField.GROUP_BY);
45+
ConstructingObjectParser<PivotConfig, Void> parser = new ConstructingObjectParser<>(NAME, lenient, args -> {
46+
GroupConfig groups = (GroupConfig) args[0];
47+
48+
// allow "aggs" and "aggregations" but require one to be specified
49+
// if somebody specifies both: throw
50+
AggregationConfig aggregationConfig = null;
51+
if (args[1] != null) {
52+
aggregationConfig = (AggregationConfig) args[1];
53+
}
54+
55+
if (args[2] != null) {
56+
if (aggregationConfig != null) {
57+
throw new IllegalArgumentException("Found two aggregation definitions: [aggs] and [aggregations]");
58+
}
59+
aggregationConfig = (AggregationConfig) args[2];
60+
}
61+
if (aggregationConfig == null) {
62+
throw new IllegalArgumentException("Required [aggregations]");
63+
}
64+
65+
return new PivotConfig(groups, aggregationConfig, (Integer) args[3]);
66+
});
67+
68+
parser.declareObject(constructorArg(), (p, c) -> (GroupConfig.fromXContent(p, lenient)), TransformField.GROUP_BY);
7169

7270
parser.declareObject(optionalConstructorArg(), (p, c) -> AggregationConfig.fromXContent(p, lenient), TransformField.AGGREGATIONS);
7371
parser.declareObject(optionalConstructorArg(), (p, c) -> AggregationConfig.fromXContent(p, lenient), TransformField.AGGS);
@@ -206,17 +204,16 @@ static List<String> aggFieldValidation(List<String> usedNames) {
206204

207205
usedNames.sort(String::compareTo);
208206
for (int i = 0; i < usedNames.size() - 1; i++) {
209-
if (usedNames.get(i+1).startsWith(usedNames.get(i) + ".")) {
207+
if (usedNames.get(i + 1).startsWith(usedNames.get(i) + ".")) {
210208
validationFailures.add("field [" + usedNames.get(i) + "] cannot be both an object and a field");
211209
}
212-
if (usedNames.get(i+1).equals(usedNames.get(i))) {
210+
if (usedNames.get(i + 1).equals(usedNames.get(i))) {
213211
validationFailures.add("duplicate field [" + usedNames.get(i) + "] detected");
214212
}
215213
}
216214
return validationFailures;
217215
}
218216

219-
220217
private static void addAggNames(AggregationBuilder aggregationBuilder, Collection<String> names) {
221218
names.add(aggregationBuilder.getName());
222219
aggregationBuilder.getSubAggregations().forEach(agg -> addAggNames(agg, names));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/transforms/pivot/PivotConfigTests.java

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424
public class PivotConfigTests extends AbstractSerializingTransformTestCase<PivotConfig> {
2525

2626
public static PivotConfig randomPivotConfig() {
27-
return new PivotConfig(GroupConfigTests.randomGroupConfig(),
27+
return new PivotConfig(
28+
GroupConfigTests.randomGroupConfig(),
2829
AggregationConfigTests.randomAggregationConfig(),
29-
randomBoolean() ? null : randomIntBetween(10, 10_000));
30+
randomBoolean() ? null : randomIntBetween(10, 10_000)
31+
);
3032
}
3133

3234
public static PivotConfig randomInvalidPivotConfig() {
33-
return new PivotConfig(GroupConfigTests.randomGroupConfig(),
35+
return new PivotConfig(
36+
GroupConfigTests.randomGroupConfig(),
3437
AggregationConfigTests.randomInvalidAggregationConfig(),
35-
randomBoolean() ? null : randomIntBetween(10, 10_000));
38+
randomBoolean() ? null : randomIntBetween(10, 10_000)
39+
);
3640
}
3741

3842
@Override
@@ -52,44 +56,39 @@ protected Reader<PivotConfig> instanceReader() {
5256

5357
public void testAggsAbbreviations() throws IOException {
5458
String pivotAggs = "{"
55-
+ " \"group_by\": {"
56-
+ " \"id\": {"
57-
+ " \"terms\": {"
58-
+ " \"field\": \"id\""
59-
+ "} } },"
60-
+ " \"aggs\": {"
61-
+ " \"avg\": {"
62-
+ " \"avg\": {"
63-
+ " \"field\": \"points\""
64-
+ "} } } }";
59+
+ " \"group_by\": {"
60+
+ " \"id\": {"
61+
+ " \"terms\": {"
62+
+ " \"field\": \"id\""
63+
+ "} } },"
64+
+ " \"aggs\": {"
65+
+ " \"avg\": {"
66+
+ " \"avg\": {"
67+
+ " \"field\": \"points\""
68+
+ "} } } }";
6569

6670
PivotConfig p1 = createPivotConfigFromString(pivotAggs, false);
6771
String pivotAggregations = pivotAggs.replace("aggs", "aggregations");
6872
assertNotEquals(pivotAggs, pivotAggregations);
6973
PivotConfig p2 = createPivotConfigFromString(pivotAggregations, false);
70-
assertEquals(p1,p2);
74+
assertEquals(p1, p2);
7175
}
7276

7377
public void testMissingAggs() throws IOException {
74-
String pivot = "{"
75-
+ " \"group_by\": {"
76-
+ " \"id\": {"
77-
+ " \"terms\": {"
78-
+ " \"field\": \"id\""
79-
+ "} } } }";
78+
String pivot = "{" + " \"group_by\": {" + " \"id\": {" + " \"terms\": {" + " \"field\": \"id\"" + "} } } }";
8079

8180
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
8281
}
8382

8483
public void testEmptyAggs() throws IOException {
8584
String pivot = "{"
86-
+ " \"group_by\": {"
87-
+ " \"id\": {"
88-
+ " \"terms\": {"
89-
+ " \"field\": \"id\""
90-
+ "} } },"
91-
+ "\"aggs\": {}"
92-
+ " }";
85+
+ " \"group_by\": {"
86+
+ " \"id\": {"
87+
+ " \"terms\": {"
88+
+ " \"field\": \"id\""
89+
+ "} } },"
90+
+ "\"aggs\": {}"
91+
+ " }";
9392

9493
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
9594

@@ -100,12 +99,12 @@ public void testEmptyAggs() throws IOException {
10099

101100
public void testEmptyGroupBy() throws IOException {
102101
String pivot = "{"
103-
+ " \"group_by\": {},"
104-
+ " \"aggs\": {"
105-
+ " \"avg\": {"
106-
+ " \"avg\": {"
107-
+ " \"field\": \"points\""
108-
+ "} } } }";
102+
+ " \"group_by\": {},"
103+
+ " \"aggs\": {"
104+
+ " \"avg\": {"
105+
+ " \"avg\": {"
106+
+ " \"field\": \"points\""
107+
+ "} } } }";
109108

110109
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
111110

@@ -115,34 +114,29 @@ public void testEmptyGroupBy() throws IOException {
115114
}
116115

117116
public void testMissingGroupBy() {
118-
String pivot = "{"
119-
+ " \"aggs\": {"
120-
+ " \"avg\": {"
121-
+ " \"avg\": {"
122-
+ " \"field\": \"points\""
123-
+ "} } } }";
117+
String pivot = "{" + " \"aggs\": {" + " \"avg\": {" + " \"avg\": {" + " \"field\": \"points\"" + "} } } }";
124118

125119
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
126120
}
127121

128122
public void testDoubleAggs() {
129123
String pivot = "{"
130-
+ " \"group_by\": {"
131-
+ " \"id\": {"
132-
+ " \"terms\": {"
133-
+ " \"field\": \"id\""
134-
+ "} } },"
135-
+ " \"aggs\": {"
136-
+ " \"avg\": {"
137-
+ " \"avg\": {"
138-
+ " \"field\": \"points\""
139-
+ "} } },"
140-
+ " \"aggregations\": {"
141-
+ " \"avg\": {"
142-
+ " \"avg\": {"
143-
+ " \"field\": \"points\""
144-
+ "} } }"
145-
+ "}";
124+
+ " \"group_by\": {"
125+
+ " \"id\": {"
126+
+ " \"terms\": {"
127+
+ " \"field\": \"id\""
128+
+ "} } },"
129+
+ " \"aggs\": {"
130+
+ " \"avg\": {"
131+
+ " \"avg\": {"
132+
+ " \"field\": \"points\""
133+
+ "} } },"
134+
+ " \"aggregations\": {"
135+
+ " \"avg\": {"
136+
+ " \"avg\": {"
137+
+ " \"field\": \"points\""
138+
+ "} } }"
139+
+ "}";
146140

147141
expectThrows(IllegalArgumentException.class, () -> createPivotConfigFromString(pivot, false));
148142
}
@@ -171,17 +165,17 @@ public void testAggNameValidationsWithoutIssues() {
171165
String nestedField1 = randomAlphaOfLength(10) + "3";
172166
String nestedField2 = randomAlphaOfLength(10) + "4";
173167

174-
assertThat(PivotConfig.aggFieldValidation(Arrays.asList(prefix + nestedField1 + nestedField2,
175-
prefix + nestedField1,
176-
prefix,
177-
prefix2)), is(empty()));
168+
assertThat(
169+
PivotConfig.aggFieldValidation(Arrays.asList(prefix + nestedField1 + nestedField2, prefix + nestedField1, prefix, prefix2)),
170+
is(empty())
171+
);
178172

179-
assertThat(PivotConfig.aggFieldValidation(
180-
Arrays.asList(
181-
dotJoin(prefix, nestedField1, nestedField2),
182-
dotJoin(nestedField1, nestedField2),
183-
nestedField2,
184-
prefix2)), is(empty()));
173+
assertThat(
174+
PivotConfig.aggFieldValidation(
175+
Arrays.asList(dotJoin(prefix, nestedField1, nestedField2), dotJoin(nestedField1, nestedField2), nestedField2, prefix2)
176+
),
177+
is(empty())
178+
);
185179
}
186180

187181
public void testAggNameValidationsWithDuplicatesAndNestingIssues() {
@@ -197,21 +191,27 @@ public void testAggNameValidationsWithDuplicatesAndNestingIssues() {
197191
dotJoin(prefix, nestedField1),
198192
dotJoin(prefix2, nestedField1),
199193
dotJoin(prefix2, nestedField1),
200-
prefix2));
201-
202-
assertThat(failures,
203-
containsInAnyOrder("duplicate field [" + dotJoin(prefix2, nestedField1) + "] detected",
194+
prefix2
195+
)
196+
);
197+
198+
assertThat(
199+
failures,
200+
containsInAnyOrder(
201+
"duplicate field [" + dotJoin(prefix2, nestedField1) + "] detected",
204202
"field [" + prefix2 + "] cannot be both an object and a field",
205-
"field [" + dotJoin(prefix, nestedField1) + "] cannot be both an object and a field"));
203+
"field [" + dotJoin(prefix, nestedField1) + "] cannot be both an object and a field"
204+
)
205+
);
206206
}
207207

208208
private static String dotJoin(String... fields) {
209209
return Strings.arrayToDelimitedString(fields, ".");
210210
}
211211

212212
private PivotConfig createPivotConfigFromString(String json, boolean lenient) throws IOException {
213-
final XContentParser parser = XContentType.JSON.xContent().createParser(xContentRegistry(),
214-
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
213+
final XContentParser parser = XContentType.JSON.xContent()
214+
.createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
215215
return PivotConfig.fromXContent(parser, lenient);
216216
}
217217
}

0 commit comments

Comments
 (0)