Skip to content

Commit 2e634a4

Browse files
Fix the flaky CalcitePPLTcphIT (#4846)
Signed-off-by: Lantao Jin <ltjin@amazon.com> (cherry picked from commit c0f5680) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 08c113e commit 2e634a4

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/tpch/CalcitePPLTpchIT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.json.JSONObject;
2020
import org.junit.Assume;
21-
import org.junit.Ignore;
2221
import org.junit.Test;
2322
import org.opensearch.sql.ppl.PPLIntegTestCase;
2423
import org.opensearch.sql.util.Retry;
@@ -144,21 +143,19 @@ public void testQ3() throws IOException {
144143
rows(4423, 3055.9365, "1995-02-17 00:00:00", 0));
145144
}
146145

147-
// TODO: Aggregation push down has a hard-coded limit of 1000 buckets for output, so this query
148-
// will not return the correct results with aggregation push down and it's unstable
149-
@Ignore
146+
@Test
150147
public void testQ4() throws IOException {
151148
String ppl = sanitize(loadFromFile("tpch/queries/q4.ppl"));
152149
JSONObject actual = executeQuery(ppl);
153150
verifySchemaInOrder(
154151
actual, schema("o_orderpriority", "string"), schema("order_count", "bigint"));
155152
verifyDataRows(
156153
actual,
157-
rows("1-URGENT", 7),
154+
rows("1-URGENT", 9),
158155
rows("2-HIGH", 7),
159-
rows("3-MEDIUM", 4),
160-
rows("4-NOT SPECIFIED", 7),
161-
rows("5-LOW", 10));
156+
rows("3-MEDIUM", 9),
157+
rows("4-NOT SPECIFIED", 8),
158+
rows("5-LOW", 12));
162159
}
163160

164161
@Test

integ-test/src/test/java/org/opensearch/sql/legacy/SQLIntegTestCase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ protected synchronized void loadIndex(Index index, RestClient client) throws IOE
202202
createIndexByRestClient(client, indexName, mapping);
203203
loadDataByRestClient(client, indexName, dataSet);
204204
}
205+
// loadIndex() could directly return when isIndexExist()=true,
206+
// e.g. the index is created in the cluster but data hasn't been flushed.
207+
// We block loadIndex() until data loaded to resolve
208+
// https://github.com/opensearch-project/sql/issues/4261
209+
int countDown = 3; // 1500ms timeout
210+
while (countDown != 0 && getDocCount(client, indexName) == 0) {
211+
try {
212+
Thread.sleep(500);
213+
countDown--;
214+
} catch (InterruptedException e) {
215+
throw new IOException(e);
216+
}
217+
}
205218
}
206219

207220
protected synchronized void loadIndex(Index index) throws IOException {

integ-test/src/test/java/org/opensearch/sql/legacy/TestUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ public static void loadDataByRestClient(
103103
performRequest(client, request);
104104
}
105105

106+
/**
107+
* Return how many docs in the index
108+
*
109+
* @param client client connection
110+
* @param indexName index name
111+
* @return doc count of the index
112+
* @throws IOException
113+
*/
114+
public static int getDocCount(RestClient client, String indexName) throws IOException {
115+
Request request = new Request("GET", "/" + indexName + "/_count");
116+
Response response = performRequest(client, request);
117+
JSONObject jsonObject = new JSONObject(getResponseBody(response));
118+
return jsonObject.getInt("count");
119+
}
120+
106121
/**
107122
* Perform a request by REST client.
108123
*

0 commit comments

Comments
 (0)