flow php

UNIFIED DATA PROCESSING FRAMEWORK

composer require flow-php/etl ~0.18.0

ChangelogRelease Cycle

elephant
extract

Extracts

Read from various data sources.

arrow
transform

Transforms

Shape and optimize for your needs.

arrow
load

Loads

Store and secure in one of many available data sinks.

Examples:

Description

The easiest way to call any callable. Whenever you need to apply a function or method to a column or a value, and there is no existing scalar function available, you can use the call scalar function.

There are two ways to use it:

  • ref('column')->call()
  • \Flow\ETL\DSL\call()

The main difference is that the first one will always pass the column value as argument.
When passing additional arguments, it might be necessary to use refAlias to provide a argument name for column value.

composer.json
{
    "name": "flow-php/examples",
    "description": "Flow PHP - Examples",
    "license": "MIT",
    "type": "library",
    "require": {
        "flow-php/etl": "1.x-dev"
    }
}
code.php
<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{data_frame,
    from_array,
    lit,
    ref,
    to_stream};
use function Flow\Types\DSL\{type_integer, type_list};

require __DIR__ . '/../../../../vendor/autoload.php';

(data_frame())
    ->read(
        from_array(
            [
                ['integers' => '1,2,3'],
                ['integers' => '5,7'],
                ['integers' => '0,2,4'],
            ]
        )
    )
    ->withEntry(
        'integers',
        ref('integers')->call(lit('explode'), ['separator' => ','], refAlias: 'string', returnType: type_list(type_integer()))
    )
    ->write(to_stream(__DIR__ . '/output.txt', truncate: false))
    ->run();

Output

+----------+
| integers |
+----------+
|  [1,2,3] |
+----------+
1 rows
+----------+
| integers |
+----------+
|    [5,7] |
+----------+
1 rows
+----------+
| integers |
+----------+
|  [0,2,4] |
+----------+
1 rows

Contributors

Join us on GitHub external resource
scroll back to top