24
24
public class PivotConfigTests extends AbstractSerializingTransformTestCase <PivotConfig > {
25
25
26
26
public static PivotConfig randomPivotConfig () {
27
- return new PivotConfig (GroupConfigTests .randomGroupConfig (),
27
+ return new PivotConfig (
28
+ GroupConfigTests .randomGroupConfig (),
28
29
AggregationConfigTests .randomAggregationConfig (),
29
- randomBoolean () ? null : randomIntBetween (10 , 10_000 ));
30
+ randomBoolean () ? null : randomIntBetween (10 , 10_000 )
31
+ );
30
32
}
31
33
32
34
public static PivotConfig randomInvalidPivotConfig () {
33
- return new PivotConfig (GroupConfigTests .randomGroupConfig (),
35
+ return new PivotConfig (
36
+ GroupConfigTests .randomGroupConfig (),
34
37
AggregationConfigTests .randomInvalidAggregationConfig (),
35
- randomBoolean () ? null : randomIntBetween (10 , 10_000 ));
38
+ randomBoolean () ? null : randomIntBetween (10 , 10_000 )
39
+ );
36
40
}
37
41
38
42
@ Override
@@ -52,44 +56,39 @@ protected Reader<PivotConfig> instanceReader() {
52
56
53
57
public void testAggsAbbreviations () throws IOException {
54
58
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
+ + "} } } }" ;
65
69
66
70
PivotConfig p1 = createPivotConfigFromString (pivotAggs , false );
67
71
String pivotAggregations = pivotAggs .replace ("aggs" , "aggregations" );
68
72
assertNotEquals (pivotAggs , pivotAggregations );
69
73
PivotConfig p2 = createPivotConfigFromString (pivotAggregations , false );
70
- assertEquals (p1 ,p2 );
74
+ assertEquals (p1 , p2 );
71
75
}
72
76
73
77
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\" " + "} } } }" ;
80
79
81
80
expectThrows (IllegalArgumentException .class , () -> createPivotConfigFromString (pivot , false ));
82
81
}
83
82
84
83
public void testEmptyAggs () throws IOException {
85
84
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
+ + " }" ;
93
92
94
93
expectThrows (IllegalArgumentException .class , () -> createPivotConfigFromString (pivot , false ));
95
94
@@ -100,12 +99,12 @@ public void testEmptyAggs() throws IOException {
100
99
101
100
public void testEmptyGroupBy () throws IOException {
102
101
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
+ + "} } } }" ;
109
108
110
109
expectThrows (IllegalArgumentException .class , () -> createPivotConfigFromString (pivot , false ));
111
110
@@ -115,34 +114,29 @@ public void testEmptyGroupBy() throws IOException {
115
114
}
116
115
117
116
public void testMissingGroupBy () {
118
- String pivot = "{"
119
- + " \" aggs\" : {"
120
- + " \" avg\" : {"
121
- + " \" avg\" : {"
122
- + " \" field\" : \" points\" "
123
- + "} } } }" ;
117
+ String pivot = "{" + " \" aggs\" : {" + " \" avg\" : {" + " \" avg\" : {" + " \" field\" : \" points\" " + "} } } }" ;
124
118
125
119
expectThrows (IllegalArgumentException .class , () -> createPivotConfigFromString (pivot , false ));
126
120
}
127
121
128
122
public void testDoubleAggs () {
129
123
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
+ + "}" ;
146
140
147
141
expectThrows (IllegalArgumentException .class , () -> createPivotConfigFromString (pivot , false ));
148
142
}
@@ -171,17 +165,17 @@ public void testAggNameValidationsWithoutIssues() {
171
165
String nestedField1 = randomAlphaOfLength (10 ) + "3" ;
172
166
String nestedField2 = randomAlphaOfLength (10 ) + "4" ;
173
167
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
+ );
178
172
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
+ );
185
179
}
186
180
187
181
public void testAggNameValidationsWithDuplicatesAndNestingIssues () {
@@ -197,21 +191,27 @@ public void testAggNameValidationsWithDuplicatesAndNestingIssues() {
197
191
dotJoin (prefix , nestedField1 ),
198
192
dotJoin (prefix2 , nestedField1 ),
199
193
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" ,
204
202
"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
+ );
206
206
}
207
207
208
208
private static String dotJoin (String ... fields ) {
209
209
return Strings .arrayToDelimitedString (fields , "." );
210
210
}
211
211
212
212
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 );
215
215
return PivotConfig .fromXContent (parser , lenient );
216
216
}
217
217
}
0 commit comments