99
1010import com .carrotsearch .randomizedtesting .annotations .ThreadLeakFilters ;
1111
12+ import org .apache .http .util .EntityUtils ;
1213import org .elasticsearch .client .Request ;
14+ import org .elasticsearch .client .Response ;
1315import org .elasticsearch .client .ResponseException ;
1416import org .elasticsearch .test .TestClustersThreadFilter ;
1517import org .elasticsearch .test .cluster .ElasticsearchCluster ;
1618import org .elasticsearch .test .cluster .local .distribution .DistributionType ;
1719import org .elasticsearch .test .rest .ESRestTestCase ;
1820import org .junit .ClassRule ;
1921
22+ import javax .swing .text .html .parser .Entity ;
23+
2024import java .io .IOException ;
2125
26+ import static org .hamcrest .Matchers .containsString ;
2227import static org .hamcrest .Matchers .equalTo ;
2328
2429@ ThreadLeakFilters (filters = TestClustersThreadFilter .class )
@@ -32,15 +37,42 @@ public class ExtraCheckersIT extends ESRestTestCase {
3237 .plugin ("extra-checkers" )
3338 .build ();
3439
35- public void testIncludesCategorize () throws IOException {
36- Request request = new Request ("POST" , "/_query" );
37- request .setJsonEntity ("""
40+ public void testWithCategorize () {
41+ ResponseException e = expectThrows (ResponseException .class , () -> runEsql ("""
42+ {
43+ "query": "ROW message=\\ "foo bar\\ " | STATS COUNT(*) BY CATEGORIZE(message) | LIMIT 1"
44+ }""" ));
45+ assertThat (e .getResponse ().getStatusLine ().getStatusCode (), equalTo (400 ));
46+ assertThat (e .getMessage (), containsString ("line 1:43: CATEGORIZE is unsupported" ));
47+ }
48+
49+ public void testWithoutCategorize () throws IOException {
50+ String result = runEsql ("""
3851 {
39- "query": "ROW message=\\ "foo bar\\ " | STATS COUNT(*) BY CATEGORIZE(message) "
52+ "query": "ROW message=\\ "foo bar\\ " | STATS COUNT(*) | LIMIT 1 "
4053 }""" );
54+ assertThat (result , containsString ("""
55+ "columns" : [
56+ {
57+ "name" : "COUNT(*)",
58+ "type" : "long"
59+ }
60+ ],
61+ "values" : [
62+ [
63+ 1
64+ ]
65+ ]
66+ """ ));
67+ }
68+
69+ private String runEsql (String json ) throws IOException {
70+ Request request = new Request ("POST" , "/_query" );
71+ request .setJsonEntity (json );
4172 request .addParameter ("error_trace" , "" );
42- Exception e = expectThrows (ResponseException .class , () -> client ().performRequest (request ));
43- assertThat (e .getMessage (), equalTo ("ADFSADF" ));
73+ request .addParameter ("pretty" , "" );
74+ Response response = client ().performRequest (request );
75+ return EntityUtils .toString (response .getEntity ());
4476 }
4577
4678 @ Override
0 commit comments