-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unified behavior of first/last aggregations
- Loading branch information
1 parent
f06a032
commit 5900095
Showing
17 changed files
with
278 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
89 changes: 89 additions & 0 deletions
89
src/core/etl/tests/Flow/ETL/Tests/Integration/Function/FirstTest.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,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Function; | ||
|
||
use function Flow\ETL\DSL\{df, first, from_array}; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class FirstTest extends TestCase | ||
{ | ||
public function test_first_aggregation() : void | ||
{ | ||
$first = df() | ||
->read( | ||
from_array([ | ||
['id' => 1, 'value' => 10], | ||
['id' => 2, 'value' => 20], | ||
['id' => 3, 'value' => 30], | ||
['id' => 4, 'value' => 40], | ||
['id' => 5, 'value' => 50], | ||
]) | ||
) | ||
->aggregate(first('value')) | ||
->fetch() | ||
->toArray(); | ||
|
||
self::assertSame( | ||
[ | ||
['value_first' => 10], | ||
], | ||
$first | ||
); | ||
} | ||
|
||
public function test_first_aggregation_with_grouping() : void | ||
{ | ||
$first = df() | ||
->read( | ||
from_array([ | ||
['id' => 1, 'value' => 10, 'group' => 'A'], | ||
['id' => 2, 'value' => 20, 'group' => 'A'], | ||
['id' => 3, 'value' => 30, 'group' => 'B'], | ||
['id' => 4, 'value' => 40, 'group' => 'C'], | ||
['id' => 5, 'value' => 50, 'group' => 'B'], | ||
]) | ||
) | ||
->groupBy('group')->aggregate(first('value')) | ||
->fetch() | ||
->toArray(); | ||
|
||
self::assertSame( | ||
[ | ||
['group' => 'A', 'value_first' => 10], | ||
['group' => 'B', 'value_first' => 30], | ||
['group' => 'C', 'value_first' => 40], | ||
], | ||
$first | ||
); | ||
} | ||
|
||
public function test_first_aggregation_with_on_aggregated_column() : void | ||
{ | ||
$first = df() | ||
->read( | ||
from_array([ | ||
['id' => 1, 'value' => 10, 'group' => 'A'], | ||
['id' => 2, 'value' => 20, 'group' => 'A'], | ||
['id' => 3, 'value' => 30, 'group' => 'B'], | ||
['id' => 4, 'value' => 40, 'group' => 'C'], | ||
['id' => 5, 'value' => 50, 'group' => 'B'], | ||
]) | ||
) | ||
->groupBy('value')->aggregate(first('value')) | ||
->fetch() | ||
->toArray(); | ||
|
||
self::assertSame( | ||
[ | ||
['value' => 10, 'value_first' => 10], | ||
['value' => 20, 'value_first' => 20], | ||
['value' => 30, 'value_first' => 30], | ||
['value' => 40, 'value_first' => 40], | ||
['value' => 50, 'value_first' => 50], | ||
], | ||
$first | ||
); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/core/etl/tests/Flow/ETL/Tests/Integration/Function/LastTest.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,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Integration\Function; | ||
|
||
use function Flow\ETL\DSL\{df, from_array, last}; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class LastTest extends TestCase | ||
{ | ||
public function test_first_aggregation_with_grouping() : void | ||
{ | ||
$first = df() | ||
->read( | ||
from_array([ | ||
['id' => 1, 'value' => 10, 'group' => 'A'], | ||
['id' => 2, 'value' => 20, 'group' => 'A'], | ||
['id' => 3, 'value' => 30, 'group' => 'B'], | ||
['id' => 4, 'value' => 40, 'group' => 'C'], | ||
['id' => 5, 'value' => 50, 'group' => 'B'], | ||
]) | ||
) | ||
->groupBy('group')->aggregate(last('value')) | ||
->fetch() | ||
->toArray(); | ||
|
||
self::assertSame( | ||
[ | ||
['group' => 'A', 'value_last' => 20], | ||
['group' => 'B', 'value_last' => 50], | ||
['group' => 'C', 'value_last' => 40], | ||
], | ||
$first | ||
); | ||
} | ||
|
||
public function test_first_aggregation_with_on_aggregated_column() : void | ||
{ | ||
$first = df() | ||
->read( | ||
from_array([ | ||
['id' => 1, 'value' => 10, 'group' => 'A'], | ||
['id' => 2, 'value' => 20, 'group' => 'A'], | ||
['id' => 3, 'value' => 30, 'group' => 'B'], | ||
['id' => 4, 'value' => 40, 'group' => 'C'], | ||
['id' => 5, 'value' => 50, 'group' => 'B'], | ||
]) | ||
) | ||
->groupBy('value')->aggregate(last('value')) | ||
->fetch() | ||
->toArray(); | ||
|
||
self::assertSame( | ||
[ | ||
['value' => 10, 'value_last' => 10], | ||
['value' => 20, 'value_last' => 20], | ||
['value' => 30, 'value_last' => 30], | ||
['value' => 40, 'value_last' => 40], | ||
['value' => 50, 'value_last' => 50], | ||
], | ||
$first | ||
); | ||
} | ||
|
||
public function test_last_aggregation() : void | ||
{ | ||
$first = df() | ||
->read( | ||
from_array([ | ||
['id' => 1, 'value' => 10], | ||
['id' => 2, 'value' => 20], | ||
['id' => 3, 'value' => 30], | ||
['id' => 4, 'value' => 40], | ||
['id' => 5, 'value' => 50], | ||
]) | ||
) | ||
->aggregate(last('value')) | ||
->fetch() | ||
->toArray(); | ||
|
||
self::assertSame( | ||
[ | ||
['value_last' => 50], | ||
], | ||
$first | ||
); | ||
} | ||
} |
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
Oops, something went wrong.