Skip to content

Commit ecd1bda

Browse files
authored
Rename performance (#2250)
* fix: entries droping metadata during rename * refactor: optimize rename performance - removed deprecated code * fix: fragile website tests
1 parent 80722cb commit ecd1bda

89 files changed

Lines changed: 831 additions & 16428 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
Sprintf,
145145
StringAggregate,
146146
StructureFunctions,
147-
StyleConverter\StringStyles as OldStringStyles,
148147
Sum,
149148
ToDate,
150149
ToDateTime,
@@ -210,7 +209,7 @@
210209
use Flow\ETL\Transformation\AddRowIndex\StartFrom;
211210
use Flow\ETL\Transformation\{AddRowIndex, BatchSize, Drop, Limit, MaskColumns, Select};
212211
use Flow\ETL\Transformer\OrderEntries\{CombinedComparator, Comparator, NameComparator, Order, TypeComparator, TypePriorities};
213-
use Flow\ETL\Transformer\Rename\{RenameCaseEntryStrategy, RenameReplaceEntryStrategy};
212+
use Flow\ETL\Transformer\Rename\{RenameCaseEntryStrategy, RenameMapEntryStrategy, RenameReplaceEntryStrategy};
214213
use Flow\Filesystem\{Filesystem, Local\NativeLocalFilesystem, Partition, Partitions, Path};
215214
use Flow\Filesystem\Stream\Mode;
216215
use Flow\Filesystem\Telemetry\FilesystemTelemetryOptions;
@@ -497,7 +496,7 @@ function to_branch(ScalarFunction $condition, Loader $loader) : BranchingLoader
497496
}
498497

499498
#[DocumentationDSL(module: Module::CORE, type: DSLType::TRANSFORMER)]
500-
function rename_style(OldStringStyles|StringStyles $style) : RenameCaseEntryStrategy
499+
function rename_style(StringStyles $style) : RenameCaseEntryStrategy
501500
{
502501
return new RenameCaseEntryStrategy($style);
503502
}
@@ -512,6 +511,15 @@ function rename_replace(string|array $search, string|array $replace) : RenameRep
512511
return new RenameReplaceEntryStrategy($search, $replace);
513512
}
514513

514+
/**
515+
* @param array<string, string> $renames Map of old_name => new_name
516+
*/
517+
#[DocumentationDSL(module: Module::CORE, type: DSLType::TRANSFORMER)]
518+
function rename_map(array $renames) : RenameMapEntryStrategy
519+
{
520+
return new RenameMapEntryStrategy($renames);
521+
}
522+
515523
/**
516524
* @return Entry<?bool>
517525
*/
@@ -1297,12 +1305,8 @@ function array_key_rename(ScalarFunction $ref, ScalarFunction|string $path, Scal
12971305
}
12981306

12991307
#[DocumentationDSL(module: Module::CORE, type: DSLType::SCALAR_FUNCTION)]
1300-
function array_keys_style_convert(ScalarFunction $ref, OldStringStyles|StringStyles|string $style = StringStyles::SNAKE) : ArrayKeysStyleConvert
1308+
function array_keys_style_convert(ScalarFunction $ref, StringStyles|string $style = StringStyles::SNAKE) : ArrayKeysStyleConvert
13011309
{
1302-
if ($style instanceof OldStringStyles) {
1303-
$style = StringStyles::fromString($style->value);
1304-
}
1305-
13061310
return new ArrayKeysStyleConvert($ref, $style instanceof StringStyles ? $style : StringStyles::fromString($style));
13071311
}
13081312

src/core/etl/src/Flow/ETL/DataFrame.php

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Flow\ETL\Function\{AggregatingFunction,
1616
ExecutionMode,
1717
ScalarFunction,
18-
StyleConverter\StringStyles as OldStringStyles,
1918
WindowFunction};
2019
use Flow\ETL\Join\{Expression, Join};
2120
use Flow\ETL\Loader\SchemaValidationLoader;
@@ -35,7 +34,6 @@
3534
use Flow\ETL\Row\{EntryReference, Formatter\ASCIISchemaFormatter, Reference, References};
3635
use Flow\ETL\Schema\{Definition, SchemaFormatter};
3736
use Flow\ETL\Schema\Validator\StrictValidator;
38-
use Flow\ETL\String\StringStyles;
3937
use Flow\ETL\Transformer\{AutoCastTransformer,
4038
CallbackRowTransformer,
4139
CrossJoinRowsTransformer,
@@ -50,9 +48,7 @@
5048
OrderEntries\TypeComparator,
5149
RenameEachEntryTransformer,
5250
RenameEntryTransformer,
53-
Rename\RenameCaseEntryStrategy,
5451
Rename\RenameEntryStrategy,
55-
Rename\RenameReplaceEntryStrategy,
5652
ScalarFunctionFilterTransformer,
5753
ScalarFunctionTransformer,
5854
SelectEntriesTransformer,
@@ -724,85 +720,6 @@ public function rename(string $from, string $to) : self
724720
return $this;
725721
}
726722

