Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fdf072
commit b0d73b8
Showing
5 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Pipeline; | ||
|
||
use Flow\ETL\Config; | ||
use Flow\ETL\Extractor; | ||
use Flow\ETL\Loader; | ||
use Flow\ETL\Pipeline; | ||
use Flow\ETL\Transformer; | ||
|
||
final class NestedPipeline implements Pipeline | ||
{ | ||
public function __construct( | ||
private readonly Pipeline $currentPipeline, | ||
private readonly Pipeline $nextPipeline | ||
) { | ||
} | ||
|
||
public function add(Loader|Transformer $pipe) : Pipeline | ||
{ | ||
$this->nextPipeline->add($pipe); | ||
|
||
return $this; | ||
} | ||
|
||
public function cleanCopy() : Pipeline | ||
{ | ||
return new self( | ||
$this->currentPipeline->cleanCopy(), | ||
$this->nextPipeline->cleanCopy(), | ||
); | ||
} | ||
|
||
public function process(Config $config) : \Generator | ||
{ | ||
foreach ($this->nextPipeline->source(new Extractor\PipelineExtractor($this->currentPipeline, $config))->process($config) as $rows) { | ||
yield $rows; | ||
} | ||
} | ||
|
||
public function source(Extractor $extractor) : Pipeline | ||
{ | ||
$this->currentPipeline->source($extractor); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Pipeline; | ||
|
||
use Flow\ETL\Config; | ||
use Flow\ETL\DSL\Entry; | ||
use Flow\ETL\DSL\Transform; | ||
use Flow\ETL\Extractor\ProcessExtractor; | ||
use Flow\ETL\Pipeline\NestedPipeline; | ||
use Flow\ETL\Pipeline\ParallelizingPipeline; | ||
use Flow\ETL\Pipeline\SynchronousPipeline; | ||
use Flow\ETL\Row; | ||
use Flow\ETL\Rows; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class NestedPipelineTest extends TestCase | ||
{ | ||
public function test_nested_pipelines() : void | ||
{ | ||
$pipeline = new NestedPipeline( | ||
(new SynchronousPipeline())->add(Transform::add_boolean('active', true)), | ||
new ParallelizingPipeline(new SynchronousPipeline(), 1) | ||
); | ||
|
||
$pipeline->source(new ProcessExtractor( | ||
new Rows( | ||
Row::create(Entry::integer('id', 1)), | ||
Row::create(Entry::integer('id', 2)) | ||
) | ||
)); | ||
|
||
$this->assertEquals( | ||
[ | ||
new Rows( | ||
Row::create(Entry::integer('id', 1), Entry::boolean('active', true)), | ||
), | ||
new Rows( | ||
Row::create(Entry::integer('id', 2), Entry::boolean('active', true)) | ||
), | ||
], | ||
\iterator_to_array($pipeline->process(Config::default())) | ||
); | ||
} | ||
} |