Skip to content

Commit

Permalink
Renamed read to df()
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Nov 29, 2023
1 parent 35e18d2 commit 5eea91b
Show file tree
Hide file tree
Showing 33 changed files with 640 additions and 611 deletions.
9 changes: 4 additions & 5 deletions examples/topics/aggregations/power_plant.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

use function Flow\ETL\DSL\average;
use function Flow\ETL\DSL\concat;
use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_csv;
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\sum;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Flow;

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

$flow = (new Flow())
$df = df()
->read(from_csv(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';'))
->withEntry('production_kwh', ref('Produkcja(kWh)'))
->withEntry('consumption_kwh', ref('Zużycie(kWh)'))
Expand All @@ -32,7 +32,6 @@
sum(ref('production_kwh')),
sum(ref('consumption_kwh'))
)

->withEntry('production_kwh_avg', ref('production_kwh_avg')->round(lit(2)))
->withEntry('consumption_kwh_avg', ref('consumption_kwh_avg')->round(lit(2)))
->withEntry('production_kwh_min', ref('production_kwh_min')->round(lit(2)))
Expand All @@ -47,7 +46,7 @@
->write(to_output(truncate: false));

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
return $flow;
return $df;
}

$flow->run();
$df->run();
8 changes: 4 additions & 4 deletions examples/topics/aggregations/power_plant_bar_chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
use function Flow\ETL\DSL\average;
use function Flow\ETL\DSL\bar_chart;
use function Flow\ETL\DSL\concat;
use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_csv;
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\sum;
use function Flow\ETL\DSL\to_chartjs_file;
use Flow\ETL\Flow;

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

$flow = (new Flow)
$df = df()
->read(from_csv(__FLOW_DATA__ . '/power-plant-daily.csv', delimiter: ';'))
->withEntry('production_kwh', ref('Produkcja(kWh)'))
->withEntry('consumption_kwh', ref('Zużycie(kWh)'))
Expand Down Expand Up @@ -54,7 +54,7 @@
);

if ($_ENV['FLOW_PHAR_APP'] ?? false) {
return $flow;
return $df;
}

$flow->run();
$df->run();
9 changes: 4 additions & 5 deletions examples/topics/transformations/aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\row;
use function Flow\ETL\DSL\rows;
Expand All @@ -13,15 +13,14 @@

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

$df = read(
from_rows(rows(
$df = df()
->from(from_rows(rows(
row(int_entry('a', 100)),
row(int_entry('a', 100)),
row(int_entry('a', 200)),
row(int_entry('a', 400)),
row(int_entry('a', 400))
))
)
)))
->aggregate(sum(ref('a')))
->write(to_output(false));

Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/array_expand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

use function Flow\ETL\DSL\array_entry;
use function Flow\ETL\DSL\array_expand;
use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\row;
use function Flow\ETL\DSL\rows;
use function Flow\ETL\DSL\to_output;

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

$df = read(
from_rows(rows(
$df = df()
->read(from_rows(rows(
row(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])),
))
)
)))
->write(to_output(false))
->withEntry('expanded', array_expand(ref('array')))
->write(to_output(false));
Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/array_unpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
declare(strict_types=1);

use function Flow\ETL\DSL\array_entry;
use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::with(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])),
Row::with(int_entry('id', 2), array_entry('array', ['d' => 4, 'e' => 5, 'f' => 6])),
))
)
)))
->write(to_output(false))
->withEntry('unpacked', ref('array')->unpack())
->write(to_output(false));
Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/filter_divide.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::with(int_entry('a', 100), int_entry('b', 100)),
Row::with(int_entry('a', 100), int_entry('b', 200))
))
)
)))
->filter(ref('b')->divide(lit(2))->equals(lit('a')))
->withEntry('new_b', ref('b')->multiply(lit(2))->multiply(lit(5)))
->write(to_output(false));
Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/filter_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::with(int_entry('a', 4), int_entry('b', 5)),
Row::with(int_entry('a', 3), int_entry('b', 6))
))
)
)))
->filter(ref('b')->mod(lit(2))->equals(lit(0)))
->write(to_output(false));

Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/group_by.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::with(int_entry('a', 100)),
Row::with(int_entry('a', 100)),
Row::with(int_entry('a', 200)),
Row::with(int_entry('a', 400)),
Row::with(int_entry('a', 400))
))
)
)))
->groupBy(ref('a'))
->write(to_output(false));

Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/literals.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\str_entry;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::create(str_entry('name', 'Norbert'))
))
)
)))
->withEntry('number', lit(1))
->write(to_output(false));

Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/math.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::create(int_entry('a', 100), int_entry('b', 200))
))
)
)))
->write(to_output(false))
->withEntry('c', ref('a')->plus(ref('b')))
->withEntry('d', ref('b')->minus(ref('a')))
Expand Down
9 changes: 4 additions & 5 deletions examples/topics/transformations/size.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
declare(strict_types=1);

use function Flow\ETL\DSL\array_entry;
use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use Flow\ETL\Row;
use Flow\ETL\Rows;

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

$df = read(
from_rows(new Rows(
$df = df()
->read(from_rows(new Rows(
Row::with(int_entry('id', 1), array_entry('array', ['a' => 1, 'b' => 2, 'c' => 3])),
))
)
)))
->withEntry('array_size', ref('array')->size())
->write(to_output(false));

Expand Down
17 changes: 9 additions & 8 deletions examples/topics/transformations/when_null.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_rows;
use function Flow\ETL\DSL\int_entry;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\null_entry;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\ref;
use function Flow\ETL\DSL\to_output;
use function Flow\ETL\DSL\when;
Expand All @@ -15,13 +15,14 @@

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

$df = read(from_rows(new Rows(
Row::with(int_entry('id', 1), int_entry('value', 1)),
Row::with(int_entry('id', 2), int_entry('value', 1)),
Row::with(int_entry('id', 3), null_entry('value')),
Row::with(int_entry('id', 4), int_entry('value', 1)),
Row::with(int_entry('id', 5), null_entry('value')),
)))
$df = df()
->read(from_rows(new Rows(
Row::with(int_entry('id', 1), int_entry('value', 1)),
Row::with(int_entry('id', 2), int_entry('value', 1)),
Row::with(int_entry('id', 3), null_entry('value')),
Row::with(int_entry('id', 4), int_entry('value', 1)),
Row::with(int_entry('id', 5), null_entry('value')),
)))
->withEntry(
'value',
when(ref('value')->isNull(), then: lit(0))
Expand Down
4 changes: 2 additions & 2 deletions examples/topics/types/csv/csv_to_json.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php declare(strict_types=1);

use function Flow\ETL\DSL\df;
use function Flow\ETL\DSL\from_csv;
use function Flow\ETL\DSL\read;
use function Flow\ETL\DSL\to_json;

require __DIR__ . '/../../../bootstrap.php';
Expand All @@ -10,7 +10,7 @@
\unlink(__FLOW_OUTPUT__ . '/dataset.json');
}

$df = read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv'))->write(to_json(__FLOW_OUTPUT__ . '/dataset.json'));
$df = df()->read(from_csv(__FLOW_OUTPUT__ . '/dataset.csv'))->write(to_json(__FLOW_OUTPUT__ . '/dataset.json'));

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

0 comments on commit 5eea91b

Please sign in to comment.