Skip to content

Commit 5552d97

Browse files
authored
Fix entry factory loosing schema metadata/type nullability (#1395)
* Fix entry factory loosing schema metadata/type nullability * Restored removed logic * Updated DSL definitions
1 parent 18630cd commit 5552d97

File tree

19 files changed

+244
-135
lines changed

19 files changed

+244
-135
lines changed

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -343,82 +343,82 @@ function to_branch(ScalarFunction $condition, Loader $loader) : Loader
343343
}
344344

345345
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
346-
function bool_entry(string $name, ?bool $value) : Entry\BooleanEntry
346+
function bool_entry(string $name, ?bool $value, ?BooleanType $type = null, ?Schema\Metadata $metadata = null) : Entry\BooleanEntry
347347
{
348-
return new Entry\BooleanEntry($name, $value);
348+
return new Entry\BooleanEntry($name, $value, $type);
349349
}
350350

351351
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
352-
function boolean_entry(string $name, ?bool $value) : Entry\BooleanEntry
352+
function boolean_entry(string $name, ?bool $value, ?BooleanType $type = null, ?Schema\Metadata $metadata = null) : Entry\BooleanEntry
353353
{
354-
return bool_entry($name, $value);
354+
return bool_entry($name, $value, $type, $metadata);
355355
}
356356

357357
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
358-
function datetime_entry(string $name, \DateTimeInterface|string|null $value) : Entry\DateTimeEntry
358+
function datetime_entry(string $name, \DateTimeInterface|string|null $value, ?DateTimeType $type = null, ?Schema\Metadata $metadata = null) : Entry\DateTimeEntry
359359
{
360-
return new Entry\DateTimeEntry($name, $value);
360+
return new Entry\DateTimeEntry($name, $value, $type, $metadata);
361361
}
362362

363363
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
364-
function time_entry(string $name, \DateInterval|string|null $value) : Entry\TimeEntry
364+
function time_entry(string $name, \DateInterval|string|null $value, ?TimeType $type = null, ?Schema\Metadata $metadata = null) : Entry\TimeEntry
365365
{
366-
return new Entry\TimeEntry($name, $value);
366+
return new Entry\TimeEntry($name, $value, $type, $metadata);
367367
}
368368

369369
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
370-
function date_entry(string $name, \DateTimeInterface|string|null $value) : Entry\DateEntry
370+
function date_entry(string $name, \DateTimeInterface|string|null $value, ?DateType $type = null, ?Schema\Metadata $metadata = null) : Entry\DateEntry
371371
{
372-
return new Entry\DateEntry($name, $value);
372+
return new Entry\DateEntry($name, $value, $type, $metadata);
373373
}
374374

375375
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
376-
function int_entry(string $name, ?int $value) : Entry\IntegerEntry
376+
function int_entry(string $name, ?int $value, ?IntegerType $type = null, ?Schema\Metadata $metadata = null) : Entry\IntegerEntry
377377
{
378-
return new Entry\IntegerEntry($name, $value);
378+
return new Entry\IntegerEntry($name, $value, $type, $metadata);
379379
}
380380

381381
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
382-
function integer_entry(string $name, ?int $value) : Entry\IntegerEntry
382+
function integer_entry(string $name, ?int $value, ?IntegerType $type = null, ?Schema\Metadata $metadata = null) : Entry\IntegerEntry
383383
{
384-
return int_entry($name, $value);
384+
return int_entry($name, $value, $type, $metadata);
385385
}
386386

387387
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
388-
function enum_entry(string $name, ?\UnitEnum $enum) : Entry\EnumEntry
388+
function enum_entry(string $name, ?\UnitEnum $enum, ?EnumType $type = null, ?Schema\Metadata $metadata = null) : Entry\EnumEntry
389389
{
390-
return new Entry\EnumEntry($name, $enum);
390+
return new Entry\EnumEntry($name, $enum, $type, $metadata);
391391
}
392392

393393
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
394-
function float_entry(string $name, ?float $value, int $precision = 6) : Entry\FloatEntry
394+
function float_entry(string $name, ?float $value, int $precision = 6, ?FloatType $type = null, ?Schema\Metadata $metadata = null) : Entry\FloatEntry
395395
{
396-
return new Entry\FloatEntry($name, $value, $precision);
396+
return new Entry\FloatEntry($name, $value, $precision, $type, $metadata);
397397
}
398398

