Skip to content

Commit

Permalink
Remove StaticEntryTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Oct 6, 2023
1 parent 6ec111c commit 5d3d8da
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 141 deletions.
1 change: 0 additions & 1 deletion src/core/etl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ Adapters might also define some custom transformers.
* [keep entries](src/Flow/ETL/Transformer/KeepEntriesTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/KeepEntriesTransformerTest.php)
* [remove entries](src/Flow/ETL/Transformer/RemoveEntriesTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/RemoveEntriesTransformerTest.php)
* [rename entries](src/Flow/ETL/Transformer/RenameEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/RenameEntryTransformerTest.php)
* [static entry](src/Flow/ETL/Transformer/StaticEntryTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/StaticEntryTransformerTest.php)
* **Array**
* [array keys style converter](src/Flow/ETL/Transformer/ArrayKeysStyleConverterTransformer.php) - [tests](tests/Flow/ETL/Tests/Unit/Transformer/ArrayKeysStyleConverterTransformerTest.php)
* **Callback** - *Might come with performance degradation*
Expand Down
22 changes: 0 additions & 22 deletions src/core/etl/src/Flow/ETL/DSL/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Flow\ETL\DSL;

use Flow\ETL\DSL\Entry as DSLEntry;
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\Exception\RuntimeException;
use Flow\ETL\Row;
Expand All @@ -23,27 +22,6 @@
*/
class Transform
{
/**
* @param array<mixed> $data
*/
final public static function add_json(string $name, array $data) : Transformer
{
return new Transformer\StaticEntryTransformer(DSLEntry::json($name, $data));
}

final public static function add_json_from_string(string $name, string $json) : Transformer
{
return new Transformer\StaticEntryTransformer(DSLEntry::json($name, (array) \json_decode($json, true, 512, JSON_THROW_ON_ERROR)));
}

/**
* @param array<mixed> $data
*/
final public static function add_json_object(string $name, array $data) : Transformer
{
return new Transformer\StaticEntryTransformer(DSLEntry::json_object($name, $data));
}

/**
* @param ?Schema $schema Desired schema of unpacked elements. Elements not found in schema will be auto detected.
* It is allowed to provide definitions only for selected elements, like for example
Expand Down
40 changes: 0 additions & 40 deletions src/core/etl/src/Flow/ETL/Transformer/StaticEntryTransformer.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

declare(strict_types=1);

namespace Flow\ETL\Tests\Integration\Row\Reference\Expression;

use function Flow\ETL\DSL\array_unpack;
use function Flow\ETL\DSL\lit;
use function Flow\ETL\DSL\ref;
use Flow\ETL\DSL\From;
use Flow\ETL\DSL\To;
use Flow\ETL\Flow;
use Flow\ETL\Memory\ArrayMemory;
use PHPUnit\Framework\TestCase;

final class AddJsonTest extends TestCase
{
public function test_add_json_into_existing_reference() : void
{
(new Flow())
->read(
From::array(
[['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]],
)
)
->withEntry('row', array_unpack(ref('row')))
->renameAll('row.', '')
->drop('row')
->withEntry('array', ref('array')->arrayMerge(lit(['d' => 4])))
->write(To::memory($memory = new ArrayMemory()))
->run();

$this->assertSame(
[
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]],
],
$memory->data
);
}

public function test_add_json_string_into_existing_reference() : void
{
(new Flow())
->read(
From::array(
[['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]]],
)
)
->withEntry('row', array_unpack(ref('row')))
->renameAll('row.', '')
->drop('row')
->withEntry('json', lit('{"d": 4}'))
->withEntry('array', ref('array')->arrayMerge(ref('json')->jsonDecode()))
->drop('json')
->write(To::memory($memory = new ArrayMemory()))
->run();

$this->assertSame(
[
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]],
],
$memory->data
);
}

public function test_adding_json_as_object_from_string_entry() : void
{
(new Flow())
->read(
From::array([['id' => 1]])
)
->withEntry('row', array_unpack(ref('row')))
->renameAll('row.', '')
->drop('row')
->withEntry('json', lit(['id' => 1, 'name' => 'test']))
->withEntry('json', ref('json')->jsonEncode(\JSON_FORCE_OBJECT))
->write(To::memory($memory = new ArrayMemory()))
->run();

$this->assertSame(
[
[
'id' => 1,
'json' => '{"id":1,"name":"test"}',
],
],
$memory->data
);
}

public function test_adding_json_from_string_entry() : void
{
(new Flow())
->read(
From::array([['id' => 1]])
)
->withEntry('row', array_unpack(ref('row')))
->renameAll('row.', '')
->drop('row')
->withEntry('json', lit('[{"id":1},{"id":2}]'))
->write(To::memory($memory = new ArrayMemory()))
->run();

$this->assertSame(
[
[
'id' => 1,
'json' => '[{"id":1},{"id":2}]',
],
],
$memory->data
);
}
}

This file was deleted.

0 comments on commit 5d3d8da

Please sign in to comment.