@@ -418,20 +418,33 @@ public void testWeekAndWeekOfYear() throws IOException {
418
418
schema ("WEEK(DATE('2008-02-20'))" , "int" ),
419
419
schema ("WEEK(DATE('2008-02-20'), 1)" , "int" ));
420
420
421
- verifyDataRows (actual , rows (15 , 15 , 15 , 15 , 7 , 8 ));
421
+ int week19840412 = getYearWeek (LocalDate .of (1984 , 4 , 12 ), 0 ) % 100 ;
422
+ int week19840412Mode1 = getYearWeek (LocalDate .of (1984 , 4 , 12 ), 1 ) % 100 ;
423
+ int week20080220 = getYearWeek (LocalDate .of (2008 , 2 , 20 ), 0 ) % 100 ;
424
+ int week20080220Mode1 = getYearWeek (LocalDate .of (2008 , 2 , 20 ), 1 ) % 100 ;
425
+ verifyDataRows (
426
+ actual ,
427
+ rows (
428
+ week19840412 ,
429
+ week19840412 ,
430
+ week19840412Mode1 ,
431
+ week19840412Mode1 ,
432
+ week20080220 ,
433
+ week20080220Mode1 ));
422
434
}
423
435
424
436
@ Test
425
- public void testWeekAndWeekOfYearWithFilter () throws IOException {
437
+ public void testWeekAndWeekOfYearWithFilter () {
438
+ int week19840412 = getYearWeek (LocalDate .of (1984 , 4 , 12 ), 0 ) % 100 ;
426
439
JSONObject actual =
427
440
executeQuery (
428
441
String .format (
429
442
"source=%s | fields strict_date_optional_time"
430
443
+ "| where YEAR(strict_date_optional_time) < 2000"
431
- + "| where WEEK(DATE(strict_date_optional_time)) = 15 "
444
+ + "| where WEEK(DATE(strict_date_optional_time)) = %d "
432
445
+ "| stats COUNT() AS CNT "
433
446
+ "| head 1 " ,
434
- TEST_INDEX_DATE_FORMATS ));
447
+ TEST_INDEX_DATE_FORMATS , week19840412 ));
435
448
436
449
verifySchema (actual , schema ("CNT" , "bigint" ));
437
450
@@ -464,13 +477,14 @@ public void testWeekDay() throws IOException {
464
477
}
465
478
466
479
@ Test
467
- public void testYearWeek () throws IOException {
480
+ public void testYearWeek () {
468
481
int currentYearWeek =
469
- exprYearweek (
470
- new ExprDateValue (
471
- LocalDateTime .now (new FunctionProperties ().getQueryStartClock ()).toLocalDate ()),
472
- new ExprIntegerValue (0 ))
473
- .integerValue ();
482
+ getYearWeek (
483
+ LocalDateTime .now (new FunctionProperties ().getQueryStartClock ()).toLocalDate (), 0 );
484
+ int yearWeek19840412 = getYearWeek (LocalDate .of (1984 , 4 , 12 ), 0 );
485
+ int yearWeek20200826 = getYearWeek (LocalDate .of (2020 , 8 , 26 ), 0 );
486
+ int yearWeek20190105 = getYearWeek (LocalDate .of (2019 , 1 , 5 ), 1 );
487
+ // Write to a tmp file
474
488
JSONObject actual =
475
489
executeQuery (
476
490
String .format (
@@ -491,7 +505,14 @@ public void testYearWeek() throws IOException {
491
505
schema ("YEARWEEK('2020-08-26')" , "int" ),
492
506
schema ("YEARWEEK('2019-01-05', 1)" , "int" ));
493
507
494
- verifyDataRows (actual , rows (198415 , currentYearWeek , 198415 , 202034 , 201901 ));
508
+ verifyDataRows (
509
+ actual ,
510
+ rows (
511
+ yearWeek19840412 ,
512
+ currentYearWeek ,
513
+ yearWeek19840412 ,
514
+ yearWeek20200826 ,
515
+ yearWeek20190105 ));
495
516
}
496
517
497
518
@ Test
@@ -1004,6 +1025,8 @@ public void testDateFormatAndDatetimeAndFromDays() throws IOException {
1004
1025
offsetUTC .format (DateTimeFormatter .ofPattern ("yyyy-MM-dd HH:mm:ss" ));
1005
1026
String expectedDatetimeAtPlus8 =
1006
1027
offsetPlus8 .format (DateTimeFormatter .ofPattern ("yyyy-MM-dd HH:mm:ss" ));
1028
+ int week19840412 = getYearWeek (LocalDate .of (1984 , 4 , 12 ), 0 ) % 100 ;
1029
+ int week19840412Mode1 = getYearWeek (LocalDate .of (1984 , 4 , 12 ), 1 ) % 100 ;
1007
1030
1008
1031
verifyDataRows (
1009
1032
actual ,
@@ -1016,8 +1039,8 @@ public void testDateFormatAndDatetimeAndFromDays() throws IOException {
1016
1039
"2017-11-02" ,
1017
1040
expectedDatetimeAtPlus8 ,
1018
1041
expectedDatetimeAtUTC ,
1019
- "15 1984 15" ,
1020
- "15 15 1984" ,
1042
+ String . format ( "%d 1984 %d" , week19840412 , week19840412 ) ,
1043
+ String . format ( "%d %d 1984", week19840412Mode1 , week19840412Mode1 ) ,
1021
1044
"09:07:42.000123" ));
1022
1045
}
1023
1046
@@ -1452,4 +1475,8 @@ public void testMicrosecond() throws IOException {
1452
1475
schema ("m5" , "int" ));
1453
1476
verifyDataRows (actual , rows (0 , 0 , 0 , 123456 , 123456 ));
1454
1477
}
1478
+
1479
+ private static int getYearWeek (LocalDate date , int mode ) {
1480
+ return exprYearweek (new ExprDateValue (date ), new ExprIntegerValue (mode )).integerValue ();
1481
+ }
1455
1482
}
0 commit comments