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
20 changes: 12 additions & 8 deletions src/core/etl/src/Flow/ETL/DSL/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
Sprintf,
StringAggregate,
StructureFunctions,
StyleConverter\StringStyles as OldStringStyles,
Sum,
ToDate,
ToDateTime,
Expand Down Expand Up @@ -210,7 +209,7 @@
use Flow\ETL\Transformation\AddRowIndex\StartFrom;
use Flow\ETL\Transformation\{AddRowIndex, BatchSize, Drop, Limit, MaskColumns, Select};
use Flow\ETL\Transformer\OrderEntries\{CombinedComparator, Comparator, NameComparator, Order, TypeComparator, TypePriorities};
use Flow\ETL\Transformer\Rename\{RenameCaseEntryStrategy, RenameReplaceEntryStrategy};
use Flow\ETL\Transformer\Rename\{RenameCaseEntryStrategy, RenameMapEntryStrategy, RenameReplaceEntryStrategy};
use Flow\Filesystem\{Filesystem, Local\NativeLocalFilesystem, Partition, Partitions, Path};
use Flow\Filesystem\Stream\Mode;
use Flow\Filesystem\Telemetry\FilesystemTelemetryOptions;
Expand Down Expand Up @@ -497,7 +496,7 @@ function to_branch(ScalarFunction $condition, Loader $loader) : BranchingLoader
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::TRANSFORMER)]
function rename_style(OldStringStyles|StringStyles $style) : RenameCaseEntryStrategy
function rename_style(StringStyles $style) : RenameCaseEntryStrategy
{
return new RenameCaseEntryStrategy($style);
}
Expand All @@ -512,6 +511,15 @@ function rename_replace(string|array $search, string|array $replace) : RenameRep
return new RenameReplaceEntryStrategy($search, $replace);
}

/**
* @param array<string, string> $renames Map of old_name => new_name
*/
#[DocumentationDSL(module: Module::CORE, type: DSLType::TRANSFORMER)]
function rename_map(array $renames) : RenameMapEntryStrategy
{
return new RenameMapEntryStrategy($renames);
}

/**
* @return Entry<?bool>
*/
Expand Down Expand Up @@ -1297,12 +1305,8 @@ function array_key_rename(ScalarFunction $ref, ScalarFunction|string $path, Scal
}

#[DocumentationDSL(module: Module::CORE, type: DSLType::SCALAR_FUNCTION)]
function array_keys_style_convert(ScalarFunction $ref, OldStringStyles|StringStyles|string $style = StringStyles::SNAKE) : ArrayKeysStyleConvert
function array_keys_style_convert(ScalarFunction $ref, StringStyles|string $style = StringStyles::SNAKE) : ArrayKeysStyleConvert
{
if ($style instanceof OldStringStyles) {
$style = StringStyles::fromString($style->value);
}

return new ArrayKeysStyleConvert($ref, $style instanceof StringStyles ? $style : StringStyles::fromString($style));
}

Expand Down
83 changes: 0 additions & 83 deletions src/core/etl/src/Flow/ETL/DataFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Flow\ETL\Function\{AggregatingFunction,
ExecutionMode,
ScalarFunction,
StyleConverter\StringStyles as OldStringStyles,
WindowFunction};
use Flow\ETL\Join\{Expression, Join};
use Flow\ETL\Loader\SchemaValidationLoader;
Expand All @@ -35,7 +34,6 @@
use Flow\ETL\Row\{EntryReference, Formatter\ASCIISchemaFormatter, Reference, References};
use Flow\ETL\Schema\{Definition, SchemaFormatter};
use Flow\ETL\Schema\Validator\StrictValidator;
use Flow\ETL\String\StringStyles;
use Flow\ETL\Transformer\{AutoCastTransformer,
CallbackRowTransformer,
CrossJoinRowsTransformer,
Expand All @@ -50,9 +48,7 @@
OrderEntries\TypeComparator,
RenameEachEntryTransformer,
RenameEntryTransformer,
Rename\RenameCaseEntryStrategy,
Rename\RenameEntryStrategy,
Rename\RenameReplaceEntryStrategy,
ScalarFunctionFilterTransformer,
ScalarFunctionTransformer,
SelectEntriesTransformer,
Expand Down Expand Up @@ -724,85 +720,6 @@ public function rename(string $from, string $to) : self
return $this;
}

