-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust
Rows::chunk()
to work on generators instead of arrays (#656)
* Adjust `Rows::chunk()` to work on generators instead of arrays * Add benchmark for `Rows::chunk()` * Add `GeneratorExtractor` * Use `building_blocks` group name for the benchmark * Validate content of `GeneratorExtractor`
- Loading branch information
Showing
20 changed files
with
127 additions
and
57 deletions.
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
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
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
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
34 changes: 34 additions & 0 deletions
34
src/core/etl/src/Flow/ETL/Extractor/GeneratorExtractor.php
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Extractor; | ||
|
||
use Flow\ETL\Exception\InvalidArgumentException; | ||
use Flow\ETL\Extractor; | ||
use Flow\ETL\FlowContext; | ||
use Flow\ETL\Rows; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class GeneratorExtractor implements Extractor | ||
{ | ||
/** | ||
* @param \Generator<Rows> $rows | ||
*/ | ||
public function __construct(private readonly \Generator $rows) | ||
{ | ||
} | ||
|
||
public function extract(FlowContext $context) : \Generator | ||
{ | ||
foreach ($this->rows as $row) { | ||
if (!$row instanceof Rows) { | ||
throw new InvalidArgumentException('Passed generator can contain only Rows class instances, given: ' . $row::class); | ||
} | ||
|
||
yield $row; | ||
} | ||
} | ||
} |
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
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,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
use Flow\ETL\Rows; | ||
use PhpBench\Attributes\Groups; | ||
use PhpBench\Attributes\Iterations; | ||
use PhpBench\Attributes\Revs; | ||
|
||
#[Iterations(5)] | ||
#[Groups(['building_blocks'])] | ||
final class RowsBench | ||
{ | ||
private Rows $rows; | ||
|
||
public function __construct() | ||
{ | ||
$this->rows = Rows::fromArray( | ||
\array_merge(...\array_map(static fn () : array => [ | ||
['id' => 1, 'random' => false, 'text' => null, 'from' => 666], | ||
['id' => 2, 'random' => true, 'text' => null, 'from' => 666], | ||
['id' => 3, 'random' => false, 'text' => null, 'from' => 666], | ||
['id' => 4, 'random' => true, 'text' => null, 'from' => 666], | ||
['id' => 5, 'random' => false, 'text' => null, 'from' => 666], | ||
], \range(0, 10_000))) | ||
); | ||
} | ||
|
||
#[Revs(5)] | ||
public function bench_chunk_10() : void | ||
{ | ||
foreach ($this->rows->chunks(10) as $chunk) { | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.