Browse Source

Fix SQLCompatIT.testCursorFromOldNodeFailsOnNewNode (#85531)

resolves #85520

The failure was caused by the assumption that groupBy queries always
return a scroll cursor that has been fixed in
https://github.com/elastic/elasticsearch/pull/84356.

Because we will run into the same problem again with 8.2.1 this fix also
needs to be backported to 8.2.
Lukas Wegmann 3 years ago
parent
commit
20f8a1fd20

+ 6 - 0
docs/changelog/85531.yaml

@@ -0,0 +1,6 @@
+pr: 85531
+summary: Fix SQLCompatIT.testCursorFromOldNodeFailsOnNewNode
+area: SQL
+type: bug
+issues:
+ - 85520

+ 9 - 5
x-pack/plugin/sql/qa/mixed-node/src/test/java/org/elasticsearch/xpack/sql/qa/mixed_node/SqlCompatIT.java

@@ -143,8 +143,11 @@ public class SqlCompatIT extends BaseRestSqlTestCase {
     }
 
     public static String sqlQueryEntityWithOptionalMode(String query, Version bwcVersion) throws IOException {
+        return sqlQueryEntityWithOptionalMode(Map.of("query", query), bwcVersion);
+    }
+
+    public static String sqlQueryEntityWithOptionalMode(Map<String, Object> fields, Version bwcVersion) throws IOException {
         XContentBuilder json = XContentFactory.jsonBuilder().startObject();
-        json.field("query", query);
         if (bwcVersion.before(Version.V_7_12_0)) {
             // a bug previous to 7.12 caused a NullPointerException when accessing displaySize in ColumnInfo. The bug has been addressed in
             // https://github.com/elastic/elasticsearch/pull/68802/files
@@ -154,12 +157,14 @@ public class SqlCompatIT extends BaseRestSqlTestCase {
             json.field("binary_format", false);
             json.field("version", bwcVersion.toString());
         }
+        for (Map.Entry<String, Object> entry : fields.entrySet()) {
+            json.field(entry.getKey(), entry.getValue());
+        }
         json.endObject();
 
         return Strings.toString(json);
     }
 
-    @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/85520")
     public void testCursorFromOldNodeFailsOnNewNode() throws IOException {
         assertCursorNotCompatibleAcrossVersions(bwcVersion, oldNodesClient, Version.CURRENT, newNodesClient);
     }
@@ -174,11 +179,10 @@ public class SqlCompatIT extends BaseRestSqlTestCase {
         indexDocs();
 
         Request req = new Request("POST", "_sql");
-        // GROUP BY queries always return a cursor
-        req.setJsonEntity(sqlQueryEntityWithOptionalMode("SELECT int FROM test GROUP BY 1", bwcVersion));
+        req.setJsonEntity(sqlQueryEntityWithOptionalMode(Map.of("query", "SELECT int FROM test", "fetch_size", 1), bwcVersion));
         Map<String, Object> json = performRequestAndReadBodyAsJson(client1, req);
         String cursor = (String) json.get("cursor");
-        assertThat(cursor, Matchers.not(Matchers.emptyString()));
+        assertThat(cursor, Matchers.not(Matchers.emptyOrNullString()));
 
         Request scrollReq = new Request("POST", "_sql");
         scrollReq.setJsonEntity("{\"cursor\": \"%s\"}".formatted(cursor));