727-
/**
728-
* @lazy
729-
* Iterate over all entry names and replace the given search string with replace string.
730-
*
731-
* @deprecated use DataFrame::renameEach() with a RenameReplaceStrategy
732-
*/
733-
public function renameAll(string $search, string $replace) : self
734-
{
735-
$this->renameEach(new RenameReplaceEntryStrategy($search, $replace));
736-
737-
return $this;
738-
}
739-
740-
/**
741-
* @lazy
742-
*
743-
* @deprecated use DataFrame::renameEach() with a selected StringStyles
744-
*/
745-
public function renameAllLowerCase() : self
746-
{
747-
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::LOWER));
748-
749-
return $this;
750-
}
751-
752-
/**
753-
* @lazy
754-
* Rename all entries to a given style.
755-
* Please look into \Flow\ETL\Function\StyleConverter\StringStyles class for all available styles.
756-
*
757-
* @deprecated use DataFrame::renameEach() with a selected Style
758-
*/
759-
public function renameAllStyle(OldStringStyles|StringStyles|string $style) : self
760-
{
761-
if ($style instanceof OldStringStyles) {
762-
$style = StringStyles::fromString($style->value);
763-
}
764-
765-
$this->renameEach(new RenameCaseEntryStrategy(\is_string($style) ? StringStyles::fromString($style) : $style));
766-
767-
return $this;
768-
}
769-
770-
/**
771-
* @lazy
772-
*
773-
* @deprecated use DataFrame::renameEach() with a selected Style
774-
*/
775-
public function renameAllUpperCase() : self
776-
{
777-
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::UPPER));
778-
779-
return $this;
780-
}
781-
782-
/**
783-
* @lazy
784-
*
785-
* @deprecated use DataFrame::renameEach() with a selected Style
786-
*/
787-
public function renameAllUpperCaseFirst() : self
788-
{
789-
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::UCFIRST));
790-
791-
return $this;
792-
}
793-
794-
/**
795-
* @lazy
796-
*
797-
* @deprecated use DataFrame::renameEach() with a selected Style
798-
*/
799-
public function renameAllUpperCaseWord() : self
800-
{
801-
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::UCWORDS));
802-
803-
return $this;
804-
}
805-
806723
public function renameEach(RenameEntryStrategy ...$strategies) : self
807724
{
808725
$this->pipeline->add(new RenameEachEntryTransformer(...$strategies));

src/core/etl/src/Flow/ETL/Function/ArrayKeysStyleConvert.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,15 @@
66

77
use Flow\ETL\Exception\InvalidArgumentException;
88
use Flow\ETL\{FlowContext, Row};
9-
use Flow\ETL\Function\StyleConverter\{ArrayKeyConverter, StringStyles as OldStringStyles};
9+
use Flow\ETL\Function\StyleConverter\ArrayKeyConverter;
1010
use Flow\ETL\String\StringStyles;
1111

1212
final class ArrayKeysStyleConvert extends ScalarFunctionChain
1313
{
14-
private StringStyles $style;
15-
1614
public function __construct(
1715
private readonly ScalarFunction $ref,
18-
OldStringStyles|StringStyles $style,
16+
private readonly StringStyles $style,
1917
) {
20-
if ($style instanceof OldStringStyles) {
21-
$this->style = StringStyles::fromString($style->value);
22-
} else {
23-
$this->style = $style;
24-
}
2518
}
2619

2720
public function eval(Row $row, FlowContext $context) : mixed

src/core/etl/src/Flow/ETL/Function/ScalarFunctionChain.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Flow\ETL\Function\ArrayExpand\ArrayExpand;
1212
use Flow\ETL\Function\ArraySort\Sort;
1313
use Flow\ETL\Function\Between\Boundary;
14-
use Flow\ETL\Function\StyleConverter\StringStyles as OldStringStyles;
1514
use Flow\ETL\Hash\{Algorithm, NativePHPHash};
1615
use Flow\ETL\String\StringStyles;
1716
use Flow\Types\Type;
@@ -676,7 +675,7 @@ public function stringNormalize(ScalarFunction|int $form = \Normalizer::NFC) : S
676675
* Covert string to a style from enum list, passed in parameter.
677676
* Can be string "upper" or StringStyles::UPPER for Upper (example).
678677
*/
679-
public function stringStyle(ScalarFunction|string|OldStringStyles|StringStyles $style) : StringStyle
678+
public function stringStyle(ScalarFunction|string|StringStyles $style) : StringStyle
680679
{
681680
return new StringStyle($this, $style);
682681
}

src/core/etl/src/Flow/ETL/Function/StringStyle.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
use function Flow\Types\DSL\{type_enum, type_string};
88
use Flow\ETL\Exception\InvalidArgumentException;
99
use Flow\ETL\{FlowContext, Row};
10-
use Flow\ETL\Function\StyleConverter\StringStyles as OldStringStyles;
1110
use Flow\ETL\String\StringStyles;
1211

1312
final class StringStyle extends ScalarFunctionChain
1413
{
1514
public function __construct(
1615
private readonly ScalarFunction|string $string,
17-
private readonly ScalarFunction|string|OldStringStyles|StringStyles $style,
16+
private readonly ScalarFunction|string|StringStyles $style,
1817
) {
1918
}
2019

2120
public function eval(Row $row, FlowContext $context) : ?string
2221
{
2322
$string = (new Parameter($this->string))->asString($row, $context);
24-
$style = (new Parameter($this->style))->as($row, $context, type_string(), type_enum(StringStyles::class), type_enum(OldStringStyles::class));
23+
$style = (new Parameter($this->style))->as($row, $context, type_string(), type_enum(StringStyles::class));
2524

2625
if ($string === null) {
2726
return $context->functions()->invalidResult(new InvalidArgumentException('StringStyle function requires non-null value'));
@@ -33,8 +32,6 @@ public function eval(Row $row, FlowContext $context) : ?string
3332

3433
if (is_string($style)) {
3534
$style = StringStyles::fromString($style);
36-
} elseif ($style instanceof OldStringStyles) {
37-
$style = StringStyles::fromString($style->value);
3835
}
3936

4037
if (!$style instanceof StringStyles) {

src/core/etl/src/Flow/ETL/Function/StyleConverter/StringStyles.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/core/etl/src/Flow/ETL/Pipeline/Optimizer/LimitOptimization.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
use Flow\ETL\Processor\{BatchingProcessor, CollectingProcessor, VoidProcessor};
1111
use Flow\ETL\Transformer\{CallbackRowTransformer,
1212
DropEntriesTransformer,
13-
EntryNameStyleConverterTransformer,
1413
LimitTransformer,
15-
RenameAllCaseTransformer,
1614
RenameEachEntryTransformer,
1715
RenameEntryTransformer,
18-
RenameStrReplaceAllEntriesTransformer,
1916
ScalarFunctionTransformer,
2017
SelectEntriesTransformer};
2118

@@ -38,13 +35,10 @@ final class LimitOptimization implements Optimization
3835
private array $nonExpandingTransformers = [
3936
CallbackRowTransformer::class,
4037
ScalarFunctionTransformer::class,
41-
EntryNameStyleConverterTransformer::class,
4238
SelectEntriesTransformer::class,
4339
DropEntriesTransformer::class,
44-
RenameAllCaseTransformer::class,
4540
RenameEachEntryTransformer::class,
4641
RenameEntryTransformer::class,
47-
RenameStrReplaceAllEntriesTransformer::class,
4842
LimitTransformer::class,
4943
];
5044

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ public function rename(string $currentName, string $newName) : self
134134
return new self($this->entries->rename($currentName, $newName));
135135
}
136136

137+
/**
138+
* Rename multiple entries in a single pass.
139+
*
140+
* @param array<string, string> $renames Map of old_name => new_name
141+
*/
142+
public function renameMany(array $renames) : self
143+
{
144+
if ($renames === []) {
145+
return $this;
146+
}
147+
148+
return new self($this->entries->renameMany($renames));
149+
}
150+
137151
/**
138152
* @return Schema
139153
*/

src/core/etl/src/Flow/ETL/Row/Entries.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,36 @@ public function rename(string|Reference $current, string|Reference $new) : self
330330
return self::recreate($entries);
331331
}
332332

333+
/**
334+
* Rename multiple entries in a single pass.
335+
*
336+
* @param array<string, string> $renames Map of old_name => new_name
337+
*/
338+
public function renameMany(array $renames) : self
339+
{
340+
if ($renames === []) {
341+
return $this;
342+
}
343+
344+
$entries = $this->entries;
345+
346+
foreach ($renames as $from => $to) {
347+
if ($from === $to) {
348+
continue;
349+
}
350+
351+
if (!\array_key_exists($from, $entries)) {
352+
throw InvalidLogicException::because(\sprintf('Entry "%s" does not exist', $from));
353+
}
354+
355+
$entry = $entries[$from];
356+
unset($entries[$from]);
357+
$entries[$to] = $entry->rename($to);
358+
}
359+
360+
return self::recreate($entries);
361+
}
362+
333363
/**
334364
* @param Entry<mixed> ...$entries
335365
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function name() : string
7676
*/
7777
public function rename(string $name) : static
7878
{
79-
return new self($name, $this->value);
79+
return new self($name, $this->value, $this->definition->metadata());
8080
}
8181

8282
public function toString() : string

0 commit comments

Comments
 (0)