@@ -143,23 +143,32 @@ public void testTimewrapIncompletePeriodNullFill() throws IOException {
143143 schema ("sum(requests)_2days_before" , "bigint" ),
144144 schema ("sum(requests)_1day_before" , "bigint" ),
145145 schema ("sum(requests)_latest_day" , "bigint" ));
146- verifyDataRowsSome (result , rows ("2024-07-04 12:00:00" , null , 310 , 330 , 285 ));
147- verifyDataRowsSome (result , rows ("2024-07-04 18:00:00" , null , 190 , 215 , 165 ));
146+ verifyDataRowsInOrder (
147+ result ,
148+ rows ("2024-07-04 00:00:00" , 180 , 205 , 165 , 80 ),
149+ rows ("2024-07-04 06:00:00" , 240 , 260 , 225 , 100 ),
150+ rows ("2024-07-04 12:00:00" , null , 310 , 330 , 285 ),
151+ rows ("2024-07-04 18:00:00" , null , 190 , 215 , 165 ));
148152 }
149153
150154 // --- Different timescales ---
151155
152156 @ Test
153157 public void testTimewrapWeekSpanSinglePeriod () throws IOException {
158+ // 3 days of daily data in 1 week -> single period, 3 rows
154159 JSONObject result =
155160 executeQuery (
156161 "source=timewrap_test"
157- + WHERE_ALL
158- + " | timechart span=6h sum(requests) | timewrap 1week" );
162+ + WHERE_JUL1_TO_JUL3
163+ + " | timechart span=1day sum(requests) | timewrap 1week" );
159164
160165 verifySchema (
161166 result , schema ("@timestamp" , "timestamp" ), schema ("sum(requests)_latest_week" , "bigint" ));
162- verifyDataRowsSome (result , rows ("2024-07-04 00:00:00" , 80 ), rows ("2024-07-04 06:00:00" , 100 ));
167+ verifyDataRowsInOrder (
168+ result ,
169+ rows ("2024-07-01 00:00:00" , 920 ),
170+ rows ("2024-07-02 00:00:00" , 1010 ),
171+ rows ("2024-07-03 00:00:00" , 840 ));
163172 }
164173
165174 @ Test
@@ -180,7 +189,10 @@ public void testTimewrapTwelveHourSpan() throws IOException {
180189 schema ("sum(requests)_24hours_before" , "bigint" ),
181190 schema ("sum(requests)_12hours_before" , "bigint" ),
182191 schema ("sum(requests)_latest_hour" , "bigint" ));
183- verifyDataRowsSome (result , rows ("2024-07-04 00:00:00" , 180 , 310 , 205 , 330 , 165 , 285 , 80 ));
192+ verifyDataRowsInOrder (
193+ result ,
194+ rows ("2024-07-04 00:00:00" , 180 , 310 , 205 , 330 , 165 , 285 , 80 ),
195+ rows ("2024-07-04 06:00:00" , 240 , 190 , 260 , 215 , 225 , 165 , 100 ));
184196 }
185197
186198 @ Test
@@ -531,15 +543,17 @@ public void testTimewrapDaySpan() throws IOException {
531543
532544 @ Test
533545 public void testTimewrapWeekSpan () throws IOException {
546+ // 2 days of daily data in 1 week -> single period, 2 rows
534547 JSONObject result =
535548 executeQuery (
536549 "source=timewrap_test"
537- + WHERE_ALL
538- + " | timechart span=6h sum(requests) | timewrap 1week" );
550+ + WHERE_JUL1_TO_JUL2
551+ + " | timechart span=1day sum(requests) | timewrap 1week" );
539552
540553 verifySchema (
541554 result , schema ("@timestamp" , "timestamp" ), schema ("sum(requests)_latest_week" , "bigint" ));
542- verifyDataRowsSome (result , rows ("2024-07-04 00:00:00" , 80 ), rows ("2024-07-04 06:00:00" , 100 ));
555+ verifyDataRowsInOrder (
556+ result , rows ("2024-07-01 00:00:00" , 920 ), rows ("2024-07-02 00:00:00" , 1010 ));
543557 }
544558
545559 @ Test
@@ -552,7 +566,12 @@ public void testTimewrapMonthSpan() throws IOException {
552566
553567 verifySchema (
554568 result , schema ("@timestamp" , "timestamp" ), schema ("sum(requests)_latest_month" , "bigint" ));
555- verifyDataRowsSome (result , rows ("2024-07-01 00:00:00" , 920 ), rows ("2024-07-04 00:00:00" , 180 ));
569+ verifyDataRowsInOrder (
570+ result ,
571+ rows ("2024-07-01 00:00:00" , 920 ),
572+ rows ("2024-07-02 00:00:00" , 1010 ),
573+ rows ("2024-07-03 00:00:00" , 840 ),
574+ rows ("2024-07-04 00:00:00" , 180 ));
556575 }
557576
558577 @ Test
@@ -570,24 +589,174 @@ public void testTimewrapQuarterSpan() throws IOException {
570589 schema ("@timestamp" , "timestamp" ),
571590 schema ("sum(requests)_1quarter_before" , "bigint" ),
572591 schema ("sum(requests)_latest_quarter" , "bigint" ));
573- // Day 15 of each quarter aligns — both values on the same row
574- verifyDataRowsSome (result , rows ("2024-04-15 00:00:00" , 300 , 350 ));
592+ // Day 15 of each quarter aligns -- both values on the same row
593+ verifyDataRows (result , rows ("2024-04-15 00:00:00" , 300 , 350 ));
575594 }
576595
577596 @ Test
578597 public void testTimewrapYearSpan () throws IOException {
579- // Jan 2024 to Jan 2025 → 2 year periods (2024 and 2025)
580- // Jan 15 offset exists in both years: 2024=300, 2025=400
598+ // Jan 15 2024 (300) and Jan 15 2025 (400) -- 2 data points in 2 different years
599+ // timechart span=1year: 2 yearly buckets
600+ // timewrap 1year: 2 periods, 1 offset row
581601 JSONObject result =
582602 executeQuery (
583- "source=timewrap_test | where @timestamp >= '2024-01-15 00 :00:00' and @timestamp <="
584- + " '2025-01-15 12:00:00' | timechart span=1day sum(requests) | timewrap 1year" );
603+ "source=timewrap_test | where @timestamp >= '2024-01-15 12 :00:00' and @timestamp <="
604+ + " '2025-01-15 12:00:00' | timechart span=1year sum(requests) | timewrap 1year" );
585605
586606 verifySchema (
587607 result ,
588608 schema ("@timestamp" , "timestamp" ),
589609 schema ("sum(requests)_1year_before" , "bigint" ),
590610 schema ("sum(requests)_latest_year" , "bigint" ));
591- verifyDataRowsSome (result , rows ("2025-01-15 00:00:00" , 300 , 400 ));
611+ // 2024 yearly sum = all 2024 data in WHERE range; 2025 = Jan 15 only (400)
612+ verifyDataRows (result , rows ("2025-01-01 00:00:00" , 4050 , 400 ));
613+ }
614+
615+ // --- series parameter ---
616+
617+ @ Test
618+ public void testTimewrapSeriesRelativeIsDefault () throws IOException {
619+ // series=relative is the default — same as no series parameter
620+ JSONObject resultDefault =
621+ executeQuery (
622+ "source=timewrap_test"
623+ + WHERE_JUL1_TO_JUL3
624+ + " | timechart span=6h sum(requests) | timewrap 1day" );
625+ JSONObject resultRelative =
626+ executeQuery (
627+ "source=timewrap_test"
628+ + WHERE_JUL1_TO_JUL3
629+ + " | timechart span=6h sum(requests) | timewrap 1day series=relative" );
630+
631+ verifySchema (
632+ resultRelative ,
633+ schema ("@timestamp" , "timestamp" ),
634+ schema ("sum(requests)_2days_before" , "bigint" ),
635+ schema ("sum(requests)_1day_before" , "bigint" ),
636+ schema ("sum(requests)_latest_day" , "bigint" ));
637+ verifyDataRowsInOrder (
638+ resultRelative ,
639+ rows ("2024-07-03 00:00:00" , 180 , 205 , 165 ),
640+ rows ("2024-07-03 06:00:00" , 240 , 260 , 225 ),
641+ rows ("2024-07-03 12:00:00" , 310 , 330 , 285 ),
642+ rows ("2024-07-03 18:00:00" , 190 , 215 , 165 ));
643+ verifySchema (
644+ resultDefault ,
645+ schema ("@timestamp" , "timestamp" ),
646+ schema ("sum(requests)_2days_before" , "bigint" ),
647+ schema ("sum(requests)_1day_before" , "bigint" ),
648+ schema ("sum(requests)_latest_day" , "bigint" ));
649+ verifyDataRowsInOrder (
650+ resultDefault ,
651+ rows ("2024-07-03 00:00:00" , 180 , 205 , 165 ),
652+ rows ("2024-07-03 06:00:00" , 240 , 260 , 225 ),
653+ rows ("2024-07-03 12:00:00" , 310 , 330 , 285 ),
654+ rows ("2024-07-03 18:00:00" , 190 , 215 , 165 ));
592655 }
656+
657+ @ Test
658+ public void testTimewrapSeriesShort () throws IOException {
659+ // series=short: columns named <agg>_s<absolutePeriod>
660+ // With align=end and WHERE upper bound = Jul 3 18:00, baseOffset=0
661+ // Periods: oldest=2, middle=1, newest=0
662+ JSONObject result =
663+ executeQuery (
664+ "source=timewrap_test"
665+ + WHERE_JUL1_TO_JUL3
666+ + " | timechart span=6h sum(requests) | timewrap 1day series=short" );
667+
668+ verifySchema (
669+ result ,
670+ schema ("@timestamp" , "timestamp" ),
671+ schema ("sum(requests)_s2" , "bigint" ),
672+ schema ("sum(requests)_s1" , "bigint" ),
673+ schema ("sum(requests)_s0" , "bigint" ));
674+ verifyDataRowsInOrder (
675+ result ,
676+ rows ("2024-07-03 00:00:00" , 180 , 205 , 165 ),
677+ rows ("2024-07-03 06:00:00" , 240 , 260 , 225 ),
678+ rows ("2024-07-03 12:00:00" , 310 , 330 , 285 ),
679+ rows ("2024-07-03 18:00:00" , 190 , 215 , 165 ));
680+ }
681+
682+ @ Test
683+ public void testTimewrapSeriesShortWithCount () throws IOException {
684+ // series=short with count aggregation
685+ JSONObject result =
686+ executeQuery (
687+ "source=timewrap_test"
688+ + WHERE_JUL2_TO_JUL3
689+ + " | timechart span=6h count() | timewrap 1day series=short" );
690+
691+ verifySchema (
692+ result ,
693+ schema ("@timestamp" , "timestamp" ),
694+ schema ("count()_s1" , "bigint" ),
695+ schema ("count()_s0" , "bigint" ));
696+ verifyDataRowsInOrder (
697+ result ,
698+ rows ("2024-07-03 00:00:00" , 2 , 2 ),
699+ rows ("2024-07-03 06:00:00" , 2 , 2 ),
700+ rows ("2024-07-03 12:00:00" , 2 , 2 ),
701+ rows ("2024-07-03 18:00:00" , 2 , 2 ));
702+ }
703+
704+ @ Test
705+ public void testTimewrapSeriesShortWeekSpan () throws IOException {
706+ // series=short with week span, single period = s0, daily buckets
707+ JSONObject result =
708+ executeQuery (
709+ "source=timewrap_test"
710+ + WHERE_JUL1_TO_JUL2
711+ + " | timechart span=1day sum(requests) | timewrap 1week series=short" );
712+
713+ verifySchema (result , schema ("@timestamp" , "timestamp" ), schema ("sum(requests)_s0" , "bigint" ));
714+ verifyDataRowsInOrder (
715+ result , rows ("2024-07-01 00:00:00" , 920 ), rows ("2024-07-02 00:00:00" , 1010 ));
716+ }
717+
718+ @ Test
719+ public void testTimewrapSeriesShortWithAvg () throws IOException {
720+ JSONObject result =
721+ executeQuery (
722+ "source=timewrap_test"
723+ + WHERE_JUL1_TO_JUL2
724+ + " | timechart span=6h avg(requests) | timewrap 1day series=short" );
725+
726+ verifySchema (
727+ result ,
728+ schema ("@timestamp" , "timestamp" ),
729+ schema ("avg(requests)_s1" , "double" ),
730+ schema ("avg(requests)_s0" , "double" ));
731+ verifyDataRowsInOrder (
732+ result ,
733+ rows ("2024-07-02 00:00:00" , 90.0 , 102.5 ),
734+ rows ("2024-07-02 06:00:00" , 120.0 , 130.0 ),
735+ rows ("2024-07-02 12:00:00" , 155.0 , 165.0 ),
736+ rows ("2024-07-02 18:00:00" , 95.0 , 107.5 ));
737+ }
738+
739+ @ Test
740+ public void testTimewrapSeriesShortWithErrors () throws IOException {
741+ JSONObject result =
742+ executeQuery (
743+ "source=timewrap_test"
744+ + WHERE_JUL2_TO_JUL3
745+ + " | timechart span=6h sum(errors) | timewrap 1day series=short" );
746+
747+ verifySchema (
748+ result ,
749+ schema ("@timestamp" , "timestamp" ),
750+ schema ("sum(errors)_s1" , "bigint" ),
751+ schema ("sum(errors)_s0" , "bigint" ));
752+ verifyDataRowsInOrder (
753+ result ,
754+ rows ("2024-07-03 00:00:00" , 4 , 1 ),
755+ rows ("2024-07-03 06:00:00" , 6 , 3 ),
756+ rows ("2024-07-03 12:00:00" , 9 , 6 ),
757+ rows ("2024-07-03 18:00:00" , 3 , 1 ));
758+ }
759+
760+ // BY clause tests are pending -- blocked by timechart BY output format gap.
761+ // See docs/dev/ppl-timewrap-command.md for design options.
593762}
0 commit comments