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 @@ -72,6 +72,7 @@ private function normalizeSchema(ManifestOptions $object, array &$data): void

$this->normalizeDataTypes($schema, $columnMetadata);
$this->normalizeColumnMetadata($schema, $columnMetadata);
$this->deduplicateMetadata($columnMetadata);

if (!empty($columnMetadata)) {
$data['column_metadata'][$schema->getName()] = $columnMetadata;
Expand Down Expand Up @@ -248,4 +249,23 @@ public function supportsDenormalization($data, $type, $format = null): bool
{
return $type === ManifestOptions::class;
}

private function deduplicateMetadata(array &$columnMetadata): void
{
$columnMetadata = array_values(array_reduce(
$columnMetadata,
/**
* @param array<string, array<string, mixed>> $carry
* @param array<string, mixed> $item
* @return array<string, array<string, mixed>>
*/
function (array $carry, array $item): array {
if (isset($item['key']) && !isset($carry[$item['key']])) {
$carry[$item['key']] = $item;
}
return $carry;
},
[],
));
}
}
4 changes: 4 additions & 0 deletions tests/Manifest/ManifestManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ public function provideWriteManifestOptions(): array
'key' => 'yet.another.key',
'value' => 'Some other value',
],
[
'key' => 'yet.another.key', //duplicated key should be removed
'value' => 'Some other value',
],
],
])
->setDestination('my.table')
Expand Down