|
15 | 15 |
|
16 | 16 | import java.io.IOException; |
17 | 17 | import java.time.LocalDate; |
| 18 | +import java.time.LocalDateTime; |
18 | 19 | import java.time.LocalTime; |
| 20 | +import java.time.ZoneOffset; |
19 | 21 | import java.time.format.DateTimeFormatter; |
20 | 22 | import java.util.TimeZone; |
21 | 23 | import org.json.JSONObject; |
22 | 24 | import org.junit.After; |
23 | 25 | import org.junit.Before; |
24 | 26 | import org.junit.Ignore; |
25 | 27 | import org.junit.jupiter.api.Test; |
| 28 | +import org.opensearch.client.Request; |
26 | 29 | import org.opensearch.sql.common.utils.StringUtils; |
27 | 30 |
|
28 | 31 | @SuppressWarnings("unchecked") |
@@ -1559,4 +1562,31 @@ public void testExtract() throws IOException { |
1559 | 1562 | verifySchema(result, schema("f1", null, "bigint"), schema("f2", null, "bigint")); |
1560 | 1563 | verifySome(result.getJSONArray("datarows"), rows(1997L, 17L)); |
1561 | 1564 | } |
| 1565 | + |
| 1566 | + @Test |
| 1567 | + public void testCompareAgainstUTCDate() throws IOException { |
| 1568 | + LocalDateTime now = LocalDateTime.now(ZoneOffset.UTC); |
| 1569 | + String isoTimestamp = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")); |
| 1570 | + String pplTimestamp = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| 1571 | + // a random ID that did not exist in the index bank |
| 1572 | + int DOC_ID = 40; |
| 1573 | + Request putRequest = |
| 1574 | + new Request("PUT", String.format("/%s/_doc/%d?refresh=true", TEST_INDEX_BANK, DOC_ID)); |
| 1575 | + putRequest.setJsonEntity(String.format("{\"birthdate\":\"%s\"}", isoTimestamp)); |
| 1576 | + client().performRequest(putRequest); |
| 1577 | + |
| 1578 | + JSONObject result = |
| 1579 | + executeQuery( |
| 1580 | + String.format( |
| 1581 | + "source=%s | where birthdate > date_sub(now(), interval 1 hour) and birthdate <" |
| 1582 | + + " date_add(now(), interval 1 hour) | fields birthdate", |
| 1583 | + TEST_INDEX_BANK)); |
| 1584 | + |
| 1585 | + verifySchema(result, schema("birthdate", "timestamp")); |
| 1586 | + verifyDataRows(result, rows(pplTimestamp)); |
| 1587 | + |
| 1588 | + Request deleteRequest = |
| 1589 | + new Request("DELETE", String.format("/%s/_doc/%d?refresh=true", TEST_INDEX_BANK, DOC_ID)); |
| 1590 | + client().performRequest(deleteRequest); |
| 1591 | + } |
1562 | 1592 | } |
0 commit comments