Skip to content

Commit

Permalink
Remove covered filters from FilterRowsTransformer (#516)
Browse files Browse the repository at this point in the history
* Remove covered filters from `FilterRowsTransformer`

* Add new `IsNumeric` & `IsNotNumeric` expressions
  • Loading branch information
stloyd authored Oct 4, 2023
1 parent d9f7101 commit 947d374
Show file tree
Hide file tree
Showing 23 changed files with 82 additions and 701 deletions.
1 change: 0 additions & 1 deletion src/core/etl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ Adapters might also define some custom transformers.
* [clone entry](src/Flow/ETL/Transformer/CloneEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/CloneEntryTransformerTest.php)
* [dynamic entry](src/Flow/ETL/Transformer/DynamicEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/DynamicEntryTransformerTest.php)
* [entry name style converter](src/Flow/ETL/Transformer/EntryNameStyleConverterTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/DynamicEntryTransformerTest.php)
* [filter rows](src/Flow/ETL/Transformer/FilterRowsTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/FilterRowsTransformerTest.php)
* [group to array](src/Flow/ETL/Transformer/GroupToArrayTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/GroupToArrayTransformerTest.php)
* [keep entries](src/Flow/ETL/Transformer/KeepEntriesTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/KeepEntriesTransformerTest.php)
* [remove entries](src/Flow/ETL/Transformer/RemoveEntriesTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/RemoveEntriesTransformerTest.php)
Expand Down
6 changes: 0 additions & 6 deletions src/core/etl/docs/complex_transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ Available Filters
- [all](../src/Flow/ETL/Transformer/Filter/Filter/All.php)
- [any](../src/Flow/ETL/Transformer/Filter/Filter/Any.php)
- [callback](../src/Flow/ETL/Transformer/Filter/Filter/Callback.php)
- [entry equals to](../src/Flow/ETL/Transformer/Filter/Filter/EntryEqualsTo.php)
- [entry not equals to](../src/Flow/ETL/Transformer/Filter/Filter/EntryNotEqualsTo.php)
- [entry not null](../src/Flow/ETL/Transformer/Filter/Filter/EntryNotNull.php)
- [entry not number](../src/Flow/ETL/Transformer/Filter/Filter/EntryNotNumber.php)
- [entry number](../src/Flow/ETL/Transformer/Filter/Filter/EntryNumber.php)
- [entry exists](../src/Flow/ETL/Transformer/Filter/Filter/EntryExists.php)
- [opposite](../src/Flow/ETL/Transformer/Filter/Filter/Opposite.php)

#### Transformer - Conditional
Expand Down
46 changes: 0 additions & 46 deletions src/core/etl/src/Flow/ETL/DSL/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
use Flow\ETL\Transformer\Cast\EntryCaster\DateTimeToStringEntryCaster;
use Flow\ETL\Transformer\Cast\EntryCaster\StringToDateTimeEntryCaster;
use Flow\ETL\Transformer\CastTransformer;
use Flow\ETL\Transformer\Filter\Filter\EntryEqualsTo;
use Flow\ETL\Transformer\Filter\Filter\EntryExists;
use Flow\ETL\Transformer\Filter\Filter\EntryNotNull;
use Flow\ETL\Transformer\Filter\Filter\EntryNumber;
use Flow\ETL\Transformer\Filter\Filter\Opposite;
use Flow\ETL\Transformer\FilterRowsTransformer;
use Flow\ETL\Transformer\KeepEntriesTransformer;
use Flow\ETL\Transformer\Rename\EntryRename;
use Flow\ETL\Transformer\RenameEntriesTransformer;
Expand Down Expand Up @@ -154,46 +148,6 @@ final public static function dynamic(callable $generator) : Transformer
return new Transformer\DynamicEntryTransformer($generator);
}

final public static function filter_equals(string $entry, mixed $value) : Transformer
{
return new FilterRowsTransformer(new EntryEqualsTo($entry, $value));
}

final public static function filter_exists(string $entry) : Transformer
{
return new FilterRowsTransformer(new EntryExists($entry));
}

final public static function filter_not_equals(string $entry, mixed $value) : Transformer
{
return new FilterRowsTransformer(new Opposite(new EntryEqualsTo($entry, $value)));
}

final public static function filter_not_exists(string $entry) : Transformer
{
return new FilterRowsTransformer(new Opposite(new EntryExists($entry)));
}

final public static function filter_not_null(string $entry) : Transformer
{
return new FilterRowsTransformer(new EntryNotNull($entry));
}

final public static function filter_not_number(string $entry) : Transformer
{
return new FilterRowsTransformer(new Opposite(new EntryNumber($entry)));
}

final public static function filter_null(string $entry) : Transformer
{
return new FilterRowsTransformer(new Opposite(new EntryNotNull($entry)));
}

final public static function filter_number(string $entry) : Transformer
{
return new FilterRowsTransformer(new EntryNumber($entry));
}

final public static function group_to_array(string $group_by_entry, string $new_entry_name) : Transformer
{
return new Transformer\GroupToArrayTransformer($group_by_entry, $new_entry_name);
Expand Down
12 changes: 12 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Reference/EntryExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use Flow\ETL\Row\Reference\Expression\GreaterThanEqual;
use Flow\ETL\Row\Reference\Expression\IsIn;
use Flow\ETL\Row\Reference\Expression\IsNotNull;
use Flow\ETL\Row\Reference\Expression\IsNotNumeric;
use Flow\ETL\Row\Reference\Expression\IsNull;
use Flow\ETL\Row\Reference\Expression\IsNumeric;
use Flow\ETL\Row\Reference\Expression\IsType;
use Flow\ETL\Row\Reference\Expression\LessThan;
use Flow\ETL\Row\Reference\Expression\LessThanEqual;
Expand Down Expand Up @@ -176,11 +178,21 @@ public function isNotNull() : Expression|EntryReference
return new Expressions(new IsNotNull($this));
}

public function isNotNumeric() : Expression|EntryReference
{
return new Expressions(new IsNotNumeric($this));
}

public function isNull() : Expression|EntryReference
{
return new Expressions(new IsNull($this));
}

public function isNumeric() : Expression|EntryReference
{
return new Expressions(new IsNumeric($this));
}

public function isOdd() : Expression|EntryReference
{
return new NotEquals(new Mod($this, lit(2)), lit(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Flow\ETL\Row\Reference\Expression;

use Flow\ETL\Row;
use Flow\ETL\Row\Reference\Expression;

final class IsNotNumeric implements Expression
{
public function __construct(
private readonly Expression $ref
) {
}

public function eval(Row $row) : bool
{
return !\is_numeric($this->ref->eval($row));
}
}
21 changes: 21 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Reference/Expression/IsNumeric.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Flow\ETL\Row\Reference\Expression;

use Flow\ETL\Row;
use Flow\ETL\Row\Reference\Expression;

final class IsNumeric implements Expression
{
public function __construct(
private readonly Expression $ref
) {
}

public function eval(Row $row) : bool
{
return \is_numeric($this->ref->eval($row));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 947d374

Please sign in to comment.