Skip to content

Commit 96bd246

Browse files
committed
Add a test to compare against UTC date
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 1f089f6 commit 96bd246

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteDateTimeFunctionIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.opensearch.sql.calcite.remote;
77

88
import java.io.IOException;
9+
import org.junit.Ignore;
910
import org.opensearch.sql.ppl.DateTimeFunctionIT;
1011

1112
public class CalciteDateTimeFunctionIT extends DateTimeFunctionIT {
@@ -17,6 +18,8 @@ public void init() throws Exception {
1718
}
1819

1920
// TODO: Remove this when supporting type coercion and casting with Calcite
21+
// https://github.com/opensearch-project/sql/issues/3761
22+
@Ignore
2023
@Override
2124
public void testUnixTimestampWithTimestampString() throws IOException {}
2225
}

integ-test/src/test/java/org/opensearch/sql/ppl/DateTimeFunctionIT.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515

1616
import java.io.IOException;
1717
import java.time.LocalDate;
18+
import java.time.LocalDateTime;
1819
import java.time.LocalTime;
20+
import java.time.ZoneOffset;
1921
import java.time.format.DateTimeFormatter;
2022
import java.util.TimeZone;
2123
import org.json.JSONObject;
2224
import org.junit.After;
2325
import org.junit.Before;
2426
import org.junit.Ignore;
2527
import org.junit.jupiter.api.Test;
28+
import org.opensearch.client.Request;
2629
import org.opensearch.sql.common.utils.StringUtils;
2730

2831
@SuppressWarnings("unchecked")
@@ -1559,4 +1562,31 @@ public void testExtract() throws IOException {
15591562
verifySchema(result, schema("f1", null, "bigint"), schema("f2", null, "bigint"));
15601563
verifySome(result.getJSONArray("datarows"), rows(1997L, 17L));
15611564
}
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+
}
15621592
}

0 commit comments

Comments
 (0)