flow php

UNIFIED DATA PROCESSING FRAMEWORK

composer require flow-php/etl ^0.10.0

Changelog

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

There are multiple ways to rename entries in a DataFrame:

  • rename(string $from, string $to) - renames a single entry
  • renameAll(string $search, string $replace) - renames all entries that contain a given substring and replaces it with another substring
  • renameAllToLowercase() - renames all entries to lowercase
  • renameAllStyle(StringStyles|string $style) - renames all entries to a given style (e.g. camel, snakem, kebab, etc.)

Code

<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{data_frame, from_array, to_stream};

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

data_frame()
    ->read(from_array([
        ['id' => 1, 'name' => 'Norbert', 'joined_id' => 1, 'joined_Status' => 'active'],
        ['id' => 2, 'name' => 'John', 'joined_id' => 2, 'joined_Status' => 'inactive'],
        ['id' => 3, 'name' => 'Jane', 'joined_id' => 3, 'joined_Status' => 'active'],
    ]))
    ->rename('id', 'user_id')
    ->renameAll('joined_', '')
    ->collect()
    ->write(to_stream(__DIR__ . '/output.txt', truncate: false))
    ->run();

Output

+---------+----+----------+--------+
|    name | id |   status | userId |
+---------+----+----------+--------+
| Norbert |  1 |   active |      1 |
|    John |  2 | inactive |      2 |
|    Jane |  3 |   active |      3 |
+---------+----+----------+--------+
3 rows

Contributors

Join us on GitHub external resource
scroll back to top