399399
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
400-
function json_entry(string $name, array|string|null $data) : Entry\JsonEntry
400+
function json_entry(string $name, array|string|null $data, ?JsonType $type = null, ?Schema\Metadata $metadata = null) : Entry\JsonEntry
401401
{
402-
return new Entry\JsonEntry($name, $data);
402+
return new Entry\JsonEntry($name, $data, $type, $metadata);
403403
}
404404

405405
/**
406406
* @throws InvalidArgumentException
407407
*/
408408
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
409-
function json_object_entry(string $name, array|string|null $data) : Entry\JsonEntry
409+
function json_object_entry(string $name, array|string|null $data, ?JsonType $type = null, ?Schema\Metadata $metadata = null) : Entry\JsonEntry
410410
{
411411
if (\is_string($data)) {
412-
return new Entry\JsonEntry($name, $data);
412+
return new Entry\JsonEntry($name, $data, $type, $metadata);
413413
}
414414

415-
return Entry\JsonEntry::object($name, $data);
415+
return Entry\JsonEntry::object($name, $data, $type, $metadata);
416416
}
417417

418418
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
419-
function str_entry(string $name, ?string $value) : Entry\StringEntry
419+
function str_entry(string $name, ?string $value, ?StringType $type = null, ?Schema\Metadata $metadata = null) : Entry\StringEntry
420420
{
421-
return new Entry\StringEntry($name, $value);
421+
return new Entry\StringEntry($name, $value, $type, $metadata);
422422
}
423423

424424
/**
@@ -432,33 +432,33 @@ function str_entry(string $name, ?string $value) : Entry\StringEntry
432432
* By design flow assumes when guessing column type that null would be a string (the most flexible type).
433433
*/
434434
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
435-
function null_entry(string $name) : Entry\StringEntry
435+
function null_entry(string $name, ?Schema\Metadata $metadata = null) : Entry\StringEntry
436436
{
437-
return Entry\StringEntry::fromNull($name);
437+
return Entry\StringEntry::fromNull($name, $metadata);
438438
}
439439

440440
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
441-
function string_entry(string $name, ?string $value) : Entry\StringEntry
441+
function string_entry(string $name, ?string $value, ?StringType $type = null, ?Schema\Metadata $metadata = null) : Entry\StringEntry
442442
{
443-
return str_entry($name, $value);
443+
return str_entry($name, $value, $type, $metadata);
444444
}
445445

446446
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
447-
function uuid_entry(string $name, \Flow\ETL\PHP\Value\Uuid|string|null $value) : Entry\UuidEntry
447+
function uuid_entry(string $name, \Flow\ETL\PHP\Value\Uuid|string|null $value, ?UuidType $type = null, ?Schema\Metadata $metadata = null) : Entry\UuidEntry
448448
{
449-
return new Entry\UuidEntry($name, $value);
449+
return new Entry\UuidEntry($name, $value, $type, $metadata);
450450
}
451451

452452
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
453-
function xml_entry(string $name, \DOMDocument|string|null $value) : Entry\XMLEntry
453+
function xml_entry(string $name, \DOMDocument|string|null $value, ?XMLType $type = null, ?Schema\Metadata $metadata = null) : Entry\XMLEntry
454454
{
455-
return new Entry\XMLEntry($name, $value);
455+
return new Entry\XMLEntry($name, $value, $type, $metadata);
456456
}
457457

458458
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
459-
function xml_element_entry(string $name, \DOMElement|string|null $value) : Entry\XMLElementEntry
459+
function xml_element_entry(string $name, \DOMElement|string|null $value, ?XMLElementType $type = null, ?Schema\Metadata $metadata = null) : Entry\XMLElementEntry
460460
{
461-
return new Entry\XMLElementEntry($name, $value);
461+
return new Entry\XMLElementEntry($name, $value, $type, $metadata);
462462
}
463463

