4444import static org .hamcrest .Matchers .containsString ;
4545import static org .hamcrest .Matchers .equalTo ;
4646import static org .hamcrest .Matchers .greaterThan ;
47- import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
4847import static org .hamcrest .Matchers .hasItem ;
4948import static org .hamcrest .Matchers .instanceOf ;
5049import static org .hamcrest .Matchers .not ;
@@ -80,12 +79,10 @@ public void testBasicEsql() throws IOException {
8079 builder .pragmas (Settings .builder ().put ("data_partitioning" , "shard" ).build ());
8180 }
8281 Map <String , Object > result = runEsql (builder );
83- assertEquals ( 3 , result . size ());
82+
8483 Map <String , String > colA = Map .of ("name" , "avg(value)" , "type" , "double" );
85- assertEquals (List .of (colA ), result .get ("columns" ));
86- assertEquals (List .of (List .of (499.5d )), result .get ("values" ));
84+ assertResultMap (result , colA , List .of (List .of (499.5d )));
8785 assertTrue (result .containsKey ("took" ));
88- assertThat (((Number ) result .get ("took" )).longValue (), greaterThanOrEqualTo (0L ));
8986 }
9087
9188 public void testInvalidPragma () throws IOException {
@@ -118,11 +115,8 @@ public void testDoNotLogWithInfo() throws IOException {
118115 setLoggingLevel ("INFO" );
119116 RequestObjectBuilder builder = requestObjectBuilder ().query ("ROW DO_NOT_LOG_ME = 1" );
120117 Map <String , Object > result = runEsql (builder );
121- assertEquals (3 , result .size ());
122- assertThat (((Integer ) result .get ("took" )).intValue (), greaterThanOrEqualTo (0 ));
123118 Map <String , String > colA = Map .of ("name" , "DO_NOT_LOG_ME" , "type" , "integer" );
124- assertEquals (List .of (colA ), result .get ("columns" ));
125- assertEquals (List .of (List .of (1 )), result .get ("values" ));
119+ assertResultMap (result , colA , List .of (List .of (1 )));
126120 for (int i = 0 ; i < cluster .getNumNodes (); i ++) {
127121 try (InputStream log = cluster .getNodeLog (i , LogType .SERVER )) {
128122 Streams .readAllLines (log , line -> assertThat (line , not (containsString ("DO_NOT_LOG_ME" ))));
@@ -138,11 +132,8 @@ public void testDoLogWithDebug() throws IOException {
138132 setLoggingLevel ("DEBUG" );
139133 RequestObjectBuilder builder = requestObjectBuilder ().query ("ROW DO_LOG_ME = 1" );
140134 Map <String , Object > result = runEsql (builder );
141- assertEquals (3 , result .size ());
142- assertThat (((Integer ) result .get ("took" )).intValue (), greaterThanOrEqualTo (0 ));
143135 Map <String , String > colA = Map .of ("name" , "DO_LOG_ME" , "type" , "integer" );
144- assertEquals (List .of (colA ), result .get ("columns" ));
145- assertEquals (List .of (List .of (1 )), result .get ("values" ));
136+ assertResultMap (result , colA , List .of (List .of (1 )));
146137 boolean [] found = new boolean [] { false };
147138 for (int i = 0 ; i < cluster .getNumNodes (); i ++) {
148139 try (InputStream log = cluster .getNodeLog (i , LogType .SERVER )) {
@@ -289,13 +280,11 @@ public void testProfile() throws IOException {
289280 builder .pragmas (Settings .builder ().put ("data_partitioning" , "shard" ).build ());
290281 }
291282 Map <String , Object > result = runEsql (builder );
292- MapMatcher mapMatcher = matchesMap ();
293- assertMap (
283+ assertResultMap (
294284 result ,
295- mapMatcher .entry ("columns" , matchesList ().item (matchesMap ().entry ("name" , "AVG(value)" ).entry ("type" , "double" )))
296- .entry ("values" , List .of (List .of (499.5d )))
297- .entry ("profile" , matchesMap ().entry ("drivers" , instanceOf (List .class )))
298- .entry ("took" , greaterThanOrEqualTo (0 ))
285+ getResultMatcher (result ).entry ("profile" , matchesMap ().entry ("drivers" , instanceOf (List .class ))),
286+ matchesList ().item (matchesMap ().entry ("name" , "AVG(value)" ).entry ("type" , "double" )),
287+ equalTo (List .of (List .of (499.5d )))
299288 );
300289
301290 List <List <String >> signatures = new ArrayList <>();
@@ -373,24 +362,19 @@ public void testInlineStatsProfile() throws IOException {
373362 }
374363
375364 Map <String , Object > result = runEsql (builder );
376- MapMatcher mapMatcher = matchesMap ();
377365 ListMatcher values = matchesList ();
378366 for (int i = 0 ; i < 1000 ; i ++) {
379367 values = values .item (matchesList ().item ("2020-12-12T00:00:00.000Z" ).item ("value" + i ).item ("value" + i ).item (i ).item (499.5 ));
380368 }
381- assertMap (
369+ assertResultMap (
382370 result ,
383- mapMatcher .entry (
384- "columns" ,
385- matchesList ().item (matchesMap ().entry ("name" , "@timestamp" ).entry ("type" , "date" ))
386- .item (matchesMap ().entry ("name" , "test" ).entry ("type" , "text" ))
387- .item (matchesMap ().entry ("name" , "test.keyword" ).entry ("type" , "keyword" ))
388- .item (matchesMap ().entry ("name" , "value" ).entry ("type" , "long" ))
389- .item (matchesMap ().entry ("name" , "AVG(value)" ).entry ("type" , "double" ))
390- )
391- .entry ("values" , values )
392- .entry ("profile" , matchesMap ().entry ("drivers" , instanceOf (List .class )))
393- .entry ("took" , greaterThanOrEqualTo (0 ))
371+ getResultMatcher (result ).entry ("profile" , matchesMap ().entry ("drivers" , instanceOf (List .class ))),
372+ matchesList ().item (matchesMap ().entry ("name" , "@timestamp" ).entry ("type" , "date" ))
373+ .item (matchesMap ().entry ("name" , "test" ).entry ("type" , "text" ))
374+ .item (matchesMap ().entry ("name" , "test.keyword" ).entry ("type" , "keyword" ))
375+ .item (matchesMap ().entry ("name" , "value" ).entry ("type" , "long" ))
376+ .item (matchesMap ().entry ("name" , "AVG(value)" ).entry ("type" , "double" )),
377+ values
394378 );
395379
396380 List <List <String >> signatures = new ArrayList <>();
@@ -484,20 +468,15 @@ public void testForceSleepsProfile() throws IOException {
484468 for (int group2 = 0 ; group2 < 10 ; group2 ++) {
485469 expectedValues .add (List .of (1.0 , 1 , 1 , 0 , group2 ));
486470 }
487- MapMatcher mapMatcher = matchesMap ();
488- assertMap (
471+ assertResultMap (
489472 result ,
490- mapMatcher .entry (
491- "columns" ,
492- matchesList ().item (matchesMap ().entry ("name" , "AVG(value)" ).entry ("type" , "double" ))
493- .item (matchesMap ().entry ("name" , "MAX(value)" ).entry ("type" , "long" ))
494- .item (matchesMap ().entry ("name" , "MIN(value)" ).entry ("type" , "long" ))
495- .item (matchesMap ().entry ("name" , "group1" ).entry ("type" , "long" ))
496- .item (matchesMap ().entry ("name" , "group2" ).entry ("type" , "long" ))
497- )
498- .entry ("values" , expectedValues )
499- .entry ("profile" , matchesMap ().entry ("drivers" , instanceOf (List .class )))
500- .entry ("took" , greaterThanOrEqualTo (0 ))
473+ getResultMatcher (result ).entry ("profile" , matchesMap ().entry ("drivers" , instanceOf (List .class ))),
474+ matchesList ().item (matchesMap ().entry ("name" , "AVG(value)" ).entry ("type" , "double" ))
475+ .item (matchesMap ().entry ("name" , "MAX(value)" ).entry ("type" , "long" ))
476+ .item (matchesMap ().entry ("name" , "MIN(value)" ).entry ("type" , "long" ))
477+ .item (matchesMap ().entry ("name" , "group1" ).entry ("type" , "long" ))
478+ .item (matchesMap ().entry ("name" , "group2" ).entry ("type" , "long" )),
479+ equalTo (expectedValues )
501480 );
502481
503482 @ SuppressWarnings ("unchecked" )
0 commit comments