Skip to content

Commit deaf5b3

Browse files
authored
Added DataFrame with function (#1392)
1 parent e89fae7 commit deaf5b3

File tree

9 files changed

+31
-21
lines changed

9 files changed

+31
-21
lines changed

examples/topics/data_reading/elasticsearch/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@
5252
]
5353
))
5454
->write(to_stream(__DIR__ . '/output.raw.txt', truncate: false))
55-
->transform(es_hits_to_rows())
55+
->with(es_hits_to_rows())
5656
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
5757
->run();

examples/topics/data_writing/elasticsearch/code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@
5252
]
5353
))
5454
->write(to_stream(__DIR__ . '/output.raw.txt', truncate: false))
55-
->transform(es_hits_to_rows())
55+
->with(es_hits_to_rows())
5656
->write(to_stream(__DIR__ . '/output.txt', truncate: false))
5757
->run();

src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function test_extraction_index_with_from_and_size() : void
9090

9191
$results = (data_frame())
9292
->extract(from_es($this->elasticsearchContext->clientConfig(), $params))
93-
->transform(es_hits_to_rows(DocumentDataSource::fields))
93+
->with(es_hits_to_rows(DocumentDataSource::fields))
9494
->fetch();
9595

9696
self::assertCount(2000, $results);

src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function test_extraction_index_with_from_and_size() : void
6868

6969
$results = (data_frame())
7070
->extract(from_meilisearch($this->meilisearchContext->clientConfig(), $params, self::INDEX_NAME))
71-
->transform(meilisearch_hits_to_rows())
71+
->with(meilisearch_hits_to_rows())
7272
->fetch();
7373

7474
self::assertCount(49, $results);

src/bridge/symfony/http-foundation/src/Flow/Bridge/Symfony/HttpFoundation/FlowStreamedResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private function stream() : void
3434
{
3535
df($this->config)
3636
->read($this->extractor)
37-
->transform($this->transformations)
37+
->with($this->transformations)
3838
->dropPartitions()
3939
->write($this->output->loader())
4040
->run();

src/bridge/symfony/http-foundation/tests/Flow/Bridge/Symfony/HttpFoundation/Tests/Unit/Transformation/MaskColumnTransformationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function test_masking_columns_transformation() : void
1919
['id' => 3, 'name' => 'John Smith', 'salary' => 9000, 'currency' => 'USD'],
2020
['id' => 4, 'name' => 'Jane Smith', 'salary' => 10000, 'currency' => 'USD'],
2121
]))
22-
->transform(new MaskColumns(['salary']))
22+
->with(new MaskColumns(['salary']))
2323
->fetch()
2424
->toArray();
2525

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function collect() : self
222222
#[DSLMethod(exclude: true)]
223223
public function collectRefs(References $references) : self
224224
{
225-
$this->transform(new CallbackRowTransformer(function (Row $row) use ($references) : Row {
225+
$this->with(new CallbackRowTransformer(function (Row $row) use ($references) : Row {
226226
foreach ($row->entries()->all() as $entry) {
227227
$references->add($entry->ref());
228228
}
@@ -739,7 +739,7 @@ public function reorderEntries(Comparator $comparator = new TypeComparator()) :
739739
*/
740740
public function rows(Transformer|Transformation $transformer) : self
741741
{
742-
return $this->transform($transformer);
742+
return $this->with($transformer);
743743
}
744744

745745
/**
@@ -826,17 +826,13 @@ public function sortBy(Reference ...$entries) : self
826826
}
827827

828828
/**
829+
* Alias for DataFrame::with().
830+
*
829831
* @lazy
830832
*/
831833
public function transform(Transformer|Transformation $transformer) : self
832834
{
833-
if ($transformer instanceof Transformer) {
834-
$this->pipeline->add($transformer);
835-
836-
return $this;
837-
}
838-
839-
return $transformer->transform($this);
835+
return $this->with($transformer);
840836
}
841837

842838
/**
@@ -878,6 +874,20 @@ public function void() : self
878874
return $this;
879875
}
880876

877+
/**
878+
* @lazy
879+
*/
880+
public function with(Transformer|Transformation $transformer) : self
881+
{
882+
if ($transformer instanceof Transformer) {
883+
$this->pipeline->add($transformer);
884+
885+
return $this;
886+
}
887+
888+
return $transformer->transform($this);
889+
}
890+
881891
/**
882892
* @lazy
883893
*
@@ -910,7 +920,7 @@ public function withEntry(string|Definition $entry, ScalarFunction|WindowFunctio
910920

911921
$this->pipeline->add(new WindowFunctionTransformer($entry, $reference));
912922
} else {
913-
$this->transform(new ScalarFunctionTransformer($entry, $reference));
923+
$this->with(new ScalarFunctionTransformer($entry, $reference));
914924
}
915925

916926
return $this;

src/core/etl/tests/Flow/ETL/Tests/Unit/DataFrameTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function extract(FlowContext $context) : \Generator
508508
}
509509
}
510510
)
511-
->transform(
511+
->with(
512512
new class implements Transformer {
513513
public function transform(Rows $rows, FlowContext $context) : Rows
514514
{
@@ -545,7 +545,7 @@ public function extract(FlowContext $context) : \Generator
545545
}
546546
}
547547
)
548-
->transform(
548+
->with(
549549
new class implements Transformer {
550550
public function transform(Rows $rows, FlowContext $context) : Rows
551551
{

src/core/etl/tests/Flow/ETL/Tests/Unit/ETLErrorHandlingTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function load(Rows $rows, FlowContext $context) : void
5050
(data_frame())
5151
->extract($extractor)
5252
->onError(throw_error_handler())
53-
->transform($brokenTransformer)
53+
->with($brokenTransformer)
5454
->load($loader)
5555
->run();
5656
}
@@ -90,7 +90,7 @@ public function load(Rows $rows, FlowContext $context) : void
9090
(data_frame())
9191
->extract($extractor)
9292
->onError(ignore_error_handler())
93-
->transform($brokenTransformer)
93+
->with($brokenTransformer)
9494
->load($loader)
9595
->run();
9696

@@ -152,7 +152,7 @@ public function load(Rows $rows, FlowContext $context) : void
152152
(data_frame())
153153
->extract($extractor)
154154
->onError(skip_rows_handler())
155-
->transform($brokenTransformer)
155+
->with($brokenTransformer)
156156
->load($loader)
157157
->run();
158158

0 commit comments

Comments
 (0)