-
-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Sometimes we need to simply duplicate a row based on specific condition and then apply some transformations on it (or not).
Currently the only way to achieve that would be through iterating through dataset, filtering the rows we want to modify, apply transformations and then do union merge it with the main data frame.
But there is a better way:
<?php
$result = DataFrame::df()
->read(from_array($data))
->duplicateRow(
condition: ref('status')->equals('canceled'),
transformations: [
with_entry('amount', ref('amount')->multiply(-1)),
]
)
->run()
->toArray();We would need to introduce new dsl function, with_entry(string|Reference $ref, ScalarFunction $transformation)
That scalar function would simply create WithEntry object that we can also pass into DataFrame::transform() method alongside Transformer|Transformation|Transformations
which would be another great way to chain many transformations.
It would also allow us to deprecate array<string, ScalarFunction|WindowFunction> in withEntries and replace it with array<WithEntries>
Metadata
Metadata
Assignees
Labels
Type
Projects
Status