Skip to content

Commit

Permalink
Feature/window functions (#797)
Browse files Browse the repository at this point in the history
* RM

* Merged together Expressions, WindowFunctions and Aggregattors

* Moved all functions under Flow/ETL/Function namespace

* Use Reference interface instead of EntryReference & removed struct function

* Removed references to word Expression from the codebase

* CS Fixes and docs

* Updated dependencies
  • Loading branch information
norberttech committed Nov 17, 2023
1 parent 2b6b153 commit 70a759e
Show file tree
Hide file tree
Showing 285 changed files with 2,569 additions and 2,676 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ $ php daily_revenue.php
## Features

* low and constant memory consumption
* asynchronous data processing
* reading from any data source
* writing to any data source
* rich collection of data transformation functions
Expand Down Expand Up @@ -196,11 +195,6 @@ In order to understand how Flow works, please read [documentation](src/core/etl/
* Pipeline - Interface representing ETL process, each received `Rows` instanced is passed through all `Pipes`, also responsible for error handling.
* Pipe - Loader of Transformer instance existing in the `Pipes` collection.

## Asynchronous Processing

* [etl-adapter-amphp](https://github.com/flow-php/etl-adapter-amphp)
* [etl-adapter-reactphp](https://github.com/flow-php/etl-adapter-reactphp)

### GitHub Stars

[![Star History Chart](https://api.star-history.com/svg?repos=flow-php/flow&type=Date)](https://star-history.com/#flow-php/flow&Date)
Expand Down
10 changes: 5 additions & 5 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ After adding native & logical types into the Flow, we remove the `CollectionEntr

## Upgrading from 0.3.x to 0.4.x

### 1) Transformers replaced with expressions
### 1) Transformers replaced with scalar functions

Transformers are a really powerful tool that was used in Flow since the beginning, but that tool was too powerful for the simple cases that were needed, and introduced additional complexity and maintenance issues when they were handwritten.

We reworked most of the internal transformers to new expressions and entry expressions (based on the built-in expressions), and we still internally use that powerful tool, but we don't expose it to end users, instead, we provide easy-to-use, covering all user needs expressions.
We reworked most of the internal transformers to new scalar functions and entry scalar functions (based on the built-in functions), and we still internally use that powerful tool, but we don't expose it to end users, instead, we provide easy-to-use, covering all user needs functions.

All available expressions can be found in [`ETL\Row\Reference\Expression` folder](src/core/etl/src/Flow/ETL/Row/Reference/Expression) or in [`ETL\DSL\functions` file](src/core/etl/src/Flow/ETL/DSL/functions.php), and entry expression are defined in [`EntryExpression` trait](src/core/etl/src/Flow/ETL/Row/Reference/EntryExpression.php).
All available functions can be found in [`ETL\Row\Function` folder](src/core/etl/src/Flow/ETL/Function) or in [`ETL\DSL\functions` file](src/core/etl/src/Flow/ETL/DSL/functions.php), and entry scalar functions are defined in [`EntryScalarFunction` trait](src/core/etl/src/Flow/ETL/Function/EntryScalarFunction.php).

To see what transformers are available see [`ETL\DSL\Transform` class](src/core/etl/src/Flow/ETL/DSL/Transform.php).

Expand Down Expand Up @@ -141,10 +141,10 @@ use Flow\ETL\Flow;
->withEntry('name', concat(ref('name'), lit(' '), ref('last name')))
```

### 2) `ref` expression nullability
### 2) `ref` function nullability

`ref("entry_name")` is no longer returning null when the entry is not found. Instead, it throws an exception.
The same behavior can be achieved through using a newly introduced `optional` expression:
The same behavior can be achieved through using a newly introduced `optional` function:

Before:
```php
Expand Down
62 changes: 31 additions & 31 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/topics/aggregations/daily_revenue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\sum;
use Flow\ETL\DSL\Parquet;
use Flow\ETL\DSL\To;
use Flow\ETL\Filesystem\SaveMode;
use Flow\ETL\Flow;
use Flow\ETL\GroupBy\Aggregation;

require __DIR__ . '/../../bootstrap.php';

Expand All @@ -19,12 +19,12 @@
->withEntry('revenue', ref('total_price')->minus(ref('discount')))
->select('created_at', 'revenue')
->groupBy('created_at')
->aggregate(Aggregation::sum(ref('revenue')))
->aggregate(sum(ref('revenue')))
->sortBy(ref('created_at')->desc())
->withEntry('daily_revenue', ref('revenue_sum')->round(lit(2)))
->withEntry('daily_revenue', ref('revenue_sum')->round(lit(2))->numberFormat(lit(2)))
->drop('revenue_sum')
->withEntry('created_at', ref('created_at')->toDate('Y/m'))
->write(To::output(truncate: false))
->withEntry('created_at', ref('created_at')->toDate('Y/m'))
->mode(SaveMode::Overwrite)
->write(Parquet::to(__FLOW_OUTPUT__ . '/daily_revenue.parquet'));

Expand Down
24 changes: 13 additions & 11 deletions examples/topics/aggregations/power_plant.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

declare(strict_types=1);

use function Flow\ETL\DSL\average;
use function Flow\ETL\DSL\concat;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\max;
use function Flow\ETL\DSL\min;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\struct;
use function Flow\ETL\DSL\sum;
use Flow\ETL\DSL\CSV;
use Flow\ETL\DSL\To;
use Flow\ETL\Flow;
use Flow\ETL\GroupBy\Aggregation;

require __DIR__ . '/../../bootstrap.php';

Expand All @@ -18,17 +20,17 @@
->withEntry('production_kwh', ref('Produkcja(kWh)'))
->withEntry('consumption_kwh', ref('Zużycie(kWh)'))
->withEntry('date', ref('Zaktualizowany czas')->toDate('Y/m/d')->dateFormat('Y/m'))
->select(struct('date', 'production_kwh', 'consumption_kwh'))
->select('date', 'production_kwh', 'consumption_kwh')
->groupBy(ref('date'))
->aggregate(
Aggregation::avg(ref('production_kwh')),
Aggregation::avg(ref('consumption_kwh')),
Aggregation::min(ref('production_kwh')),
Aggregation::min(ref('consumption_kwh')),
Aggregation::max(ref('production_kwh')),
Aggregation::max(ref('consumption_kwh')),
Aggregation::sum(ref('production_kwh')),
Aggregation::sum(ref('consumption_kwh'))
average(ref('production_kwh')),
average(ref('consumption_kwh')),
min(ref('production_kwh')),
min(ref('consumption_kwh')),
max(ref('production_kwh')),
max(ref('consumption_kwh')),
sum(ref('production_kwh')),
sum(ref('consumption_kwh'))
)

->withEntry('production_kwh_avg', ref('production_kwh_avg')->round(lit(2)))
Expand Down
24 changes: 13 additions & 11 deletions examples/topics/aggregations/power_plant_bar_chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

declare(strict_types=1);

use function Flow\ETL\DSL\average;
use function Flow\ETL\DSL\concat;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\max;
use function Flow\ETL\DSL\min;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\struct;
use function Flow\ETL\DSL\sum;
use Flow\ETL\DSL\ChartJS;
use Flow\ETL\DSL\CSV;
use Flow\ETL\Flow;
use Flow\ETL\GroupBy\Aggregation;

require __DIR__ . '/../../bootstrap.php';

Expand All @@ -18,17 +20,17 @@
->withEntry('production_kwh', ref('Produkcja(kWh)'))
->withEntry('consumption_kwh', ref('Zużycie(kWh)'))
->withEntry('date', ref('Zaktualizowany czas')->toDate('Y/m/d')->dateFormat('Y/m'))
->select(struct('date', 'production_kwh', 'consumption_kwh'))
->select('date', 'production_kwh', 'consumption_kwh')
->groupBy(ref('date'))
->aggregate(
Aggregation::avg(ref('production_kwh')),
Aggregation::avg(ref('consumption_kwh')),
Aggregation::min(ref('production_kwh')),
Aggregation::min(ref('consumption_kwh')),
Aggregation::max(ref('production_kwh')),
Aggregation::max(ref('consumption_kwh')),
Aggregation::sum(ref('production_kwh')),
Aggregation::sum(ref('consumption_kwh'))
average(ref('production_kwh')),
average(ref('consumption_kwh')),
min(ref('production_kwh')),
min(ref('consumption_kwh')),
max(ref('production_kwh')),
max(ref('consumption_kwh')),
sum(ref('production_kwh')),
sum(ref('consumption_kwh'))
)

->withEntry('production_kwh_avg', ref('production_kwh_avg')->round(lit(2)))
Expand Down
4 changes: 2 additions & 2 deletions examples/topics/transformations/aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
declare(strict_types=1);

use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\sum;
use Flow\ETL\DSL\Entry;
use Flow\ETL\DSL\From;
use Flow\ETL\DSL\To;
use Flow\ETL\Flow;
use Flow\ETL\GroupBy\Aggregation;
use Flow\ETL\Row;
use Flow\ETL\Rows;

Expand All @@ -23,7 +23,7 @@
Row::with(Entry::int('a', 400))
))
)
->aggregate(Aggregation::sum(ref('a')))
->aggregate(sum(ref('a')))
->write(To::output(false));

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
Expand Down
Loading

0 comments on commit 70a759e

Please sign in to comment.