Skip to content

Commit f479d8f

Browse files
authored
Fixed merging two definitions created from null (#1559)
1 parent badb358 commit f479d8f

4 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/cli/tests/Flow/CLI/Tests/Integration/FileSchemaCommandTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,19 @@ public function test_run_schema_with_table_output_on_json() : void
244244

245245
self::assertSame(
246246
<<<'OUTPUT'
247-
+--------------+-----------+----------+----------+
248-
| name | type | nullable | metadata |
249-
+--------------+-----------+----------+----------+
250-
| order_id | uuid | false | [] |
251-
| created_at | datetime | false | [] |
252-
| updated_at | datetime | false | [] |
253-
| cancelled_at | string | true | [] |
254-
| total_price | float | false | [] |
255-
| discount | float | false | [] |
256-
| customer | structure | false | [] |
257-
| address | structure | false | [] |
258-
| notes | list | false | [] |
259-
+--------------+-----------+----------+----------+
247+
+--------------+-----------+----------+--------------------+
248+
| name | type | nullable | metadata |
249+
+--------------+-----------+----------+--------------------+
250+
| order_id | uuid | false | [] |
251+
| created_at | datetime | false | [] |
252+
| updated_at | datetime | false | [] |
253+
| cancelled_at | string | true | {"from_null":true} |
254+
| total_price | float | false | [] |
255+
| discount | float | false | [] |
256+
| customer | structure | false | [] |
257+
| address | structure | false | [] |
258+
| notes | list | false | [] |
259+
+--------------+-----------+----------+--------------------+
260260
9 rows
261261

262262
OUTPUT,

src/core/etl/src/Flow/ETL/Row/Schema/Definition.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ public function merge(self $definition) : self
218218
throw new RuntimeException(\sprintf('Cannot merge different definitions, %s and %s', $this->ref->name(), $definition->ref->name()));
219219
}
220220

221+
if ($this->metadata->has(Metadata::FROM_NULL) && $definition->metadata()->has(Metadata::FROM_NULL)) {
222+
return new self(
223+
$this->ref,
224+
$this->type()->makeNullable($this->isNullable() || $definition->isNullable()),
225+
$this->metadata->merge($definition->metadata)
226+
);
227+
}
228+
221229
if ($this->metadata->has(Metadata::FROM_NULL)) {
222230
return new self(
223231
$this->ref,

src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/SchemaTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
string_entry};
2424
use Flow\ETL\Pipeline\SynchronousPipeline;
2525
use Flow\ETL\Row\Schema;
26+
use Flow\ETL\Row\Schema\Metadata;
2627
use Flow\ETL\Tests\FlowIntegrationTestCase;
2728

2829
final class SchemaTest extends FlowIntegrationTestCase
@@ -84,7 +85,7 @@ public function test_extraction_without_to_schema() : void
8485
schema(
8586
int_schema('id'),
8687
str_schema('name'),
87-
str_schema('active', nullable: true)
88+
str_schema('active', nullable: true, metadata: Metadata::fromArray([Metadata::FROM_NULL => true]))
8889
),
8990
$rows->schema()
9091
);

src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public function test_merging_time_with_datetime() : void
191191
);
192192
}
193193

194+
public function test_merging_two_definitions_created_from_null() : void
195+
{
196+
self::assertTrue(
197+
string_schema('id', true, Metadata::fromArray([Metadata::FROM_NULL => true]))
198+
->merge(string_schema('id', true, Metadata::fromArray([Metadata::FROM_NULL => true])))
199+
->metadata()->has(Metadata::FROM_NULL)
200+
);
201+
}
202+
194203
public function test_merging_two_different_lists() : void
195204
{
196205
self::assertEquals(

0 commit comments

Comments
 (0)