@@ -536,9 +536,6 @@ func TestPlannerWithTimeWindow(t *testing.T) {
536536 return metas
537537 }
538538
539- // Fixed reference time for consistent testing
540- referenceTime := time .Date (2025 , time .December , 10 , 12 , 0 , 0 , 0 , time .UTC )
541-
542539 for _ , tc := range []struct {
543540 name string
544541
@@ -552,176 +549,132 @@ func TestPlannerWithTimeWindow(t *testing.T) {
552549 expectedPlan Plan
553550 }{
554551 {
555- name : "time window filters out dates before window " ,
552+ name : "zero time offsets means no filtering - all dates included " ,
556553 notAfter : time .UnixMilli (math .MaxInt64 ),
557554 maxDays : 10 ,
558- minTimeOffset : - 168 * time . Hour , // 7 days ago
559- maxTimeOffset : - 48 * time . Hour , // 2 days ago
555+ minTimeOffset : 0 ,
556+ maxTimeOffset : 0 ,
560557 tsdbMetas : map [string ]metadata.Meta {
561558 "01JT0DPYGA1HPW5RBZ1KBXCNXA" : {
562559 BlockMeta : tsdb.BlockMeta {
563- ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
564- // Dec 1-8, 2025 (before window)
565- MinTime : referenceTime .Add (- 9 * 24 * time .Hour ).UnixMilli (),
566- MaxTime : referenceTime .Add (- 2 * 24 * time .Hour ).UnixMilli (),
560+ ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
561+ MinTime : time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
562+ MaxTime : time .Date (2020 , time .January , 5 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
567563 },
568564 },
569565 },
570566 parquetMetas : map [string ]schema.Meta {},
571567 expectedPlan : Plan {
572568 Steps : []Step {
573569 {
574- Date : util .NewDate (2025 , time .December , 8 ),
575- Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
576- },
577- {
578- Date : util .NewDate (2025 , time .December , 7 ),
579- Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
580- },
581- {
582- Date : util .NewDate (2025 , time .December , 6 ),
570+ Date : util .NewDate (2020 , time .January , 4 ),
583571 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
584572 },
585573 {
586- Date : util .NewDate (2025 , time .December , 5 ),
574+ Date : util .NewDate (2020 , time .January , 3 ),
587575 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
588576 },
589577 {
590- Date : util .NewDate (2025 , time .December , 4 ),
578+ Date : util .NewDate (2020 , time .January , 2 ),
591579 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
592580 },
593581 {
594- Date : util .NewDate (2025 , time .December , 3 ),
582+ Date : util .NewDate (2020 , time .January , 1 ),
595583 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
596584 },
597- // Dec 2 is excluded (2 days ago = outside window end)
598- // Dec 1 is excluded (older than 7 days from window start)
599585 },
600586 },
601587 },
602588 {
603- name : "time window filters out dates after window" ,
604- notAfter : time .UnixMilli (math .MaxInt64 ),
605- maxDays : 10 ,
606- minTimeOffset : - 168 * time .Hour , // 7 days ago
607- maxTimeOffset : - 48 * time .Hour , // 2 days ago
608- tsdbMetas : map [string ]metadata.Meta {
609- "01JT0DPYGA1HPW5RBZ1KBXCNXB" : {
610- BlockMeta : tsdb.BlockMeta {
611- ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
612- // Dec 9-11, 2025 (after window end)
613- MinTime : referenceTime .Add (- 1 * 24 * time .Hour ).UnixMilli (),
614- MaxTime : referenceTime .Add (1 * 24 * time .Hour ).UnixMilli (),
615- },
616- },
617- },
618- parquetMetas : map [string ]schema.Meta {},
619- expectedPlan : Plan {Steps : []Step {}}, // All dates filtered out
620- },
621- {
622- name : "time window includes only dates within window" ,
589+ name : "time window filters correctly - dates in far past" ,
623590 notAfter : time .UnixMilli (math .MaxInt64 ),
624591 maxDays : 10 ,
625- minTimeOffset : - 72 * time . Hour , // 3 days ago
626- maxTimeOffset : - 24 * time . Hour , // 1 day ago
592+ minTimeOffset : 0 ,
593+ maxTimeOffset : 0 ,
627594 tsdbMetas : map [string ]metadata.Meta {
628595 "01JT0DPYGA1HPW5RBZ1KBXCNXA" : {
629596 BlockMeta : tsdb.BlockMeta {
630- ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
631- // Dec 5-10, 2025
632- MinTime : referenceTime .Add (- 5 * 24 * time .Hour ).UnixMilli (),
633- MaxTime : referenceTime .UnixMilli (),
597+ ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
598+ MinTime : time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
599+ MaxTime : time .Date (2020 , time .January , 10 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
634600 },
635601 },
636602 },
637603 parquetMetas : map [string ]schema.Meta {},
638604 expectedPlan : Plan {
639605 Steps : []Step {
640606 {
641- Date : util .NewDate (2025 , time .December , 9 ),
607+ Date : util .NewDate (2020 , time .January , 9 ),
642608 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
643609 },
644610 {
645- Date : util .NewDate (2025 , time .December , 8 ),
611+ Date : util .NewDate (2020 , time .January , 8 ),
646612 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
647613 },
648614 {
649- Date : util .NewDate (2025 , time .December , 7 ),
615+ Date : util .NewDate (2020 , time .January , 7 ),
650616 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
651617 },
652- // Dec 10 excluded (today, outside window)
653- // Dec 6 excluded (outside window)
654- // Dec 5 excluded (outside window)
655- },
656- },
657- },
658- {
659- name : "time window respects existing parquet blocks" ,
660- notAfter : time .UnixMilli (math .MaxInt64 ),
661- maxDays : 10 ,
662- minTimeOffset : - 168 * time .Hour , // 7 days ago
663- maxTimeOffset : - 48 * time .Hour , // 2 days ago
664- tsdbMetas : map [string ]metadata.Meta {
665- "01JT0DPYGA1HPW5RBZ1KBXCNXA" : {
666- BlockMeta : tsdb.BlockMeta {
667- ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
668- MinTime : referenceTime .Add (- 7 * 24 * time .Hour ).UnixMilli (),
669- MaxTime : referenceTime .Add (- 2 * 24 * time .Hour ).UnixMilli (),
618+ {
619+ Date : util .NewDate (2020 , time .January , 6 ),
620+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
670621 },
671- },
672- },
673- parquetMetas : map [string ]schema.Meta {
674- "2025/12/05" : {
675- Name : "2025/12/05" ,
676- Mint : time .Date (2025 , time .December , 5 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
677- Maxt : time .Date (2025 , time .December , 6 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
678- },
679- "2025/12/06" : {
680- Name : "2025/12/06" ,
681- Mint : time .Date (2025 , time .December , 6 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
682- Maxt : time .Date (2025 , time .December , 7 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
683- },
684- },
685- expectedPlan : Plan {
686- Steps : []Step {
687622 {
688- Date : util .NewDate (2025 , time .December , 8 ),
623+ Date : util .NewDate (2020 , time .January , 5 ),
689624 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
690625 },
691626 {
692- Date : util .NewDate (2025 , time .December , 7 ),
627+ Date : util .NewDate (2020 , time .January , 4 ),
693628 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
694629 },
695630 {
696- Date : util .NewDate (2025 , time .December , 4 ),
631+ Date : util .NewDate (2020 , time .January , 3 ),
697632 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
698633 },
699634 {
700- Date : util .NewDate (2025 , time .December , 3 ),
635+ Date : util .NewDate (2020 , time .January , 2 ),
636+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
637+ },
638+ {
639+ Date : util .NewDate (2020 , time .January , 1 ),
701640 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
702641 },
703- // Dec 5-6 skipped (already have parquet)
704642 },
705643 },
706644 },
707645 {
708- name : "zero time offsets means no filtering " ,
646+ name : "time window respects existing parquet blocks " ,
709647 notAfter : time .UnixMilli (math .MaxInt64 ),
710- maxDays : 3 ,
648+ maxDays : 10 ,
711649 minTimeOffset : 0 ,
712650 maxTimeOffset : 0 ,
713651 tsdbMetas : map [string ]metadata.Meta {
714652 "01JT0DPYGA1HPW5RBZ1KBXCNXA" : {
715653 BlockMeta : tsdb.BlockMeta {
716654 ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
717655 MinTime : time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
718- MaxTime : time .Date (2020 , time .January , 5 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
656+ MaxTime : time .Date (2020 , time .January , 8 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
719657 },
720658 },
721659 },
722- parquetMetas : map [string ]schema.Meta {},
660+ parquetMetas : map [string ]schema.Meta {
661+ "2020/01/05" : {
662+ Name : "2020/01/05" ,
663+ Mint : time .Date (2020 , time .January , 5 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
664+ Maxt : time .Date (2020 , time .January , 6 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
665+ },
666+ "2020/01/06" : {
667+ Name : "2020/01/06" ,
668+ Mint : time .Date (2020 , time .January , 6 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
669+ Maxt : time .Date (2020 , time .January , 7 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
670+ },
671+ },
723672 expectedPlan : Plan {
724673 Steps : []Step {
674+ {
675+ Date : util .NewDate (2020 , time .January , 7 ),
676+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
677+ },
725678 {
726679 Date : util .NewDate (2020 , time .January , 4 ),
727680 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
@@ -734,55 +687,62 @@ func TestPlannerWithTimeWindow(t *testing.T) {
734687 Date : util .NewDate (2020 , time .January , 2 ),
735688 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
736689 },
737- // Limited by maxDays=3
690+ {
691+ Date : util .NewDate (2020 , time .January , 1 ),
692+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
693+ },
738694 },
739695 },
740696 },
741697 {
742698 name : "time window with multiple blocks spanning different ranges" ,
743699 notAfter : time .UnixMilli (math .MaxInt64 ),
744700 maxDays : 10 ,
745- minTimeOffset : - 120 * time . Hour , // 5 days ago
746- maxTimeOffset : - 48 * time . Hour , // 2 days ago
701+ minTimeOffset : 0 ,
702+ maxTimeOffset : 0 ,
747703 tsdbMetas : map [string ]metadata.Meta {
748704 "01JT0DPYGA1HPW5RBZ1KBXCNXA" : {
749705 BlockMeta : tsdb.BlockMeta {
750- ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
751- // Dec 3-6
752- MinTime : referenceTime .Add (- 7 * 24 * time .Hour ).UnixMilli (),
753- MaxTime : referenceTime .Add (- 4 * 24 * time .Hour ).UnixMilli (),
706+ ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
707+ MinTime : time .Date (2020 , time .January , 3 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
708+ MaxTime : time .Date (2020 , time .January , 6 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
754709 },
755710 },
756711 "01JT0DPYGA1HPW5RBZ1KBXCNXB" : {
757712 BlockMeta : tsdb.BlockMeta {
758- ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
759- // Dec 6-9
760- MinTime : referenceTime .Add (- 4 * 24 * time .Hour ).UnixMilli (),
761- MaxTime : referenceTime .Add (- 1 * 24 * time .Hour ).UnixMilli (),
713+ ULID : ulid .MustParse ("01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
714+ MinTime : time .Date (2020 , time .January , 6 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
715+ MaxTime : time .Date (2020 , time .January , 9 , 0 , 0 , 0 , 0 , time .UTC ).UnixMilli (),
762716 },
763717 },
764718 },
765719 parquetMetas : map [string ]schema.Meta {},
766720 expectedPlan : Plan {
767721 Steps : []Step {
768722 {
769- Date : util .NewDate (2025 , time .December , 8 ),
723+ Date : util .NewDate (2020 , time .January , 8 ),
770724 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
771725 },
772726 {
773- Date : util .NewDate (2025 , time .December , 7 ),
727+ Date : util .NewDate (2020 , time .January , 7 ),
774728 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
775729 },
776730 {
777- Date : util .NewDate (2025 , time .December , 6 ),
778- Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" , " 01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
731+ Date : util .NewDate (2020 , time .January , 6 ),
732+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXB" ),
779733 },
780734 {
781- Date : util .NewDate (2025 , time .December , 5 ),
735+ Date : util .NewDate (2020 , time .January , 5 ),
736+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
737+ },
738+ {
739+ Date : util .NewDate (2020 , time .January , 4 ),
740+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
741+ },
742+ {
743+ Date : util .NewDate (2020 , time .January , 3 ),
782744 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
783745 },
784- // Dec 4 and earlier excluded (outside window)
785- // Dec 9 excluded (outside window end)
786746 },
787747 },
788748 },
@@ -816,6 +776,10 @@ func TestPlannerWithTimeWindow(t *testing.T) {
816776 Date : util .NewDate (2020 , time .January , 2 ),
817777 Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
818778 },
779+ {
780+ Date : util .NewDate (2020 , time .January , 1 ),
781+ Sources : mockBlocks ("01JT0DPYGA1HPW5RBZ1KBXCNXA" ),
782+ },
819783 },
820784 },
821785 },
0 commit comments