From 17225a3f8c1825185f01abe3bb49e319af52c1c2 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Tue, 25 Feb 2025 14:40:35 +0100 Subject: [PATCH 1/2] Allow to pass limit as null to not break the pipeline --- src/core/etl/src/Flow/ETL/DataFrame.php | 6 +++++- .../ETL/Tests/Integration/DataFrame/LimitTest.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/etl/src/Flow/ETL/DataFrame.php b/src/core/etl/src/Flow/ETL/DataFrame.php index 8a95be11f..8f35045b6 100644 --- a/src/core/etl/src/Flow/ETL/DataFrame.php +++ b/src/core/etl/src/Flow/ETL/DataFrame.php @@ -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; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php index b33df2afe..7364f0147 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php @@ -36,6 +36,21 @@ public function test_exceeding_the_limit_in_one_rows_set() : void self::assertCount(9, $rows); } + 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_fetch_with_limit() : void { $rows = df() From 265f3cf7f298e16eb2ad90e71237d98457f04622 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Tue, 25 Feb 2025 14:44:17 +0100 Subject: [PATCH 2/2] CS Fixes --- .../etl/src/Flow/ETL/Transformation/Limit.php | 2 +- .../Tests/Integration/DataFrame/LimitTest.php | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/core/etl/src/Flow/ETL/Transformation/Limit.php b/src/core/etl/src/Flow/ETL/Transformation/Limit.php index ba0e31dd6..edbd22022 100644 --- a/src/core/etl/src/Flow/ETL/Transformation/Limit.php +++ b/src/core/etl/src/Flow/ETL/Transformation/Limit.php @@ -8,7 +8,7 @@ final readonly class Limit implements Transformation { - public function __construct(private int $limit) + public function __construct(private ?int $limit) { } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php index 7364f0147..ce8210e5c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/LimitTest.php @@ -36,21 +36,6 @@ public function test_exceeding_the_limit_in_one_rows_set() : void self::assertCount(9, $rows); } - 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_fetch_with_limit() : void { $rows = df() @@ -130,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()