Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/components/core/building-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $rows = array_to_rows([
['id' => 2, 'name' => 'user_02', 'active' => false],
['id' => 3, 'name' => 'user_03', 'active' => true],
['id' => 4, 'name' => 'user_04', 'active' => false],
]);
], flow_context(config())->entryFactory());
```

## Entry Types
Expand Down
19 changes: 19 additions & 0 deletions documentation/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ Please follow the instructions for your specific version to ensure a smooth upgr

---

## Upgrading from 0.26.x to 0.27.x

### 1) Force `EntryFactory $entryFactory` to be required on `array_to_row` & `array_to_row(s)`

Before:
```php
to_entry('name', 'data');
array_to_row([]);
array_to_rows([]);
```

After:

```php
to_entry('name', 'data', flow_context(config())->entryFactory());
array_to_row([], flow_context(config())->entryFactory());
array_to_rows([], flow_context(config())->entryFactory());
```

## Upgrading from 0.16.x to 0.17.x

### 1) Removed $nullable property from all types
Expand Down
3 changes: 1 addition & 2 deletions src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public function __construct()
$this->randomValueGenerator = new NativePHPRandomValueGenerator();
}

public function build() : Config
public function build(EntryFactory $entryFactory = new EntryFactory()) : Config
{
$this->id ??= 'flow_php' . $this->randomValueGenerator->string(32);
$entryFactory = new EntryFactory();
$this->serializer ??= new Base64Serializer(new NativePHPSerializer());
$this->clock ??= SystemClock::utc();
$this->optimizer ??= new Optimizer(
Expand Down
6 changes: 3 additions & 3 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ function number_format(ScalarFunction|int|float $value, ScalarFunction|int $deci
* @return Entry<mixed>
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
function to_entry(string $name, mixed $data, EntryFactory $entryFactory = new EntryFactory()) : Entry
function to_entry(string $name, mixed $data, EntryFactory $entryFactory) : Entry
{
return $entryFactory->create($name, $data);
}
Expand All @@ -1558,7 +1558,7 @@ function to_entry(string $name, mixed $data, EntryFactory $entryFactory = new En
* @param null|Schema $schema
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
function array_to_row(array $data, EntryFactory $entryFactory = new EntryFactory(), array|Partitions $partitions = [], ?Schema $schema = null) : Row
function array_to_row(array $data, EntryFactory $entryFactory, array|Partitions $partitions = [], ?Schema $schema = null) : Row
{
$entries = [];

Expand Down Expand Up @@ -1603,7 +1603,7 @@ function array_to_row(array $data, EntryFactory $entryFactory = new EntryFactory
* @param null|Schema $schema
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
function array_to_rows(array $data, EntryFactory $entryFactory = new EntryFactory(), array|Partitions $partitions = [], ?Schema $schema = null) : Rows
function array_to_rows(array $data, EntryFactory $entryFactory, array|Partitions $partitions = [], ?Schema $schema = null) : Rows
{
$partitions = \is_array($partitions) ? new Partitions(...$partitions) : $partitions;

Expand Down
4 changes: 2 additions & 2 deletions src/core/etl/src/Flow/ETL/Function/AggregatingFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Flow\ETL\Function;

use Flow\ETL\Row;
use Flow\ETL\Row\Entry;
use Flow\ETL\Row\{Entry, EntryFactory};

interface AggregatingFunction
{
Expand All @@ -14,5 +14,5 @@ public function aggregate(Row $row) : void;
/**
* @return Entry<mixed>
*/
public function result() : Entry;
public function result(EntryFactory $entryFactory) : Entry;
}
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Average.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\Calculator\{Calculator, Rounding};
use Flow\ETL\Exception\{InvalidArgumentException, RuntimeException};
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;
use Flow\ETL\{Row, Rows, Window};

final class Average implements AggregatingFunction, WindowFunction
Expand Down Expand Up @@ -65,7 +66,7 @@ public function over(Window $window) : WindowFunction
return $this;
}

public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->to() . '_avg');
Expand Down
5 changes: 3 additions & 2 deletions src/core/etl/src/Flow/ETL/Function/Collect.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;

final class Collect implements AggregatingFunction
{
Expand Down Expand Up @@ -38,12 +39,12 @@ public function aggregate(Row $row) : void
/**
* @return Entry<mixed>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->name() . '_collection');
}

return to_entry($this->ref->name(), $this->collection);
return to_entry($this->ref->name(), $this->collection, $entryFactory);
}
}
5 changes: 3 additions & 2 deletions src/core/etl/src/Flow/ETL/Function/CollectUnique.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;

final class CollectUnique implements AggregatingFunction
{
Expand Down Expand Up @@ -43,12 +44,12 @@ public function aggregate(Row $row) : void
/**
* @return Entry<mixed>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->name() . '_collection_unique');
}

return to_entry($this->ref->name(), $this->collection);
return to_entry($this->ref->name(), $this->collection, $entryFactory);
}
}
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use function Flow\ETL\DSL\int_entry;
use Flow\ETL\Exception\{InvalidArgumentException, RuntimeException};
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;
use Flow\ETL\{Row, Rows, Window};

final class Count implements AggregatingFunction, WindowFunction
Expand Down Expand Up @@ -62,7 +63,7 @@ public function over(Window $window) : WindowFunction
/**
* @return Entry<?int>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref) {
return int_entry('_count', $this->count);
Expand Down
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;

final class First implements AggregatingFunction
{
Expand Down Expand Up @@ -35,7 +36,7 @@ public function aggregate(Row $row) : void
/**
* @return Entry<mixed>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
$name = $this->ref->hasAlias() ? $this->ref->name() : $this->ref->name() . '_first';

Expand Down
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;

final class Last implements AggregatingFunction
{
Expand All @@ -33,7 +34,7 @@ public function aggregate(Row $row) : void
/**
* @return Entry<mixed>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
$name = $this->ref->hasAlias() ? $this->ref->name() : $this->ref->name() . '_last';

Expand Down
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Max.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;

final class Max implements AggregatingFunction
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public function aggregate(Row $row) : void
/**
* @return Entry<?\DateTimeInterface>|Entry<?float>|Entry<?int>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->to() . '_max');
Expand Down
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Min.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;

final class Min implements AggregatingFunction
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public function aggregate(Row $row) : void
/**
* @return Entry<?\DateTimeInterface>|Entry<?float>|Entry<?int>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->to() . '_min');
Expand Down
8 changes: 5 additions & 3 deletions src/core/etl/src/Flow/ETL/Function/OnEach.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Flow\ETL\Function;

use function Flow\ETL\DSL\array_to_row;
use function Flow\ETL\DSL\{array_to_row, config, flow_context};
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Row;

Expand Down Expand Up @@ -33,16 +33,18 @@ public function eval(Row $row) : mixed

$output = [];

$entryFactory = flow_context(config())->entryFactory();

foreach ($value as $key => $item) {
if ($preserveKeys) {
try {
$output[$key] = (new Parameter($this->function))->eval(array_to_row(['element' => $item]));
$output[$key] = (new Parameter($this->function))->eval(array_to_row(['element' => $item], $entryFactory));
} catch (InvalidArgumentException) {
$output[$key] = null;
}
} else {
try {
$output[] = (new Parameter($this->function))->eval(array_to_row(['element' => $item]));
$output[] = (new Parameter($this->function))->eval(array_to_row(['element' => $item], $entryFactory));
} catch (InvalidArgumentException) {
$output[] = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/etl/src/Flow/ETL/Function/StringAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function Flow\ETL\DSL\str_entry;
use Flow\ETL\Row;
use Flow\ETL\Row\Entry;
use Flow\ETL\Row\{Entry, EntryFactory};
use Flow\ETL\Row\{Reference, SortOrder};

final class StringAggregate implements AggregatingFunction
Expand All @@ -32,7 +32,7 @@ public function aggregate(Row $row) : void
/**
* @return Row\Entry<?string>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->to() . '_str_agg');
Expand Down
3 changes: 2 additions & 1 deletion src/core/etl/src/Flow/ETL/Function/Sum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flow\Calculator\Calculator;
use Flow\ETL\Exception\{InvalidArgumentException, RuntimeException};
use Flow\ETL\Row\{Entry, Reference};
use Flow\ETL\Row\EntryFactory;
use Flow\ETL\{Row, Rows, Window};

final class Sum implements AggregatingFunction, WindowFunction
Expand Down Expand Up @@ -63,7 +64,7 @@ public function over(Window $window) : WindowFunction
/**
* @return Entry<?float>|Entry<?int>
*/
public function result() : Entry
public function result(EntryFactory $entryFactory) : Entry
{
if (!$this->ref->hasAlias()) {
$this->ref->as($this->ref->to() . '_sum');
Expand Down
5 changes: 2 additions & 3 deletions src/core/etl/src/Flow/ETL/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function result(FlowContext $context) : Rows

foreach ($columns as $rowIndex => $values) {
$row[$rowIndex] = $values instanceof AggregatingFunction
? $values->result()->value()
? $values->result($context->entryFactory())->value()
: $values;
}

Expand All @@ -175,7 +175,6 @@ public function result(FlowContext $context) : Rows
}

return array_to_rows($rows, $context->entryFactory());

}

foreach ($this->groupedTable as $group) {
Expand All @@ -187,7 +186,7 @@ public function result(FlowContext $context) : Rows
}

foreach ($group['aggregators'] as $aggregator) {
$entries[] = $aggregator->result();
$entries[] = $aggregator->result($context->entryFactory());
}

if (\count($entries)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Flow\ETL\Tests\Benchmark\EntryFactory;

use function Flow\ETL\DSL\array_to_rows;
use Flow\ETL\Row\EntryFactory;
use function Flow\ETL\DSL\{array_to_rows, config, flow_context};
use PhpBench\Attributes\{Groups, ParamProviders};

#[Groups(['building_blocks'])]
Expand All @@ -18,7 +17,7 @@ final class EntryFactoryBench
public function bench_entry_factory(array $params) : void
{
/** @phpstan-ignore-next-line */
array_to_rows($params['rows'], new EntryFactory());
array_to_rows($params['rows'], flow_context(config())->entryFactory());
}

public function provideRows() : \Generator
Expand Down
8 changes: 5 additions & 3 deletions src/core/etl/tests/Flow/ETL/Tests/Benchmark/RowsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Flow\ETL\Tests\Benchmark;

use function Flow\ETL\DSL\{array_to_rows, ref, string_entry};
use function Flow\ETL\DSL\{array_to_rows, config, flow_context, ref, string_entry};
use Flow\ETL\{Row, Rows};
use PhpBench\Attributes\{BeforeMethods, Groups, Revs};

Expand All @@ -26,7 +26,8 @@ public function setUp() : void
['id' => 3, 'random' => false, 'text' => null, 'from' => 666],
['id' => 4, 'random' => true, 'text' => null, 'from' => 666],
['id' => 5, 'random' => false, 'text' => null, 'from' => 666],
], \range(0, 10_000)))
], \range(0, 10_000))),
flow_context(config())->entryFactory(),
);

$this->reducedRows = array_to_rows(
Expand All @@ -36,7 +37,8 @@ public function setUp() : void
['id' => 3, 'random' => false, 'text' => null, 'from' => 666],
['id' => 4, 'random' => true, 'text' => null, 'from' => 666],
['id' => 5, 'random' => false, 'text' => null, 'from' => 666],
], \range(0, 1000)))
], \range(0, 1000))),
flow_context(config())->entryFactory(),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function setUp() : void
['id' => 4, 'random text' => null, 'from' => 666],
['id' => 5, 'random text' => null, 'from' => 666],
], \range(0, 1_000))),
flow_context(config())->entryFactory(),
);
$this->context = flow_context(config());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function setUp() : void
['id' => 3, 'random' => false, 'text' => null, 'from' => 666],
['id' => 4, 'random' => true, 'text' => null, 'from' => 666],
['id' => 5, 'random' => false, 'text' => null, 'from' => 666],
], \range(0, 10_000)))
], \range(0, 10_000))),
flow_context(config())->entryFactory(),
);
$this->context = flow_context(config());
}
Expand Down
Loading
Loading