@@ -721,6 +721,84 @@ protected function getAllSubperiodKeys(ArchiveProcessor $archiveProcessor): arra
721721 $ this ->assertSame (['/flat-path ' , '/legacy-path ' ], $ hierarchyLabels );
722722 }
723723
724+ public function testBuildForNonDayPeriodConsumesFlatTableBeforePreInsertHook (): void
725+ {
726+ $ hookState = (object ) ['flatRowsAtHook ' => null , 'hierarchyLabelsAtHook ' => []];
727+
728+ $ recordBuilder = new class ($ hookState ) extends ArchiveProcessor \RecordBuilder {
729+ private $ hookState ;
730+
731+ public function __construct (object $ hookState )
732+ {
733+ parent ::__construct ();
734+ $ this ->hookState = $ hookState ;
735+ }
736+
737+ public function getRecordMetadata (ArchiveProcessor $ archiveProcessor ): array
738+ {
739+ return [
740+ Record::make (Record::TYPE_BLOB , 'TestPlugin_hierarchy ' )
741+ ->setBuiltFromFlatRecord ('TestPlugin_flat ' , function (Row $ flatRow ): ?array {
742+ $ label = $ flatRow ->getColumn ('label ' );
743+ if (!is_string ($ label ) || $ label === '' ) {
744+ return null ;
745+ }
746+
747+ return [$ label ];
748+ }),
749+ Record::make (Record::TYPE_BLOB , 'TestPlugin_flat ' ),
750+ ];
751+ }
752+
753+ protected function aggregate (ArchiveProcessor $ archiveProcessor ): array
754+ {
755+ return [];
756+ }
757+
758+ protected function aggregateRootDataTableFromBlobs (
759+ ArchiveProcessor $ archiveProcessor ,
760+ string $ recordName ,
761+ ?array $ columnsAggregationOperation ,
762+ ?array $ columnsToRenameAfterAggregation
763+ ): array {
764+ $ table = new DataTable ();
765+ if ($ recordName === 'TestPlugin_flat ' ) {
766+ $ table ->addRowFromSimpleArray (['label ' => '/flat-path-a ' , 'nb_visits ' => 5 ]);
767+ $ table ->addRowFromSimpleArray (['label ' => '/flat-path-b ' , 'nb_visits ' => 3 ]);
768+ $ table ->addSummaryRow (new Row ([Row::COLUMNS => ['label ' => '-1 ' , 'nb_visits ' => 2 ]]));
769+
770+ return [$ table , true , ['2020-03-04,2020-03-04 ' => true ]];
771+ }
772+
773+ return [$ table , false , []];
774+ }
775+
776+ protected function getAllSubperiodKeys (ArchiveProcessor $ archiveProcessor ): array
777+ {
778+ return ['2020-03-04,2020-03-04 ' => true ];
779+ }
780+
781+ protected function beforeInsertBuiltFromFlatHierarchyRecord (
782+ ArchiveProcessor $ archiveProcessor ,
783+ Record $ hierarchicalRecord ,
784+ DataTable $ hierarchicalTable ,
785+ DataTable $ flatTable
786+ ): void {
787+ $ this ->hookState ->flatRowsAtHook = $ flatTable ->getRowsCount ();
788+ $ this ->hookState ->hierarchyLabelsAtHook = $ hierarchicalTable ->getColumn ('label ' );
789+ }
790+ };
791+
792+ $ mockArchiveProcessor = $ this ->getMockArchiveProcessor ('week ' , ['TestPlugin_flat ' ]);
793+ $ recordBuilder ->buildForNonDayPeriod ($ mockArchiveProcessor );
794+
795+ $ this ->assertSame (0 , $ hookState ->flatRowsAtHook );
796+ $ this ->assertSame (['/flat-path-a ' , '/flat-path-b ' , '-1 ' ], $ hookState ->hierarchyLabelsAtHook );
797+
798+ $ this ->assertSame (['/flat-path-a ' , '/flat-path-b ' , '-1 ' ], $ this ->getTopLevelLabelsOfInsertedBlobRecord ('TestPlugin_flat ' ));
799+ $ this ->assertSame (['/flat-path-a ' , '/flat-path-b ' , '-1 ' ], $ this ->getTopLevelLabelsOfInsertedBlobRecord ('TestPlugin_hierarchy ' ));
800+ }
801+
724802 public function testBuildForNonDayPeriodCorrectlyAggregatesMetricsForMetricsThatAreRowCountsOfRecords ()
725803 {
726804 $ recordBuilder = new class () extends ArchiveProcessor \RecordBuilder {
0 commit comments