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 @@ -170,11 +170,11 @@ private function flowToParquet(string $name, Type $type, bool $nullable): Column
return NestedColumn::struct(
$name,
array_map(
function (string $elementName, Type $elementType) {
function (int|string $elementName, Type $elementType) {
$elementOptional = $elementType instanceof OptionalType;
$elementType = $elementType instanceof OptionalType ? $elementType->base() : $elementType;

return $this->flowToParquet($elementName, $elementType, $elementOptional);
return $this->flowToParquet((string) $elementName, $elementType, $elementOptional);
},
array_keys($type->elements()),
$type->elements(),
Expand Down
16 changes: 10 additions & 6 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,12 @@ function entries(Entry ...$entries): Entries
}

/**
* @param ?array<string, mixed> $value
* @param Type<mixed> $type
* @template TShape of array<array-key, mixed>
*
* @param ?TShape $value
* @param StructureType<mixed>|Type<TShape> $type
*
* @return ($value is null ? Entry<null> : Entry<array<string, mixed>>)
* @return ($value is null ? Entry<null> : Entry<TShape>)
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
function struct_entry(string $name, ?array $value, Type $type, ?Metadata $metadata = null): Entry
Expand All @@ -1005,10 +1007,12 @@ function struct_entry(string $name, ?array $value, Type $type, ?Metadata $metada
}

/**
* @param ?array<string, mixed> $value
* @param Type<mixed> $type
* @template TShape of array<array-key, mixed>
*
* @param ?TShape $value
* @param StructureType<mixed>|Type<TShape> $type
*
* @return ($value is null ? Entry<null> : Entry<array<string, mixed>>)
* @return ($value is null ? Entry<null> : Entry<TShape>)
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::ENTRY)]
function structure_entry(string $name, ?array $value, Type $type, ?Metadata $metadata = null): Entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function formatEntry(Definition $definition, array $buffer): array
*
* @return array<int, string>
*/
private function formatStructureElement(string $name, Type $structureType, array $buffer, int $level): array
private function formatStructureElement(int|string $name, Type $structureType, array $buffer, int $level): array
{
$indention = str_repeat(' ', $level);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function test_selecting_values_from_empty_structure(): void
{
$structure = struct_entry(
'struct',
// @mago-ignore analysis:possibly-invalid-argument
[
'id' => null,
'email' => 'email@email.com',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,52 +176,22 @@ public function test_serialization(): void

public function test_structure_element_names_as_numbers(): void
{
static::assertNotEquals(
structure_entry(
'name',
// @mago-ignore analysis:possibly-invalid-argument
['1' => 1, '2' => '2'],
// @mago-ignore analysis:possibly-invalid-argument
type_structure([
'1' => type_integer(),
'2' => type_string(),
]),
),
structure_entry(
'name',
// @mago-ignore analysis:possibly-invalid-argument
['1' => 1, '2' => '2', '3' => '3'],
// @mago-ignore analysis:possibly-invalid-argument
type_structure([
'1' => type_integer(),
'2' => type_string(),
'3' => type_string(),
]),
),
);
static::assertEquals(
structure_entry(
'name',
// @mago-ignore analysis:possibly-invalid-argument
['1' => 1, '2' => 2, '3' => 3],
// @mago-ignore analysis:possibly-invalid-argument
type_structure([
'1' => type_integer(),
'2' => type_integer(),
'3' => type_integer(),
]),
),
structure_entry(
'name',
// @mago-ignore analysis:possibly-invalid-argument
['1' => 1, '2' => 2, '3' => 3],
// @mago-ignore analysis:possibly-invalid-argument
type_structure([
'1' => type_integer(),
'2' => type_integer(),
'3' => type_integer(),
]),
),
);
static::assertNotEquals(structure_entry('name', ['1' => 1, '2' => '2'], type_structure([
'1' => type_integer(),
'2' => type_string(),
])), structure_entry('name', ['1' => 1, '2' => '2', '3' => '3'], type_structure([
'1' => type_integer(),
'2' => type_string(),
'3' => type_string(),
])));
static::assertEquals(structure_entry('name', ['1' => 1, '2' => 2, '3' => 3], type_structure([
'1' => type_integer(),
'2' => type_integer(),
'3' => type_integer(),
])), structure_entry('name', ['1' => 1, '2' => 2, '3' => 3], type_structure([
'1' => type_integer(),
'2' => type_integer(),
'3' => type_integer(),
])));
}
}
8 changes: 5 additions & 3 deletions src/lib/types/src/Flow/Types/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@
use UnitEnum;

/**
* @param array<string, Type<mixed>> $elements
* @param array<string, Type<mixed>> $optional_elements
* @template T
*
* @param array<array-key, Type<T>> $elements
* @param array<array-key, Type<T>> $optional_elements
*
* @return Type<array<string, mixed>>
* @return StructureType<T>
*/
#[DocumentationDSL(module: Module::TYPES, type: DSLType::TYPE)]
function type_structure(array $elements = [], array $optional_elements = [], bool $allow_extra = false): Type
Expand Down
16 changes: 8 additions & 8 deletions src/lib/types/src/Flow/Types/Type/Logical/StructureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@
/**
* @template T
*
* @implements Type<array<string, T>>
* @implements Type<array<array-key, T>>
*/
final readonly class StructureType implements Type
{
/**
* @var array<string, Type<T>>
* @var array<array-key, Type<T>>
*/
private array $elements;

/**
* @var array<string, Type<T>>
* @var array<array-key, Type<T>>
*/
private array $optionalElements;

/**
* @param array<string, Type<T>> $elements
* @param array<string, Type<T>> $optionalElements
* @param array<array-key, Type<T>> $elements
* @param array<array-key, Type<T>> $optionalElements
*
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ public function cast(mixed $value): array
}

/**
* @return array<string, Type<mixed>>
* @return array<array-key, Type<mixed>>
*/
public function elements(): array
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public function isValid(mixed $value): bool
}

/**
* @return array{type: 'structure', elements: array<string, array<string, mixed>>, optional_elements: array<string, array<string, mixed>>, allow_extra: bool}
* @return array{type: 'structure', elements: array<array-key, array<string, mixed>>, optional_elements: array<array-key, array<string, mixed>>, allow_extra: bool}
*/
public function normalize(): array
{
Expand Down Expand Up @@ -237,7 +237,7 @@ public function normalize(): array
}

/**
* @return array<string, Type<mixed>>
* @return array<array-key, Type<mixed>>
*/
public function optionalElements(): array
{
Expand Down
2 changes: 1 addition & 1 deletion web/landing/resources/dsl.json

Large diffs are not rendered by default.

Loading