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
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public function type() : Type;
* @return TValue
*/
public function value();

/**
* @param TValue $value
*/
public function withValue(mixed $value) : self;
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/ArrayEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@ public function value() : ?array
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ public function value() : ?bool
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public function value() : ?\DateTimeInterface
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/EnumEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ public function value() : ?\UnitEnum
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ public function value() : ?float
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/IntegerEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,9 @@ public function value() : ?int
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/JsonEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,9 @@ public function value() : ?string

return \json_encode($this->value, JSON_THROW_ON_ERROR);
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/ListEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ public function value() : ?array
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value, $this->type);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/MapEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ public function value() : ?array
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value, $this->type);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/ObjectEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public function value() : ?object
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/StringEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ public function value() : ?string
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/StructureEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ public function value() : ?array
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value, $this->type);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/UuidEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,9 @@ public function value() : ?Uuid
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/XMLElementEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,9 @@ public function value() : ?\DOMElement
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
5 changes: 5 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entry/XMLEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,9 @@ public function value() : ?\DOMDocument
{
return $this->value;
}

public function withValue(mixed $value) : Entry
{
return new self($this->name, $value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Flow\ETL\Tests\Integration\DataFrame;

use function Flow\ETL\DSL\{df,
from_array,
int_schema,
list_schema,
schema,
type_list,
type_string};
use Flow\ETL\Row;
use Flow\ETL\Tests\Integration\IntegrationTestCase;

final class MapTest extends IntegrationTestCase
{
public function test_using_map_to_replace_nullable_lists() : void
{
$rows = df()
->read(
from_array(
[
['id' => 1, 'tags' => ['A', 'B']],
['id' => 2, 'tags' => null],
['id' => 3, 'tags' => ['D']],
]
)->withSchema(
schema(
int_schema('id'),
list_schema('tags', type_list(type_string(), true))
)
)
)
->map(
fn (Row $row) : Row => $row->map(fn (Row\Entry $e) => $e->value() === null && $e->is('tags') ? $e->withValue([]) : $e)
)
->fetch();

self::assertEquals(
[
['id' => 1, 'tags' => ['A', 'B']],
['id' => 2, 'tags' => []],
['id' => 3, 'tags' => ['D']],
],
$rows->toArray()
);
}

public function test_using_map_to_replace_nulls() : void
{
$rows = df()
->read(from_array([
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => null],
['id' => 3, 'name' => 'Doe'],
]))
->map(
fn (Row $row) : Row => $row->map(fn (Row\Entry $e) => $e->value() === null && $e->is('name') ? $e->withValue('N/A') : $e)
)
->fetch();

self::assertEquals(
[
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => 'N/A'],
['id' => 3, 'name' => 'Doe'],
],
$rows->toArray()
);
}
}
Loading