2424public 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,41 @@ 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+ );
206+ }
207+
208+ public void testAggNameValidationsWithInvalidFieldnames () {
209+ List <String > failures = PivotConfig .aggFieldValidation (Arrays .asList (".at_start" , "at_end." , ".start_and_end." ));
210+
211+ assertThat (
212+ failures ,
213+ containsInAnyOrder (
214+ "field [.at_start] must not start with '.'" ,
215+ "field [at_end.] must not end with '.'" ,
216+ "field [.start_and_end.] must not start with '.'" ,
217+ "field [.start_and_end.] must not end with '.'"
218+ )
219+ );
206220 }
207221
208222 private static String dotJoin (String ... fields ) {
209223 return Strings .arrayToDelimitedString (fields , "." );
210224 }
211225
212226 private PivotConfig createPivotConfigFromString (String json , boolean lenient ) throws IOException {
213- final XContentParser parser = XContentType .JSON .xContent (). createParser ( xContentRegistry (),
214- DeprecationHandler .THROW_UNSUPPORTED_OPERATION , json );
227+ final XContentParser parser = XContentType .JSON .xContent ()
228+ . createParser ( xContentRegistry (), DeprecationHandler .THROW_UNSUPPORTED_OPERATION , json );
215229 return PivotConfig .fromXContent (parser , lenient );
216230 }
217231}
0 commit comments