Skip to content

Commit dfb903e

Browse files
committed
Fix flaky ExtractTest and update CI macOS runner
- Fix ExtractTest.testExtractDatePartWithTimeType() flaky WEEK assertion by using the same DateTimeFormatter("w", Locale.ENGLISH) calculation as the EXTRACT function instead of ALIGNED_WEEK_OF_YEAR - Update CI macOS runner from deprecated macos-13 to macos-14 Signed-off-by: Eric Wei <mengwei.eric@gmail.com>
1 parent 9e0de60 commit dfb903e

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

.github/workflows/integ-tests-with-security.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
strategy:
6161
fail-fast: false
6262
matrix:
63-
os: [ windows-latest, macos-13 ]
63+
os: [ windows-latest, macos-14 ]
6464
java: [ 11, 17, 21 ]
6565

6666
runs-on: ${{ matrix.os }}

.github/workflows/sql-test-and-build-workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ jobs:
105105
matrix:
106106
entry:
107107
- { os: windows-latest, java: 11, os_build_args: -x doctest -PbuildPlatform=windows }
108-
- { os: macos-13, java: 11}
108+
- { os: macos-14, java: 11}
109109
- { os: windows-latest, java: 17, os_build_args: -x doctest -PbuildPlatform=windows }
110-
- { os: macos-13, java: 17 }
110+
- { os: macos-14, java: 17 }
111111
- { os: windows-latest, java: 21, os_build_args: -x doctest -PbuildPlatform=windows }
112-
- { os: macos-13, java: 21 }
112+
- { os: macos-14, java: 21 }
113113
runs-on: ${{ matrix.entry.os }}
114114

115115
steps:

core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
package org.opensearch.sql.expression.datetime;
77

8-
import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
98
import static org.junit.jupiter.api.Assertions.assertEquals;
109
import static org.opensearch.sql.data.type.ExprCoreType.LONG;
1110

1211
import java.time.LocalDate;
12+
import java.time.format.DateTimeFormatter;
13+
import java.util.Locale;
1314
import java.util.stream.Stream;
1415
import org.junit.jupiter.api.Test;
1516
import org.junit.jupiter.params.ParameterizedTest;
@@ -96,15 +97,12 @@ public void testExtractDatePartWithTimeType() {
9697

9798
datePartWithTimeArgQuery("DAY", timeInput, now.getDayOfMonth());
9899

99-
// To avoid flaky test, skip the testing in December and January because the WEEK is ISO 8601
100-
// week-of-week-based-year which is considered to start on a Monday and week 1 is the first week
101-
// with >3 days. it is possible for early-January dates to be part of the 52nd or 53rd week of
102-
// the previous year, and for late-December dates to be part of the first week of the next year.
103-
// For example, 2005-01-02 is part of the 53rd week of year 2004, while 2012-12-31 is part of
104-
// the first week of 2013
105-
if (now.getMonthValue() != 1 && now.getMonthValue() != 12) {
106-
datePartWithTimeArgQuery("WEEK", datetimeInput, now.get(ALIGNED_WEEK_OF_YEAR));
107-
}
100+
// Use the same week-of-year calculation as the EXTRACT function (DateTimeFormatter "w" with
101+
// Locale.ENGLISH) to avoid flaky mismatches. ALIGNED_WEEK_OF_YEAR uses simple arithmetic
102+
// (dayOfYear-1)/7+1 which diverges from the locale-aware week numbering on many dates.
103+
long expectedWeek =
104+
Long.parseLong(DateTimeFormatter.ofPattern("w", Locale.ENGLISH).format(now.atStartOfDay()));
105+
datePartWithTimeArgQuery("WEEK", datetimeInput, expectedWeek);
108106

109107
datePartWithTimeArgQuery("MONTH", timeInput, now.getMonthValue());
110108

0 commit comments

Comments
 (0)