Skip to content

Commit 42fe036

Browse files
authored
Fixed replacing instance of dataframe when using aggregate method (#1057)
* Fixed replacing instance of dataframe when using aggregate method * Removed DataFrame::rebuild
1 parent 9c06b72 commit 42fe036

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

src/core/etl/src/Flow/ETL/DataFrame.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,16 +605,6 @@ public function printSchema(?int $limit = 20, Schema\SchemaFormatter $formatter
605605
$clone->run();
606606
}
607607

608-
/**
609-
* @lazy
610-
*
611-
* @param callable(Pipeline $pipeline, FlowContext $context) : DataFrame $callback
612-
*/
613-
public function rebuild(callable $callback) : self
614-
{
615-
return $callback($this->pipeline, $this->context);
616-
}
617-
618608
/**
619609
* @lazy
620610
*/

src/core/etl/src/Flow/ETL/DataFrame/GroupedDataFrame.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,29 @@
66

77
use Flow\ETL\Function\AggregatingFunction;
88
use Flow\ETL\Row\Reference;
9-
use Flow\ETL\{DataFrame, FlowContext, GroupBy, Pipeline};
9+
use Flow\ETL\{DataFrame, GroupBy, Pipeline};
1010

1111
final class GroupedDataFrame
1212
{
13+
/**
14+
* @var \ReflectionClass<DataFrame>
15+
*/
16+
private \ReflectionClass $dataFrameReflection;
17+
1318
public function __construct(private readonly DataFrame $df, private readonly GroupBy $groupBy)
1419
{
20+
$this->dataFrameReflection = new \ReflectionClass($this->df);
1521
}
1622

1723
public function aggregate(AggregatingFunction ...$aggregations) : DataFrame
1824
{
1925
$this->groupBy->aggregate(...$aggregations);
2026

21-
return $this->df->rebuild(function (Pipeline $pipeline, FlowContext $context) : DataFrame {
22-
return new DataFrame(
23-
new Pipeline\LinkedPipeline(new Pipeline\GroupByPipeline($this->groupBy, $pipeline)),
24-
$context
25-
);
26-
});
27+
$pipelineProperty = $this->dataFrameReflection->getProperty('pipeline');
28+
$currentPipeline = $pipelineProperty->getValue($this->df);
29+
$pipelineProperty->setValue($this->df, new Pipeline\LinkedPipeline(new Pipeline\GroupByPipeline($this->groupBy, $currentPipeline)));
30+
31+
return $this->df;
2732
}
2833

2934
public function pivot(Reference $ref) : self

src/core/etl/src/Flow/ETL/Pipeline/LinkedPipeline.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public function pipes() : Pipes
5757

5858
public function process(FlowContext $context) : \Generator
5959
{
60-
foreach ($this->nextPipeline->process($context) as $rows) {
61-
yield $rows;
62-
}
60+
return $this->nextPipeline->process($context);
6361
}
6462

6563
public function source() : Extractor

0 commit comments

Comments
 (0)