From 0a49bff6c48db3b0c25665d417323dd0953ca095 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 8 Jan 2025 17:07:09 +0000 Subject: [PATCH] Fix the flaky test testExtractDatePartWithTimeType() (#3225) * Fix the failure test testExtractDatePartWithTimeType() Signed-off-by: Lantao Jin * skip test week with time type in Jan and Dec Signed-off-by: Lantao Jin * add doc Signed-off-by: Lantao Jin * fix incorrect format Signed-off-by: Lantao Jin --------- Signed-off-by: Lantao Jin (cherry picked from commit 0e4acd3ea9b9e92316f1b0a95914e6b5345468af) Signed-off-by: github-actions[bot] --- .../sql/expression/datetime/ExtractTest.java | 24 +++++++++++-------- docs/user/dql/functions.rst | 8 +++++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java b/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java index 820158b722..74c2847566 100644 --- a/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java +++ b/core/src/test/java/org/opensearch/sql/expression/datetime/ExtractTest.java @@ -92,19 +92,23 @@ private void datePartWithTimeArgQuery(String part, String time, long expected) { @Test public void testExtractDatePartWithTimeType() { - datePartWithTimeArgQuery( - "DAY", timeInput, LocalDate.now(functionProperties.getQueryStartClock()).getDayOfMonth()); + LocalDate now = LocalDate.now(functionProperties.getQueryStartClock()); - datePartWithTimeArgQuery( - "WEEK", - timeInput, - LocalDate.now(functionProperties.getQueryStartClock()).get(ALIGNED_WEEK_OF_YEAR)); + datePartWithTimeArgQuery("DAY", timeInput, now.getDayOfMonth()); - datePartWithTimeArgQuery( - "MONTH", timeInput, LocalDate.now(functionProperties.getQueryStartClock()).getMonthValue()); + // To avoid flaky test, skip the testing in December and January because the WEEK is ISO 8601 + // week-of-week-based-year which is considered to start on a Monday and week 1 is the first week + // with >3 days. it is possible for early-January dates to be part of the 52nd or 53rd week of + // the previous year, and for late-December dates to be part of the first week of the next year. + // For example, 2005-01-02 is part of the 53rd week of year 2004, while 2012-12-31 is part of + // the first week of 2013 + if (now.getMonthValue() != 1 && now.getMonthValue() != 12) { + datePartWithTimeArgQuery("WEEK", datetimeInput, now.get(ALIGNED_WEEK_OF_YEAR)); + } - datePartWithTimeArgQuery( - "YEAR", timeInput, LocalDate.now(functionProperties.getQueryStartClock()).getYear()); + datePartWithTimeArgQuery("MONTH", timeInput, now.getMonthValue()); + + datePartWithTimeArgQuery("YEAR", timeInput, now.getYear()); } @ParameterizedTest(name = "{0}") diff --git a/docs/user/dql/functions.rst b/docs/user/dql/functions.rst index ac782a1881..27d77d8202 100644 --- a/docs/user/dql/functions.rst +++ b/docs/user/dql/functions.rst @@ -1960,11 +1960,11 @@ The format specifiers found in this table are the same as those found in the `DA * - DAY - %d * - WEEK - - %X + - %v * - MONTH - %m * - YEAR - - %V + - %Y * - SECOND_MICROSECOND - %s%f * - MINUTE_MICROSECOND @@ -2000,6 +2000,10 @@ Example:: | 202302 | +------------------------------------------------+ +Notice: + +Function `extract(WEEK FROM ...)` returns the number of the ISO 8601 week-of-week-based-year. ISO week-numbering is considered to start on a Monday and week 1 is the first week with >3 days. In the ISO week-numbering system, it is possible for early-January dates to be part of the 52nd or 53rd week of the previous year, and for late-December dates to be part of the first week of the next year. For example, 2005-01-02 is part of the 53rd week of year 2004, while 2012-12-31 is part of the first week of 2013. Ref https://en.wikipedia.org/wiki/ISO_week_date + FROM_DAYS ---------