Skip to content

Commit 4b43999

Browse files
committed
Remove opensearch test dependency from core module
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 8861e09 commit 4b43999

2 files changed

Lines changed: 0 additions & 147 deletions

File tree

core/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ dependencies {
7474
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: "${hamcrest_version}"
7575
testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockito_version}"
7676
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockito_version}"
77-
testImplementation group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}"
7877
}
7978

8079
spotless {

core/src/test/java/org/opensearch/sql/utils/DateTimeUtilsTest.java

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,13 @@
1313

1414
import java.time.Instant;
1515
import java.time.LocalDateTime;
16-
import java.time.ZoneId;
1716
import java.time.ZoneOffset;
1817
import java.time.ZonedDateTime;
1918
import java.util.concurrent.TimeUnit;
2019
import org.junit.jupiter.api.Test;
21-
import org.opensearch.common.time.DateFormatter;
22-
import org.opensearch.common.time.DateMathParser;
2320
import org.opensearch.sql.planner.physical.collector.Rounding.DateTimeUnit;
2421

2522
public class DateTimeUtilsTest {
26-
private final DateFormatter formatter =
27-
DateFormatter.forPattern("strict_date_optional_time||epoch_millis");
28-
private final DateMathParser parser = formatter.toDateMathParser();
2923
private final ZonedDateTime monday = ZonedDateTime.of(2025, 9, 15, 2, 0, 0, 0, ZoneOffset.UTC);
3024
private final ZonedDateTime tuesday =
3125
ZonedDateTime.of(2014, 11, 18, 14, 27, 32, 0, ZoneOffset.UTC);
@@ -348,125 +342,6 @@ void testResolveTimeModifierWithInvalidInput() {
348342
assertThrows(IllegalArgumentException.class, () -> DateTimeUtils.resolveTimeModifier("@+d"));
349343
}
350344

351-
@Test
352-
void testOpenSearchTimeEquivalence() {
353-
// Fixed reference time for testing
354-
ZonedDateTime baseZdt = tuesday;
355-
long baseMilli = baseZdt.toInstant().toEpochMilli();
356-
357-
// Test cases for various formats
358-
Object[][] testCases = {
359-
// PPL format, OpenSearch format
360-
{"-30s", "now-30s"},
361-
{"-1h", "now-1h"},
362-
{"+5m", "now+5m"},
363-
{"-7d", "now-7d"},
364-
{"@s", "now/s"},
365-
{"@m", "now/m"},
366-
{"@h", "now/h"},
367-
{"@d", "now/d"},
368-
{"@w1", "now/w"},
369-
{"@month", "now/M"},
370-
{"@year", "now/y"},
371-
{"-1d@d", "now-1d/d"},
372-
{"-30m@h", "now-30m/h"},
373-
{"-2w+1d", "now-2w+1d"},
374-
{"-1month@mon", "now-1M/M"},
375-
{"2025-10-22 10:32:12", "2025-10-22T10:32:12Z"},
376-
{"2025-10-22T10:32:12Z", "2025-10-22T10:32:12Z"}
377-
};
378-
379-
for (Object[] testCase : testCases) {
380-
String pplFormat = (String) testCase[0];
381-
String osFormat = (String) testCase[1];
382-
383-
// Parse with PPL format
384-
ZonedDateTime pplParsed = getRelativeZonedDateTime(pplFormat, baseZdt);
385-
String converted = resolveTimeModifier(pplFormat, baseZdt);
386-
387-
// Parse with OpenSearch format
388-
Instant osParsed = parser.parse(osFormat, () -> baseMilli, false, ZoneId.of("UTC"));
389-
390-
assertEquals(osFormat, converted);
391-
392-
assertEquals(
393-
pplParsed.toInstant(),
394-
osParsed,
395-
String.format(
396-
"PPL '%s' and OpenSearch '%s' should yield the same instant", pplFormat, osFormat));
397-
}
398-
}
399-
400-
@Test
401-
void testConversionConsistency() throws Exception {
402-
// Fixed reference time for testing
403-
String baseTimeString = "2014-11-18T14:27:32";
404-
ZonedDateTime baseTime = ZonedDateTime.parse(baseTimeString + "Z");
405-
long now = baseTime.toInstant().toEpochMilli();
406-
407-
// Test cases for PPL formats
408-
String[] pplFormats = {
409-
"-30s",
410-
"-1h",
411-
"+5m",
412-
"-7d",
413-
"@s",
414-
"@m",
415-
"@h",
416-
"@d",
417-
"@month",
418-
"@year",
419-
"-1d@d",
420-
"-30m@h",
421-
"-2w+1d",
422-
"-1month@mon"
423-
// "+1year@q" removed as quarter handling differs between implementations
424-
};
425-
426-
for (String pplFormat : pplFormats) {
427-
// Parse directly with PPL format
428-
ZonedDateTime directPPLParsed = getRelativeZonedDateTime(pplFormat, baseTime);
429-
430-
// Convert to OpenSearch format then parse
431-
String osFormat = DateTimeUtils.resolveTimeModifier(pplFormat);
432-
Instant osParsed = parser.parse(osFormat, () -> now, false, ZoneId.of("UTC"));
433-
434-
// Verify time string conversion produces the same datetime value
435-
assertEquals(
436-
directPPLParsed.toInstant(),
437-
osParsed,
438-
String.format(
439-
"Direct PPL parsing of '%s' and OpenSearch parsing of converted '%s' should match",
440-
pplFormat, osFormat));
441-
}
442-
}
443-
444-
@Test
445-
void testSpecialCases() throws Exception {
446-
// Fixed reference time for testing
447-
ZonedDateTime baseTime = tuesday;
448-
long now = baseTime.toInstant().toEpochMilli();
449-
450-
// Special cases that need approximate matching due to format differences
451-
Object[][] testCases = {
452-
{"-1q", "now-3M"}, // Quarter (3 months) approximation
453-
{"@w2", "now/w+1d"},
454-
{"-1d@w5", "now-1d/w-3d"}
455-
};
456-
457-
for (Object[] testCase : testCases) {
458-
String pplFormat = (String) testCase[0];
459-
String osFormat = (String) testCase[1];
460-
461-
ZonedDateTime pplParsed = getRelativeZonedDateTime(pplFormat, baseTime);
462-
String converted = resolveTimeModifier(pplFormat, baseTime);
463-
Instant osParsed = parser.parse(osFormat, () -> now, false, ZoneId.of("UTC"));
464-
465-
assertEquals(osFormat, converted);
466-
assertEquals(osParsed, pplParsed.toInstant());
467-
}
468-
}
469-
470345
@Test
471346
void testParseTimeWithReferenceTimeModifier() {
472347
// Test with different reference dates in different quarters
@@ -520,27 +395,6 @@ void testParseTimeWithReferenceTimeModifierAndOffset() {
520395
"now-3M/M-2M", resolveTimeModifier("-1q@q", refTime)); // -1 quarter then snap to quarter
521396
}
522397

523-
@Test
524-
void testQuarterHandlingWithDateMathParser() throws Exception {
525-
// Fixed reference times for testing
526-
ZonedDateTime refSep = ZonedDateTime.of(2023, 9, 11, 10, 0, 0, 0, ZoneOffset.UTC);
527-
long nowSep = refSep.toInstant().toEpochMilli();
528-
529-
// Expected quarter start for September is July 1
530-
ZonedDateTime expectedJul = ZonedDateTime.of(2023, 7, 1, 0, 0, 0, 0, ZoneOffset.UTC);
531-
532-
// Convert @q using our resolveTimeModifier with the September reference date
533-
String osFormatForQ = resolveTimeModifier("@q", refSep); // Should be "now/M-2M"
534-
535-
// Parse the OpenSearch format using DateMathParser
536-
Instant osParsed = parser.parse(osFormatForQ, () -> nowSep, false, ZoneId.of("UTC"));
537-
538-
assertEquals(
539-
expectedJul.toInstant(),
540-
osParsed,
541-
"Quarter snapping from September 11 should result in July 1");
542-
}
543-
544398
@Test
545399
void testWeekDaySnapping() {
546400
// Test all week day snap variants

0 commit comments

Comments
 (0)