-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DataFrame::dropPartitions() transformation (#922)
- Loading branch information
1 parent
349f4d2
commit 75d183d
Showing
5 changed files
with
115 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
src/core/etl/src/Flow/ETL/Transformer/DropPartitionsTransformer.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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Transformer; | ||
|
||
use Flow\ETL\FlowContext; | ||
use Flow\ETL\Rows; | ||
use Flow\ETL\Transformer; | ||
|
||
final class DropPartitionsTransformer implements Transformer | ||
{ | ||
public function transform(Rows $rows, FlowContext $context) : Rows | ||
{ | ||
if ($rows->isPartitioned()) { | ||
return $rows->dropPartitions(); | ||
} | ||
|
||
return $rows; | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/DropPartitionsTransformerTest.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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\Transformer; | ||
|
||
use function Flow\ETL\DSL\array_to_rows; | ||
use function Flow\ETL\DSL\flow_context; | ||
use function Flow\ETL\DSL\ref; | ||
use Flow\ETL\Transformer\DropPartitionsTransformer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class DropPartitionsTransformerTest extends TestCase | ||
{ | ||
public function test_dropping_partitions() : void | ||
{ | ||
$partitioned = array_to_rows([ | ||
['id' => 1, 'name' => 'one', 'category' => 'a'], | ||
['id' => 2, 'name' => 'two', 'category' => 'a'], | ||
['id' => 3, 'name' => 'three', 'category' => 'a'], | ||
['id' => 4, 'name' => 'four', 'category' => 'a'], | ||
['id' => 5, 'name' => 'five', 'category' => 'a'], | ||
['id' => 6, 'name' => 'six', 'category' => 'b'], | ||
['id' => 7, 'name' => 'seven', 'category' => 'b'], | ||
['id' => 8, 'name' => 'eight', 'category' => 'b'], | ||
['id' => 9, 'name' => 'nine', 'category' => 'b'], | ||
['id' => 10, 'name' => 'ten', 'category' => 'b'], | ||
])->partitionBy(ref('category')); | ||
|
||
foreach ($partitioned as $rows) { | ||
$this->assertTrue($rows->isPartitioned()); | ||
|
||
$notPartitioned = (new DropPartitionsTransformer())->transform($rows, flow_context()); | ||
|
||
$this->assertFalse($notPartitioned->isPartitioned()); | ||
} | ||
} | ||
|
||
public function test_transforming_not_partitioned_rows() : void | ||
{ | ||
$rows = array_to_rows([ | ||
['id' => 1, 'name' => 'one', 'category' => 'a'], | ||
['id' => 2, 'name' => 'two', 'category' => 'a'], | ||
['id' => 3, 'name' => 'three', 'category' => 'a'], | ||
['id' => 4, 'name' => 'four', 'category' => 'a'], | ||
['id' => 5, 'name' => 'five', 'category' => 'a'], | ||
['id' => 6, 'name' => 'six', 'category' => 'b'], | ||
['id' => 7, 'name' => 'seven', 'category' => 'b'], | ||
['id' => 8, 'name' => 'eight', 'category' => 'b'], | ||
['id' => 9, 'name' => 'nine', 'category' => 'b'], | ||
['id' => 10, 'name' => 'ten', 'category' => 'b'], | ||
]); | ||
|
||
$this->assertSame( | ||
$rows, | ||
(new DropPartitionsTransformer())->transform($rows, flow_context()) | ||
); | ||
} | ||
} |