Skip to content

Commit 2f72d3e

Browse files
authored
Enforce passing EntryFactory to array_to_row(s) & to_entry functions (#1932)
* Enforce passing `EntryFactory` to `array_to_row(s)` & `to_entry` functions * Enforce passing `EntryFactory` to `AggregatingFunction::result()`
1 parent 256964c commit 2f72d3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+246
-189
lines changed

documentation/components/core/building-blocks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $rows = array_to_rows([
4141
['id' => 2, 'name' => 'user_02', 'active' => false],
4242
['id' => 3, 'name' => 'user_03', 'active' => true],
4343
['id' => 4, 'name' => 'user_04', 'active' => false],
44-
]);
44+
], flow_context(config())->entryFactory());
4545
```
4646

4747
## Entry Types

documentation/upgrading.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ Please follow the instructions for your specific version to ensure a smooth upgr
55

66
---
77

8+
## Upgrading from 0.26.x to 0.27.x
9+
10+
### 1) Force `EntryFactory $entryFactory` to be required on `array_to_row` & `array_to_row(s)`
11+
12+
Before:
13+
```php
14+
to_entry('name', 'data');
15+
array_to_row([]);
16+
array_to_rows([]);
17+
```
18+
19+
After:
20+
21+
```php
22+
to_entry('name', 'data', flow_context(config())->entryFactory());
23+
array_to_row([], flow_context(config())->entryFactory());
24+
array_to_rows([], flow_context(config())->entryFactory());
25+
```
26+
827
## Upgrading from 0.16.x to 0.17.x
928

1029
### 1) Removed $nullable property from all types

src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ public function __construct()
5151
$this->randomValueGenerator = new NativePHPRandomValueGenerator();
5252
}
5353

54-
public function build() : Config
54+
public function build(EntryFactory $entryFactory = new EntryFactory()) : Config
5555
{
5656
$this->id ??= 'flow_php' . $this->randomValueGenerator->string(32);
57-
$entryFactory = new EntryFactory();
5857
$this->serializer ??= new Base64Serializer(new NativePHPSerializer());
5958
$this->clock ??= SystemClock::utc();
6059
$this->optimizer ??= new Optimizer(

src/core/etl/src/Flow/ETL/DSL/functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ function number_format(ScalarFunction|int|float $value, ScalarFunction|int $deci
15471547
* @return Entry<mixed>
15481548
*/
15491549
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
1550-
function to_entry(string $name, mixed $data, EntryFactory $entryFactory = new EntryFactory()) : Entry
1550+
function to_entry(string $name, mixed $data, EntryFactory $entryFactory) : Entry
15511551
{
15521552
return $entryFactory->create($name, $data);
15531553
}
@@ -1558,7 +1558,7 @@ function to_entry(string $name, mixed $data, EntryFactory $entryFactory = new En
15581558
* @param null|Schema $schema
15591559
*/
15601560
#[DocumentationDSL(module: Module::CORE, type: DSLType::DATA_FRAME)]
1561-
function array_to_row(array $data, EntryFactory $entryFactory = new EntryFactory(), array|Partitions $partitions = [], ?Schema $schema = null) : Row
1561+
function array_to_row(array $data, EntryFactory $entryFactory, array|Partitions $partitions = [], ?Schema $schema = null) : Row
15621562
{
15631563
$entries = [];
15641564

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

src/core/etl/src/Flow/ETL/Function/AggregatingFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Flow\ETL\Function;
66

77
use Flow\ETL\Row;
8-
use Flow\ETL\Row\Entry;
8+
use Flow\ETL\Row\{Entry, EntryFactory};
99

1010
interface AggregatingFunction
1111
{
@@ -14,5 +14,5 @@ public function aggregate(Row $row) : void;
1414
/**
1515
* @return Entry<mixed>
1616
*/
17-
public function result() : Entry;
17+
public function result(EntryFactory $entryFactory) : Entry;
1818
}

src/core/etl/src/Flow/ETL/Function/Average.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Flow\Calculator\{Calculator, Rounding};
99
use Flow\ETL\Exception\{InvalidArgumentException, RuntimeException};
1010
use Flow\ETL\Row\{Entry, Reference};
11+
use Flow\ETL\Row\EntryFactory;
1112
use Flow\ETL\{Row, Rows, Window};
1213

1314
final class Average implements AggregatingFunction, WindowFunction
@@ -65,7 +66,7 @@ public function over(Window $window) : WindowFunction
6566
return $this;
6667
}
6768

68-
public function result() : Entry
69+
public function result(EntryFactory $entryFactory) : Entry
6970
{
7071
if (!$this->ref->hasAlias()) {
7172
$this->ref->as($this->ref->to() . '_avg');

src/core/etl/src/Flow/ETL/Function/Collect.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Flow\ETL\Exception\InvalidArgumentException;
99
use Flow\ETL\Row;
1010
use Flow\ETL\Row\{Entry, Reference};
11+
use Flow\ETL\Row\EntryFactory;
1112

1213
final class Collect implements AggregatingFunction
1314
{
@@ -38,12 +39,12 @@ public function aggregate(Row $row) : void
3839
/**
3940
* @return Entry<mixed>
4041
*/
41-
public function result() : Entry
42+
public function result(EntryFactory $entryFactory) : Entry
4243
{
4344
if (!$this->ref->hasAlias()) {
4445
$this->ref->as($this->ref->name() . '_collection');
4546
}
4647

47-
return to_entry($this->ref->name(), $this->collection);
48+
return to_entry($this->ref->name(), $this->collection, $entryFactory);
4849
}
4950
}

src/core/etl/src/Flow/ETL/Function/CollectUnique.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Flow\ETL\Exception\InvalidArgumentException;
99
use Flow\ETL\Row;
1010
use Flow\ETL\Row\{Entry, Reference};
11+
use Flow\ETL\Row\EntryFactory;
1112

1213
final class CollectUnique implements AggregatingFunction
1314
{
@@ -43,12 +44,12 @@ public function aggregate(Row $row) : void
4344
/**
4445
* @return Entry<mixed>
4546
*/
46-
public function result() : Entry
47+
public function result(EntryFactory $entryFactory) : Entry
4748
{
4849
if (!$this->ref->hasAlias()) {
4950
$this->ref->as($this->ref->name() . '_collection_unique');
5051
}
5152

52-
return to_entry($this->ref->name(), $this->collection);
53+
return to_entry($this->ref->name(), $this->collection, $entryFactory);
5354
}
5455
}

src/core/etl/src/Flow/ETL/Function/Count.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use function Flow\ETL\DSL\int_entry;
88
use Flow\ETL\Exception\{InvalidArgumentException, RuntimeException};
99
use Flow\ETL\Row\{Entry, Reference};
10+
use Flow\ETL\Row\EntryFactory;
1011
use Flow\ETL\{Row, Rows, Window};
1112

1213
final class Count implements AggregatingFunction, WindowFunction
@@ -62,7 +63,7 @@ public function over(Window $window) : WindowFunction
6263
/**
6364
* @return Entry<?int>
6465
*/
65-
public function result() : Entry
66+
public function result(EntryFactory $entryFactory) : Entry
6667
{
6768
if (!$this->ref) {
6869
return int_entry('_count', $this->count);

src/core/etl/src/Flow/ETL/Function/First.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Flow\ETL\Exception\InvalidArgumentException;
99
use Flow\ETL\Row;
1010
use Flow\ETL\Row\{Entry, Reference};
11+
use Flow\ETL\Row\EntryFactory;
1112

1213
final class First implements AggregatingFunction
1314
{
@@ -35,7 +36,7 @@ public function aggregate(Row $row) : void
3536
/**
3637
* @return Entry<mixed>
3738
*/
38-
public function result() : Entry
39+
public function result(EntryFactory $entryFactory) : Entry
3940
{
4041
$name = $this->ref->hasAlias() ? $this->ref->name() : $this->ref->name() . '_first';
4142

0 commit comments

Comments
 (0)