Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass limit as null to not break the pipeline #1498

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/etl/src/Flow/ETL/DataFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,12 @@ public function joinEach(DataFrameFactory $factory, Expression $on, string|Join
*
* @throws InvalidArgumentException
*/
public function limit(int $limit) : self
public function limit(?int $limit) : self
{
if ($limit === null) {
return $this;
}

$this->pipeline = $this->context->config->optimizer()->optimize(new LimitTransformer($limit), $this->pipeline);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/core/etl/src/Flow/ETL/Transformation/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final readonly class Limit implements Transformation
{
public function __construct(private int $limit)
public function __construct(private ?int $limit)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ public function test_limit_below_0() : void
df()->read(from_rows(\Flow\ETL\DSL\rows()))->limit(-1);
}

public function test_limit_null() : void
{
$rows = df()
->read(from_array(
\array_map(
fn (int $id) : array => ['id' => $id],
\range(1, 10)
)
))
->limit(null)
->fetch();

self::assertCount(10, $rows);
}

public function test_limit_when_transformation_is_expanding_rows_extracted_from_extractor() : void
{
$rows = df()
Expand Down