Skip to content

[BUG] Fix flaky tests related to WeekOfYear in CalcitePPLDateTimeBuiltinFunctionIT #3815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -418,20 +418,33 @@ public void testWeekAndWeekOfYear() throws IOException {
schema("WEEK(DATE('2008-02-20'))", "int"),
schema("WEEK(DATE('2008-02-20'), 1)", "int"));

verifyDataRows(actual, rows(15, 15, 15, 15, 7, 8));
int week19840412 = getYearWeek(LocalDate.of(1984, 4, 12), 0) % 100;
int week19840412Mode1 = getYearWeek(LocalDate.of(1984, 4, 12), 1) % 100;
int week20080220 = getYearWeek(LocalDate.of(2008, 2, 20), 0) % 100;
int week20080220Mode1 = getYearWeek(LocalDate.of(2008, 2, 20), 1) % 100;
verifyDataRows(
actual,
rows(
week19840412,
week19840412,
week19840412Mode1,
week19840412Mode1,
week20080220,
week20080220Mode1));
}

@Test
public void testWeekAndWeekOfYearWithFilter() throws IOException {
public void testWeekAndWeekOfYearWithFilter() {
int week19840412 = getYearWeek(LocalDate.of(1984, 4, 12), 0) % 100;
JSONObject actual =
executeQuery(
String.format(
"source=%s | fields strict_date_optional_time"
+ "| where YEAR(strict_date_optional_time) < 2000"
+ "| where WEEK(DATE(strict_date_optional_time)) = 15"
+ "| where WEEK(DATE(strict_date_optional_time)) = %d"
+ "| stats COUNT() AS CNT "
+ "| head 1 ",
TEST_INDEX_DATE_FORMATS));
TEST_INDEX_DATE_FORMATS, week19840412));

verifySchema(actual, schema("CNT", "bigint"));

Expand Down Expand Up @@ -464,13 +477,14 @@ public void testWeekDay() throws IOException {
}

@Test
public void testYearWeek() throws IOException {
public void testYearWeek() {
int currentYearWeek =
exprYearweek(
new ExprDateValue(
LocalDateTime.now(new FunctionProperties().getQueryStartClock()).toLocalDate()),
new ExprIntegerValue(0))
.integerValue();
getYearWeek(
LocalDateTime.now(new FunctionProperties().getQueryStartClock()).toLocalDate(), 0);
int yearWeek19840412 = getYearWeek(LocalDate.of(1984, 4, 12), 0);
int yearWeek20200826 = getYearWeek(LocalDate.of(2020, 8, 26), 0);
int yearWeek20190105 = getYearWeek(LocalDate.of(2019, 1, 5), 1);
// Write to a tmp file
JSONObject actual =
executeQuery(
String.format(
Expand All @@ -491,7 +505,14 @@ public void testYearWeek() throws IOException {
schema("YEARWEEK('2020-08-26')", "int"),
schema("YEARWEEK('2019-01-05', 1)", "int"));

verifyDataRows(actual, rows(198415, currentYearWeek, 198415, 202034, 201901));
verifyDataRows(
actual,
rows(
yearWeek19840412,
currentYearWeek,
yearWeek19840412,
yearWeek20200826,
yearWeek20190105));
}

@Test
Expand Down Expand Up @@ -1004,6 +1025,8 @@ public void testDateFormatAndDatetimeAndFromDays() throws IOException {
offsetUTC.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String expectedDatetimeAtPlus8 =
offsetPlus8.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
int week19840412 = getYearWeek(LocalDate.of(1984, 4, 12), 0) % 100;
int week19840412Mode1 = getYearWeek(LocalDate.of(1984, 4, 12), 1) % 100;

verifyDataRows(
actual,
Expand All @@ -1016,8 +1039,8 @@ public void testDateFormatAndDatetimeAndFromDays() throws IOException {
"2017-11-02",
expectedDatetimeAtPlus8,
expectedDatetimeAtUTC,
"15 1984 15",
"15 15 1984",
String.format("%d 1984 %d", week19840412, week19840412),
String.format("%d %d 1984", week19840412Mode1, week19840412Mode1),
"09:07:42.000123"));
}

Expand Down Expand Up @@ -1452,4 +1475,8 @@ public void testMicrosecond() throws IOException {
schema("m5", "int"));
verifyDataRows(actual, rows(0, 0, 0, 123456, 123456));
}

private static int getYearWeek(LocalDate date, int mode) {
return exprYearweek(new ExprDateValue(date), new ExprIntegerValue(mode)).integerValue();
}
}
Loading