|
18 | 18 | import org.junit.Ignore; |
19 | 19 | import org.junit.Test; |
20 | 20 | import org.opensearch.client.Request; |
21 | | -import org.opensearch.client.Response; |
22 | 21 | import org.opensearch.client.RequestOptions; |
| 22 | +import org.opensearch.client.Response; |
23 | 23 | import org.opensearch.client.ResponseException; |
24 | 24 | import org.opensearch.sql.common.setting.Settings; |
25 | 25 | import org.opensearch.sql.legacy.SQLIntegTestCase; |
@@ -217,42 +217,44 @@ public void testQueryWithoutFrom() { |
217 | 217 | assertEquals(1, response.getInt("total")); |
218 | 218 | assertEquals(1, response.getJSONArray("datarows").getJSONArray(0).getInt(0)); |
219 | 219 | } |
| 220 | + |
220 | 221 | @Test |
221 | 222 | public void testAlias() throws Exception { |
222 | 223 | String indexName = Index.ONLINE.getName(); |
223 | 224 | String aliasName = "alias_ONLINE"; |
224 | | - String filterQuery = "{\n" + |
225 | | - " \"term\": {\n" + |
226 | | - " \"107\": 72 \n" + |
227 | | - " }\n" + |
228 | | - "}"; |
| 225 | + String filterQuery = "{\n" + " \"term\": {\n" + " \"107\": 72 \n" + " }\n" + "}"; |
229 | 226 |
|
230 | | - //Execute the SQL query with filter |
| 227 | + // Execute the SQL query with filter |
231 | 228 | String selectQuery = "SELECT * FROM " + TEST_INDEX_ONLINE; |
232 | | - JSONObject initialResponse = new JSONObject(executeFetchQuery(selectQuery, 10, "jdbc", filterQuery)); |
| 229 | + JSONObject initialResponse = |
| 230 | + new JSONObject(executeFetchQuery(selectQuery, 10, "jdbc", filterQuery)); |
233 | 231 | assertEquals(initialResponse.getInt("size"), 10); |
234 | 232 |
|
235 | | - //Create an alias |
236 | | - String createAliasQuery = String.format("{ \"actions\": [ { \"add\": { \"index\": \"%s\", \"alias\": \"%s\" } } ] }", indexName, aliasName); |
| 233 | + // Create an alias |
| 234 | + String createAliasQuery = |
| 235 | + String.format( |
| 236 | + "{ \"actions\": [ { \"add\": { \"index\": \"%s\", \"alias\": \"%s\" } } ] }", |
| 237 | + indexName, aliasName); |
237 | 238 | Request createAliasRequest = new Request("POST", "/_aliases"); |
238 | 239 | createAliasRequest.setJsonEntity(createAliasQuery); |
239 | 240 | JSONObject aliasResponse = new JSONObject(executeRequest(createAliasRequest)); |
240 | 241 |
|
241 | 242 | // Assert that alias creation was acknowledged |
242 | 243 | assertTrue(aliasResponse.getBoolean("acknowledged")); |
243 | 244 |
|
244 | | - //Query using the alias |
| 245 | + // Query using the alias |
245 | 246 | String aliasSelectQuery = String.format("SELECT * FROM %s", aliasName); |
246 | 247 | JSONObject aliasQueryResponse = new JSONObject(executeFetchQuery(aliasSelectQuery, 4, "jdbc")); |
247 | 248 | assertEquals(4, aliasQueryResponse.getInt("size")); |
248 | 249 |
|
249 | | - //Query using the alias with filter |
250 | | - JSONObject aliasFilteredResponse = new JSONObject(executeFetchQuery(aliasSelectQuery, 4, "jdbc", filterQuery)); |
| 250 | + // Query using the alias with filter |
| 251 | + JSONObject aliasFilteredResponse = |
| 252 | + new JSONObject(executeFetchQuery(aliasSelectQuery, 4, "jdbc", filterQuery)); |
251 | 253 | assertEquals(aliasFilteredResponse.getInt("size"), 4); |
252 | 254 | } |
253 | 255 |
|
254 | | - |
255 | | - private String executeFetchQuery(String query, int fetchSize, String requestType, String filter) throws IOException{ |
| 256 | + private String executeFetchQuery(String query, int fetchSize, String requestType, String filter) |
| 257 | + throws IOException { |
256 | 258 | String endpoint = "/_plugins/_sql?format=" + requestType; |
257 | 259 | String requestBody = makeRequest(query, fetchSize, filter); |
258 | 260 |
|
|
0 commit comments