Skip to content

Commit c0f5680

Browse files
authored
Fix the flaky CalcitePPLTcphIT (#4846)
Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent a8069d1 commit c0f5680

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
@@ -17,7 +17,6 @@
1717
import java.util.Locale;
1818
import org.json.JSONObject;
1919
import org.junit.Assume;
20-
import org.junit.Ignore;
2120
import org.junit.Test;
2221
import org.opensearch.sql.ppl.PPLIntegTestCase;
2322
import org.opensearch.sql.util.Retry;
@@ -143,21 +142,19 @@ public void testQ3() throws IOException {
143142
rows(4423, 3055.9365, "1995-02-17 00:00:00", 0));
144143
}
145144

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

163160
@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
@@ -210,6 +210,19 @@ protected synchronized void loadIndex(Index index, RestClient client) throws IOE
210210
createIndexByRestClient(client, indexName, mapping);
211211
loadDataByRestClient(client, indexName, dataSet);
212212
}
213+
// loadIndex() could directly return when isIndexExist()=true,
214+
// e.g. the index is created in the cluster but data hasn't been flushed.
215+
// We block loadIndex() until data loaded to resolve
216+
// https://github.com/opensearch-project/sql/issues/4261
217+
int countDown = 3; // 1500ms timeout
218+
while (countDown != 0 && getDocCount(client, indexName) == 0) {
219+
try {
220+
Thread.sleep(500);
221+
countDown--;
222+
} catch (InterruptedException e) {
223+
throw new IOException(e);
224+
}
225+
}
213226
}
214227

215228
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
@@ -104,6 +104,21 @@ public static void loadDataByRestClient(
104104
performRequest(client, request);
105105
}
106106

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

0 commit comments

Comments
 (0)