Skip to content

Commit

Permalink
Simplify concat functions internals (#1393)
Browse files Browse the repository at this point in the history
Simplify concat functions
  • Loading branch information
stloyd authored Jan 19, 2025
1 parent 9a6df1e commit 39bdb99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
12 changes: 4 additions & 8 deletions src/core/etl/src/Flow/ETL/Function/Concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,17 @@ public function __construct(

public function eval(Row $row) : mixed
{
$values = \array_map(fn (ScalarFunction|string $string) : mixed => \is_string($string) ? $string : Caster::default()->to(type_string(true))->value($string->eval($row)), $this->refs);

/** @var array<string> $concatValues */
$concatValues = [];

foreach ($values as $value) {
foreach ($this->refs as $value) {
$value = \is_string($value) ? $value : Caster::default()->to(type_string(true))->value($value->eval($row));

if (\is_string($value)) {
$concatValues[] = $value;
}
}

if (\count($concatValues) === 0) {
return '';
}

/** @var array<string> $values */
return \implode('', $concatValues);
}
}
12 changes: 4 additions & 8 deletions src/core/etl/src/Flow/ETL/Function/ConcatWithSeparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,17 @@ public function eval(Row $row) : mixed
return '';
}

$values = \array_map(fn (ScalarFunction|string $string) : mixed => \is_string($string) ? $string : Caster::default()->to(type_string(true))->value($string->eval($row)), $this->refs);

/** @var array<string> $concatValues */
$concatValues = [];

foreach ($values as $value) {
foreach ($this->refs as $value) {
$value = \is_string($value) ? $value : Caster::default()->to(type_string(true))->value($value->eval($row));

if (\is_string($value)) {
$concatValues[] = $value;
}
}

if (\count($concatValues) === 0) {
return '';
}

/** @var array<string> $values */
return \implode($separator, $concatValues);
}
}

0 comments on commit 39bdb99

Please sign in to comment.