/**
* @lazy
* Iterate over all entry names and replace the given search string with replace string.
*
* @deprecated use DataFrame::renameEach() with a RenameReplaceStrategy
*/
public function renameAll(string $search, string $replace) : self
{
$this->renameEach(new RenameReplaceEntryStrategy($search, $replace));

return $this;
}

/**
* @lazy
*
* @deprecated use DataFrame::renameEach() with a selected StringStyles
*/
public function renameAllLowerCase() : self
{
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::LOWER));

return $this;
}

/**
* @lazy
* Rename all entries to a given style.
* Please look into \Flow\ETL\Function\StyleConverter\StringStyles class for all available styles.
*
* @deprecated use DataFrame::renameEach() with a selected Style
*/
public function renameAllStyle(OldStringStyles|StringStyles|string $style) : self
{
if ($style instanceof OldStringStyles) {
$style = StringStyles::fromString($style->value);
}

$this->renameEach(new RenameCaseEntryStrategy(\is_string($style) ? StringStyles::fromString($style) : $style));

return $this;
}

/**
* @lazy
*
* @deprecated use DataFrame::renameEach() with a selected Style
*/
public function renameAllUpperCase() : self
{
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::UPPER));

return $this;
}

/**
* @lazy
*
* @deprecated use DataFrame::renameEach() with a selected Style
*/
public function renameAllUpperCaseFirst() : self
{
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::UCFIRST));

return $this;
}

/**
* @lazy
*
* @deprecated use DataFrame::renameEach() with a selected Style
*/
public function renameAllUpperCaseWord() : self
{
$this->renameEach(new RenameCaseEntryStrategy(StringStyles::UCWORDS));

return $this;
}