464464
/**
@@ -471,15 +471,15 @@ function entries(Entry ...$entries) : Row\Entries
471471
}
472472

473473
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
474-
function struct_entry(string $name, ?array $value, StructureType $type) : Entry\StructureEntry
474+
function struct_entry(string $name, ?array $value, StructureType $type, ?Schema\Metadata $metadata = null) : Entry\StructureEntry
475475
{
476-
return new Entry\StructureEntry($name, $value, $type);
476+
return new Entry\StructureEntry($name, $value, $type, $metadata);
477477
}
478478

479479
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
480-
function structure_entry(string $name, ?array $value, StructureType $type) : Entry\StructureEntry
480+
function structure_entry(string $name, ?array $value, StructureType $type, ?Schema\Metadata $metadata = null) : Entry\StructureEntry
481481
{
482-
return new Entry\StructureEntry($name, $value, $type);
482+
return new Entry\StructureEntry($name, $value, $type, $metadata);
483483
}
484484

485485
/**
@@ -519,9 +519,9 @@ function type_map(StringType|IntegerType $key_type, Type $value_type, bool $null
519519
}
520520

521521
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
522-
function map_entry(string $name, ?array $value, MapType $mapType) : Entry\MapEntry
522+
function map_entry(string $name, ?array $value, MapType $mapType, ?Schema\Metadata $metadata = null) : Entry\MapEntry
523523
{
524-
return new Entry\MapEntry($name, $value, $mapType);
524+
return new Entry\MapEntry($name, $value, $mapType, $metadata);
525525
}
526526

527527
#[DocumentationDSL(module: Module::CORE, type: DSLType::TYPE)]

src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Flow\ETL\PHP\Type\Native\BooleanType;
1010
use Flow\ETL\PHP\Type\Type;
1111
use Flow\ETL\Row\Schema\Definition;
12-
use Flow\ETL\Row\{Entry, Reference};
12+
use Flow\ETL\Row\{Entry, Reference, Schema\Metadata};
1313

1414
/**
1515
* @implements Entry<?bool, ?bool>
@@ -18,18 +18,21 @@ final class BooleanEntry implements Entry
1818
{
1919
use EntryRef;
2020

21+
private Metadata $metadata;
22+
2123
private readonly BooleanType $type;
2224

2325
/**
2426
* @throws InvalidArgumentException
2527
*/
26-
public function __construct(private readonly string $name, private readonly ?bool $value)
28+
public function __construct(private readonly string $name, private readonly ?bool $value, ?BooleanType $type = null, ?Metadata $metadata = null)
2729
{
2830
if ('' === $name) {
2931
throw InvalidArgumentException::because('Entry name cannot be empty');
3032
}
3133

32-
$this->type = type_boolean($this->value === null);
34+
$this->metadata = $metadata ?: Metadata::empty();
35+
$this->type = $type ?: type_boolean($this->value === null);
3336
}
3437

3538
public function __toString() : string
@@ -39,7 +42,7 @@ public function __toString() : string
3942

4043
public function definition() : Definition
4144
{
42-
return Definition::boolean($this->name, $this->type->nullable());
45+
return Definition::boolean($this->name, $this->type->nullable(), $this->metadata);
4346
}
4447

4548
public function is(string|Reference $name) : bool

src/core/etl/src/Flow/ETL/Row/Entry/DateEntry.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Flow\ETL\PHP\Type\Logical\DateType;
1010
use Flow\ETL\PHP\Type\Type;
1111
use Flow\ETL\Row\Schema\Definition;
12-
use Flow\ETL\Row\{Entry, Reference};
12+
use Flow\ETL\Row\{Entry, Reference, Schema\Metadata};
1313

