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
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,19 @@ public function test_run_schema_with_table_output_on_json() : void

self::assertSame(
<<<'OUTPUT'
+--------------+-----------+----------+----------+
| name | type | nullable | metadata |
+--------------+-----------+----------+----------+
| order_id | uuid | false | [] |
| created_at | datetime | false | [] |
| updated_at | datetime | false | [] |
| cancelled_at | string | true | [] |
| total_price | float | false | [] |
| discount | float | false | [] |
| customer | structure | false | [] |
| address | structure | false | [] |
| notes | list | false | [] |
+--------------+-----------+----------+----------+
+--------------+-----------+----------+--------------------+
| name | type | nullable | metadata |
+--------------+-----------+----------+--------------------+
| order_id | uuid | false | [] |
| created_at | datetime | false | [] |
| updated_at | datetime | false | [] |
| cancelled_at | string | true | {"from_null":true} |
| total_price | float | false | [] |
| discount | float | false | [] |
| customer | structure | false | [] |
| address | structure | false | [] |
| notes | list | false | [] |
+--------------+-----------+----------+--------------------+
9 rows

OUTPUT,
Expand Down
8 changes: 8 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Schema/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ public function merge(self $definition) : self
throw new RuntimeException(\sprintf('Cannot merge different definitions, %s and %s', $this->ref->name(), $definition->ref->name()));
}

if ($this->metadata->has(Metadata::FROM_NULL) && $definition->metadata()->has(Metadata::FROM_NULL)) {
return new self(
$this->ref,
$this->type()->makeNullable($this->isNullable() || $definition->isNullable()),
$this->metadata->merge($definition->metadata)
);
}

if ($this->metadata->has(Metadata::FROM_NULL)) {
return new self(
$this->ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
string_entry};
use Flow\ETL\Pipeline\SynchronousPipeline;
use Flow\ETL\Row\Schema;
use Flow\ETL\Row\Schema\Metadata;
use Flow\ETL\Tests\FlowIntegrationTestCase;

final class SchemaTest extends FlowIntegrationTestCase
Expand Down Expand Up @@ -84,7 +85,7 @@ public function test_extraction_without_to_schema() : void
schema(
int_schema('id'),
str_schema('name'),
str_schema('active', nullable: true)
str_schema('active', nullable: true, metadata: Metadata::fromArray([Metadata::FROM_NULL => true]))
),
$rows->schema()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ public function test_merging_time_with_datetime() : void
);
}

public function test_merging_two_definitions_created_from_null() : void
{
self::assertTrue(
string_schema('id', true, Metadata::fromArray([Metadata::FROM_NULL => true]))
->merge(string_schema('id', true, Metadata::fromArray([Metadata::FROM_NULL => true])))
->metadata()->has(Metadata::FROM_NULL)
);
}

public function test_merging_two_different_lists() : void
{
self::assertEquals(
Expand Down