|
29 | 29 | import org.opensearch.client.Request;
|
30 | 30 | import org.opensearch.client.RequestOptions;
|
31 | 31 | import org.opensearch.client.Response;
|
| 32 | +import org.opensearch.client.ResponseException; |
32 | 33 | import org.opensearch.sql.common.utils.StringUtils;
|
33 | 34 | import org.opensearch.sql.legacy.SQLIntegTestCase;
|
34 | 35 |
|
@@ -1288,4 +1289,85 @@ protected JSONObject executeQuery(String query) throws IOException {
|
1288 | 1289 | Response response = client().performRequest(request);
|
1289 | 1290 | return new JSONObject(getResponseBody(response));
|
1290 | 1291 | }
|
| 1292 | + |
| 1293 | + @Test |
| 1294 | + public void testTimestampBracket() throws IOException { |
| 1295 | + JSONObject result = executeQuery("select {timestamp '2020-09-16 17:30:00'}"); |
| 1296 | + verifySchema(result, schema("{timestamp '2020-09-16 17:30:00'}", null, "timestamp")); |
| 1297 | + verifyDataRows(result, rows("2020-09-16 17:30:00")); |
| 1298 | + |
| 1299 | + result = executeQuery("select {ts '2020-09-16 17:30:00'}"); |
| 1300 | + verifySchema(result, schema("{ts '2020-09-16 17:30:00'}", null, "timestamp")); |
| 1301 | + verifyDataRows(result, rows("2020-09-16 17:30:00")); |
| 1302 | + |
| 1303 | + result = executeQuery("select {timestamp '2020-09-16 17:30:00.123'}"); |
| 1304 | + verifySchema(result, schema("{timestamp '2020-09-16 17:30:00.123'}", null, "timestamp")); |
| 1305 | + verifyDataRows(result, rows("2020-09-16 17:30:00.123")); |
| 1306 | + |
| 1307 | + result = executeQuery("select {ts '2020-09-16 17:30:00.123'}"); |
| 1308 | + verifySchema(result, schema("{ts '2020-09-16 17:30:00.123'}", null, "timestamp")); |
| 1309 | + verifyDataRows(result, rows("2020-09-16 17:30:00.123")); |
| 1310 | + } |
| 1311 | + |
| 1312 | + @Test |
| 1313 | + public void testTimeBracket() throws IOException { |
| 1314 | + JSONObject result = executeQuery("select {time '17:30:00'}"); |
| 1315 | + verifySchema(result, schema("{time '17:30:00'}", null, "time")); |
| 1316 | + verifyDataRows(result, rows("17:30:00")); |
| 1317 | + |
| 1318 | + result = executeQuery("select {t '17:30:00'}"); |
| 1319 | + verifySchema(result, schema("{t '17:30:00'}", null, "time")); |
| 1320 | + verifyDataRows(result, rows("17:30:00")); |
| 1321 | + |
| 1322 | + result = executeQuery("select {time '17:30:00.123'}"); |
| 1323 | + verifySchema(result, schema("{time '17:30:00.123'}", null, "time")); |
| 1324 | + verifyDataRows(result, rows("17:30:00.123")); |
| 1325 | + |
| 1326 | + result = executeQuery("select {t '17:30:00.123'}"); |
| 1327 | + verifySchema(result, schema("{t '17:30:00.123'}", null, "time")); |
| 1328 | + verifyDataRows(result, rows("17:30:00.123")); |
| 1329 | + } |
| 1330 | + |
| 1331 | + @Test |
| 1332 | + public void testDateBracket() throws IOException { |
| 1333 | + JSONObject result = executeQuery("select {date '2020-09-16'}"); |
| 1334 | + verifySchema(result, schema("{date '2020-09-16'}", null, "date")); |
| 1335 | + verifyDataRows(result, rows("2020-09-16")); |
| 1336 | + |
| 1337 | + result = executeQuery("select {d '2020-09-16'}"); |
| 1338 | + verifySchema(result, schema("{d '2020-09-16'}", null, "date")); |
| 1339 | + verifyDataRows(result, rows("2020-09-16")); |
| 1340 | + } |
| 1341 | + |
| 1342 | + private void compareBrackets(String query1, String query2, String datetime) throws IOException { |
| 1343 | + JSONObject result1 = executeQuery("select " + query1 + " '" + datetime + "'"); |
| 1344 | + JSONObject result2 = executeQuery("select {" + query2 + " '" + datetime + "'}"); |
| 1345 | + |
| 1346 | + verifyDataRows(result1, rows(datetime)); |
| 1347 | + verifyDataRows(result2, rows(datetime)); |
| 1348 | + } |
| 1349 | + |
| 1350 | + @Test |
| 1351 | + public void testBracketedEquivalent() throws IOException { |
| 1352 | + compareBrackets("timestamp", "timestamp", "2020-09-16 17:30:00"); |
| 1353 | + compareBrackets("timestamp", "ts", "2020-09-16 17:30:00"); |
| 1354 | + compareBrackets("timestamp", "timestamp", "2020-09-16 17:30:00.123"); |
| 1355 | + compareBrackets("timestamp", "ts", "2020-09-16 17:30:00.123"); |
| 1356 | + compareBrackets("date", "date", "2020-09-16"); |
| 1357 | + compareBrackets("date", "d", "2020-09-16"); |
| 1358 | + compareBrackets("time", "time", "17:30:00"); |
| 1359 | + compareBrackets("time", "t", "17:30:00"); |
| 1360 | + } |
| 1361 | + |
| 1362 | + @Test |
| 1363 | + public void testBracketFails() { |
| 1364 | + assertThrows(ResponseException.class, ()->executeQuery("select {time '2020-09-16'}")); |
| 1365 | + assertThrows(ResponseException.class, ()->executeQuery("select {t '2020-09-16'}")); |
| 1366 | + assertThrows(ResponseException.class, ()->executeQuery("select {date '17:30:00'}")); |
| 1367 | + assertThrows(ResponseException.class, ()->executeQuery("select {d '17:30:00'}")); |
| 1368 | + assertThrows(ResponseException.class, ()->executeQuery("select {timestamp '2020-09-16'}")); |
| 1369 | + assertThrows(ResponseException.class, ()->executeQuery("select {ts '2020-09-16'}")); |
| 1370 | + assertThrows(ResponseException.class, ()->executeQuery("select {timestamp '17:30:00'}")); |
| 1371 | + assertThrows(ResponseException.class, ()->executeQuery("select {ts '17:30:00'}")); |
| 1372 | + } |
1291 | 1373 | }
|
0 commit comments