1414
/**
1515
* @implements Entry<?\DateTimeInterface, ?\DateTimeInterface>
@@ -18,14 +18,16 @@ final class DateEntry implements Entry
1818
{
1919
use EntryRef;
2020

21+
private Metadata $metadata;
22+
2123
private readonly DateType $type;
2224

2325
private readonly ?\DateTimeInterface $value;
2426

2527
/**
2628
* @throws InvalidArgumentException
2729
*/
28-
public function __construct(private readonly string $name, \DateTimeInterface|string|null $value)
30+
public function __construct(private readonly string $name, \DateTimeInterface|string|null $value, ?DateType $type = null, ?Metadata $metadata = null)
2931
{
3032
if ($name === '') {
3133
throw InvalidArgumentException::because('Entry name cannot be empty');
@@ -45,7 +47,8 @@ public function __construct(private readonly string $name, \DateTimeInterface|st
4547
$this->value = $value;
4648
}
4749

48-
$this->type = type_date($this->value === null);
50+
$this->metadata = $metadata ?: Metadata::empty();
51+
$this->type = $type ?: type_date($this->value === null);
4952
}
5053

5154
public function __toString() : string
@@ -55,7 +58,7 @@ public function __toString() : string
5558

5659
public function definition() : Definition
5760
{
58-
return Definition::dateTime($this->name, $this->type->nullable());
61+
return Definition::dateTime($this->name, $this->type->nullable(), $this->metadata);
5962
}
6063

6164
public function is(string|Reference $name) : bool

src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Flow\ETL\PHP\Type\Logical\DateTimeType;
1010
use Flow\ETL\PHP\Type\Type;
1111
use Flow\ETL\Row\Schema\Definition;
12-
use Flow\ETL\Row\{Entry, Reference};
12+
use Flow\ETL\Row\{Entry, Reference, Schema\Metadata};
1313

1414
/**
1515
* @implements Entry<?\DateTimeInterface, ?\DateTimeInterface>
@@ -18,15 +18,21 @@ final class DateTimeEntry implements Entry
1818
{
1919
use EntryRef;
2020

21+
private Metadata $metadata;
22+
2123
private readonly DateTimeType $type;
2224

2325
private readonly ?\DateTimeInterface $value;
2426

2527
/**
2628
* @throws InvalidArgumentException
2729
*/
28-
public function __construct(private readonly string $name, \DateTimeInterface|string|null $value)
29-
{
30+
public function __construct(
31+
private readonly string $name,
32+
\DateTimeInterface|string|null $value,
33+
?DateTimeType $type = null,
34+
?Metadata $metadata = null,
35+
) {
3036
if ($name === '') {
3137
throw InvalidArgumentException::because('Entry name cannot be empty');
3238
}
@@ -43,7 +49,8 @@ public function __construct(private readonly string $name, \DateTimeInterface|st
4349
$this->value = $value;
4450
}
4551

46-
$this->type = type_datetime($this->value === null);
52+
$this->metadata = $metadata ?: Metadata::empty();
53+
$this->type = $type ?: type_datetime($this->value === null);
4754
}
4855

4956
public function __toString() : string
@@ -53,7 +60,7 @@ public function __toString() : string
5360

5461
public function definition() : Definition
5562
{
56-
return Definition::dateTime($this->name, $this->type->nullable());
63+
return Definition::dateTime($this->name, $this->type->nullable(), $this->metadata);
5764
}
5865

5966
public function is(string|Reference $name) : bool

src/core/etl/src/Flow/ETL/Row/Entry/EnumEntry.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Flow\ETL\PHP\Type\Native\EnumType;
88
use Flow\ETL\PHP\Type\Type;
99
use Flow\ETL\Row\Schema\Definition;
10-
use Flow\ETL\Row\{Entry, Reference};
10+
use Flow\ETL\Row\{Entry, Reference, Schema\Metadata};
1111

1212
/**
1313
* @implements Entry<?\UnitEnum, ?\UnitEnum>
@@ -16,13 +16,18 @@ final class EnumEntry implements Entry
1616
{
1717
use EntryRef;
1818

19+
private Metadata $metadata;
20+
1921
private readonly EnumType $type;
2022

2123
public function __construct(
2224
private readonly string $name,
2325
private readonly ?\UnitEnum $value,
26+
?EnumType $type = null,
27+
?Metadata $metadata = null,
2428
) {
25-
$this->type = EnumType::of($value === null ? \UnitEnum::class : $value::class, $value === null);
29+
$this->metadata = $metadata ?: Metadata::empty();
30+
$this->type = $type ?: EnumType::of($value === null ? \UnitEnum::class : $value::class, $value === null);
2631
}
2732

2833
public function __toString() : string
@@ -39,7 +44,8 @@ public function definition() : Definition
3944
return Definition::enum(
4045
$this->name,
4146
$this->type->class,
42-
$this->type->nullable()
47+
$this->type->nullable(),
48+
$this->metadata
4349
);
4450
}
4551

0 commit comments

Comments
 (0)