Skip to content

Commit 10a0c52

Browse files
authored
Improve Expression::dropDuplicate*Entries methods (#1406)
1 parent 64d15f8 commit 10a0c52

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

src/core/etl/src/Flow/ETL/Join/Expression.php

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,58 +52,44 @@ public static function on(array|Comparison $comparison, string $joinPrefix = '')
5252

5353
public function dropDuplicateLeftEntries(Row $left) : Row
5454
{
55-
if ($this->joinPrefix === '') {
56-
$leftEntries = [];
57-
$rightEntries = [];
55+
if ($this->joinPrefix !== '') {
56+
return $left;
57+
}
5858

59-
foreach ($this->left() as $leftReference) {
60-
$leftEntries[] = $leftReference->name();
61-
}
59+
$dropLeft = [];
6260

61+
foreach ($this->left() as $leftReference) {
6362
foreach ($this->right() as $rightReference) {
64-
$rightEntries[] = $rightReference->name();
65-
}
63+
if ($leftReference->name() === $rightReference->name()) {
64+
$dropLeft[] = $leftReference->name();
6665

67-
$dropLeft = [];
68-
69-
foreach ($leftEntries as $leftEntry) {
70-
if (\in_array($leftEntry, $rightEntries, true)) {
71-
$dropLeft[] = $leftEntry;
66+
continue 2;
7267
}
7368
}
74-
75-
return $left->remove(...$dropLeft);
7669
}
7770

78-
return $left;
71+
return $left->remove(...$dropLeft);
7972
}
8073

8174
public function dropDuplicateRightEntries(Row $right) : Row
8275
{
83-
if ($this->joinPrefix === '') {
84-
$leftEntries = [];
85-
$rightEntries = [];
86-
87-
foreach ($this->left() as $leftReference) {
88-
$leftEntries[] = $leftReference->name();
89-
}
76+
if ($this->joinPrefix !== '') {
77+
return $right;
78+
}
9079

91-
foreach ($this->right() as $rightReference) {
92-
$rightEntries[] = $rightReference->name();
93-
}
80+
$dropRight = [];
9481

95-
$dropRight = [];
82+
foreach ($this->right() as $rightReference) {
83+
foreach ($this->left() as $leftReference) {
84+
if ($rightReference->name() === $leftReference->name()) {
85+
$dropRight[] = $rightReference->name();
9686

97-
foreach ($rightEntries as $rightEntry) {
98-
if (\in_array($rightEntry, $leftEntries, true)) {
99-
$dropRight[] = $rightEntry;
87+
continue 2;
10088
}
10189
}
102-
103-
return $right->remove(...$dropRight);
10490
}
10591

106-
return $right;
92+
return $right->remove(...$dropRight);
10793
}
10894

10995
/**

0 commit comments

Comments
 (0)