3838import static java .util .Collections .unmodifiableMap ;
3939import static org .elasticsearch .xpack .ql .TestUtils .buildNodeAndVersions ;
4040import static org .elasticsearch .xpack .ql .TestUtils .readResource ;
41- import static org .elasticsearch .xpack .ql .execution .search .QlSourceBuilder .SWITCH_TO_FIELDS_API_VERSION ;
4241
4342public class SqlSearchIT extends ESRestTestCase {
4443
@@ -56,9 +55,7 @@ public class SqlSearchIT extends ESRestTestCase {
5655 private static List <TestNode > newNodes ;
5756 private static List <TestNode > bwcNodes ;
5857 private static Version bwcVersion ;
59- private static Version newVersion ;
6058 private static boolean isBwcNodeBeforeFieldsApiInQL ;
61- private static boolean isBwcNodeBeforeFieldsApiInES ;
6259 private static boolean halfFloatMightReturnFullFloatPrecision ;
6360
6461 @ Before
@@ -69,9 +66,7 @@ public void createIndex() throws IOException {
6966 newNodes = new ArrayList <>(nodes .getNewNodes ());
7067 bwcNodes = new ArrayList <>(nodes .getBWCNodes ());
7168 bwcVersion = nodes .getBWCNodes ().get (0 ).getVersion ();
72- newVersion = nodes .getNewNodes ().get (0 ).getVersion ();
7369 isBwcNodeBeforeFieldsApiInQL = bwcVersion .before (FIELDS_API_QL_INTRODUCTION );
74- isBwcNodeBeforeFieldsApiInES = bwcVersion .before (SWITCH_TO_FIELDS_API_VERSION );
7570 halfFloatMightReturnFullFloatPrecision = bwcVersion .before (Version .V_7_13_0 );
7671
7772 String mappings = readResource (SqlSearchIT .class .getResourceAsStream ("/all_field_types.json" ));
@@ -150,7 +145,6 @@ public void testAllTypesWithRequestToOldNodes() throws Exception {
150145 assertAllTypesWithNodes (expectedResponse , bwcNodes );
151146 }
152147
153- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/78424" )
154148 public void testAllTypesWithRequestToUpgradedNodes () throws Exception {
155149 Map <String , Object > expectedResponse = prepareTestData (
156150 columns -> {
@@ -162,14 +156,14 @@ public void testAllTypesWithRequestToUpgradedNodes() throws Exception {
162156 * that version we don't fetch the half float because we
163157 * can't make any assertions about it.
164158 */
165- if (isBwcNodeBeforeFieldsApiInQL && isBwcNodeBeforeFieldsApiInES || false == halfFloatMightReturnFullFloatPrecision ) {
159+ if (isBwcNodeBeforeFieldsApiInQL || false == halfFloatMightReturnFullFloatPrecision ) {
166160 columns .add (columnInfo ("half_float_field" , "half_float" ));
167161 }
168162 },
169163 (builder , fieldValues ) -> {
170164 Float randomFloat = randomFloat ();
171165 builder .append ("," );
172- if (isBwcNodeBeforeFieldsApiInQL && isBwcNodeBeforeFieldsApiInES ) {
166+ if (isBwcNodeBeforeFieldsApiInQL ) {
173167 builder .append ("\" geo_point_field\" :{\" lat\" :\" 37.386483\" , \" lon\" :\" -122.083843\" }," );
174168 fieldValues .put ("geo_point_field" , "POINT (-122.08384302444756 37.38648299127817)" );
175169 builder .append ("\" float_field\" :" + randomFloat + "," );
@@ -291,20 +285,38 @@ private void assertAllTypesWithNodes(Map<String, Object> expectedResponse, List<
291285 ) {
292286 @ SuppressWarnings ("unchecked" )
293287 List <Map <String , Object >> columns = (List <Map <String , Object >>) expectedResponse .get ("columns" );
288+
294289 String intervalYearMonth = "INTERVAL '150' YEAR AS interval_year, " ;
295290 String intervalDayTime = "INTERVAL '163' MINUTE AS interval_minute, " ;
296-
297291 // get all fields names from the expected response built earlier, skipping the intervals as they execute locally
298292 // and not taken from the index itself
299- String fieldsList = columns .stream ().map (m -> (String ) m .get ("name" )).filter (str -> str .startsWith ("interval" ) == false )
300- .collect (Collectors .toList ()).stream ().collect (Collectors .joining (", " ));
293+ String fieldsList = columns .stream ()
294+ .map (m -> (String ) m .get ("name" ))
295+ .filter (str -> str .startsWith ("interval" ) == false )
296+ .collect (Collectors .toList ())
297+ .stream ()
298+ .collect (Collectors .joining (", " ));
301299 String query = "SELECT " + intervalYearMonth + intervalDayTime + fieldsList + " FROM " + index + " ORDER BY id" ;
300+
302301 Request request = new Request ("POST" , "_sql" );
303- request .setJsonEntity ("{\" query\" :\" " + query + "\" }" );
304- assertBusy (() -> { assertResponse (expectedResponse , runSql (client , request )); });
302+ request .setJsonEntity (SqlCompatIT .sqlQueryEntityWithOptionalMode (query , bwcVersion ));
303+ assertBusy (() -> {
304+ assertResponse (expectedResponse , dropDisplaySizes (runSql (client , request )));
305+ });
305306 }
306307 }
307308
309+ private Map <String , Object > dropDisplaySizes (Map <String , Object > response ) {
310+ // in JDBC mode, display_size will be part of the response, so remove it because it's not part of the expected response
311+ @ SuppressWarnings ("unchecked" )
312+ List <Map <String , Object >> columns = (List <Map <String , Object >>) response .get ("columns" );
313+ List <Map <String , Object >> columnsWithoutDisplaySizes = columns .stream ()
314+ .peek (column -> column .remove ("display_size" ))
315+ .collect (Collectors .toList ());
316+ response .put ("columns" , columnsWithoutDisplaySizes );
317+ return response ;
318+ }
319+
308320 private void assertResponse (Map <String , Object > expected , Map <String , Object > actual ) {
309321 if (false == expected .equals (actual )) {
310322 NotEqualMessageBuilder message = new NotEqualMessageBuilder ();
0 commit comments