public function renameEach(RenameEntryStrategy ...$strategies) : self
{
$this->pipeline->add(new RenameEachEntryTransformer(...$strategies));
Expand Down
11 changes: 2 additions & 9 deletions src/core/etl/src/Flow/ETL/Function/ArrayKeysStyleConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@

use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\{FlowContext, Row};
use Flow\ETL\Function\StyleConverter\{ArrayKeyConverter, StringStyles as OldStringStyles};
use Flow\ETL\Function\StyleConverter\ArrayKeyConverter;
use Flow\ETL\String\StringStyles;

final class ArrayKeysStyleConvert extends ScalarFunctionChain
{
private StringStyles $style;

public function __construct(
private readonly ScalarFunction $ref,
OldStringStyles|StringStyles $style,
private readonly StringStyles $style,
) {
if ($style instanceof OldStringStyles) {
$this->style = StringStyles::fromString($style->value);
} else {
$this->style = $style;
}
}

public function eval(Row $row, FlowContext $context) : mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Flow\ETL\Function\ArrayExpand\ArrayExpand;
use Flow\ETL\Function\ArraySort\Sort;
use Flow\ETL\Function\Between\Boundary;
use Flow\ETL\Function\StyleConverter\StringStyles as OldStringStyles;
use Flow\ETL\Hash\{Algorithm, NativePHPHash};
use Flow\ETL\String\StringStyles;
use Flow\Types\Type;
Expand Down Expand Up @@ -676,7 +675,7 @@ public function stringNormalize(ScalarFunction|int $form = \Normalizer::NFC) : S
* Covert string to a style from enum list, passed in parameter.
* Can be string "upper" or StringStyles::UPPER for Upper (example).
*/
public function stringStyle(ScalarFunction|string|OldStringStyles|StringStyles $style) : StringStyle
public function stringStyle(ScalarFunction|string|StringStyles $style) : StringStyle
{
return new StringStyle($this, $style);
}
Expand Down
7 changes: 2 additions & 5 deletions src/core/etl/src/Flow/ETL/Function/StringStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
use function Flow\Types\DSL\{type_enum, type_string};
use Flow\ETL\Exception\InvalidArgumentException;
use Flow\ETL\{FlowContext, Row};
use Flow\ETL\Function\StyleConverter\StringStyles as OldStringStyles;
use Flow\ETL\String\StringStyles;

final class StringStyle extends ScalarFunctionChain
{
public function __construct(
private readonly ScalarFunction|string $string,
private readonly ScalarFunction|string|OldStringStyles|StringStyles $style,
private readonly ScalarFunction|string|StringStyles $style,
) {
}

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

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

if (is_string($style)) {
$style = StringStyles::fromString($style);
} elseif ($style instanceof OldStringStyles) {
$style = StringStyles::fromString($style->value);
}

if (!$style instanceof StringStyles) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
use Flow\ETL\Processor\{BatchingProcessor, CollectingProcessor, VoidProcessor};
use Flow\ETL\Transformer\{CallbackRowTransformer,
DropEntriesTransformer,
EntryNameStyleConverterTransformer,
LimitTransformer,
RenameAllCaseTransformer,
RenameEachEntryTransformer,
RenameEntryTransformer,
RenameStrReplaceAllEntriesTransformer,
ScalarFunctionTransformer,
SelectEntriesTransformer};

Expand All @@ -38,13 +35,10 @@ final class LimitOptimization implements Optimization
private array $nonExpandingTransformers = [
CallbackRowTransformer::class,
ScalarFunctionTransformer::class,
EntryNameStyleConverterTransformer::class,
SelectEntriesTransformer::class,
DropEntriesTransformer::class,
RenameAllCaseTransformer::class,
RenameEachEntryTransformer::class,
RenameEntryTransformer::class,
RenameStrReplaceAllEntriesTransformer::class,
LimitTransformer::class,
];

Expand Down
14 changes: 14 additions & 0 deletions src/core/etl/src/Flow/ETL/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ public function rename(string $currentName, string $newName) : self
return new self($this->entries->rename($currentName, $newName));
}

/**
* Rename multiple entries in a single pass.
*
* @param array<string, string> $renames Map of old_name => new_name
*/
public function renameMany(array $renames) : self
{
if ($renames === []) {
return $this;
}

return new self($this->entries->renameMany($renames));
}

/**
* @return Schema
*/
Expand Down
30 changes: 30 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,36 @@ public function rename(string|Reference $current, string|Reference $new) : self
return self::recreate($entries);
}

/**
* Rename multiple entries in a single pass.
*
* @param array<string, string> $renames Map of old_name => new_name
*/
public function renameMany(array $renames) : self
{
if ($renames === []) {
return $this;
}

$entries = $this->entries;

foreach ($renames as $from => $to) {
if ($from === $to) {
continue;
}

if (!\array_key_exists($from, $entries)) {
throw InvalidLogicException::because(\sprintf('Entry "%s" does not exist', $from));
}

$entry = $entries[$from];
unset($entries[$from]);
$entries[$to] = $entry->rename($to);
}

return self::recreate($entries);
}

/**
* @param Entry<mixed> ...$entries
*/
Expand Down
2 changes: 1 addition & 1 deletion src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function name() : string
*/
public function rename(string $name) : static
{
return new self($name, $this->value);
return new self($name, $this->value, $this->definition->metadata());
}

public function toString() : string
Expand Down
2 changes: 1 addition & 1 deletion src/core/etl/src/Flow/ETL/Row/Entry/DateEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function name() : string

public function rename(string $name) : static
{
return new self($name, $this->value);
return new self($name, $this->value, $this->definition->metadata());
}

public function toString() : string
Expand Down
2 changes: 1 addition & 1 deletion src/core/etl/src/Flow/ETL/Row/Entry/DateTimeEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function name() : string

public function rename(string $name) : static
{
return new self($name, $this->value);
return new self($name, $this->value, $this->definition->metadata());
}

public function toString() : string
Expand Down
2 changes: 1 addition & 1 deletion src/core/etl/src/Flow/ETL/Row/Entry/EnumEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function name() : string

public function rename(string $name) : static
{
return new self($name, $this->value);
return new self($name, $this->value, $this->definition->metadata());
}

public function toString() : string
Expand Down
2 changes: 1 addition & 1 deletion src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function name() : string
*/
public function rename(string $name) : static
{
return new self($name, $this->value);
return new self($name, $this->value, $this->definition->metadata());
}

public function toString() : string
Expand Down
Loading
Loading