Skip to content
Search
Examples

Join

Description

Combine two datasets based on matching column values, similar to SQL JOIN operations. Supports inner, left, right, and left anti join types.

For large datasets that don't fit in memory, consider using joinEach instead.

Documentation

Code

<?php

declare(strict_types=1);

use function Flow\ETL\DSL\{data_frame, from_array, join_on, to_output};
use Flow\ETL\Join\Join;

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

$users = [
    ['id' => 1, 'name' => 'John'],
    ['id' => 2, 'name' => 'Jane'],
    ['id' => 3, 'name' => 'Doe'],
    ['id' => 4, 'name' => 'Bruno'],
];

$emails = [
    ['id' => 2, 'email' => '[email protected]'],
    ['id' => 3, 'email' => '[email protected]'],
    ['id' => 4, 'email' => '[email protected]'],
];

data_frame()
    ->read(from_array($users))
    ->join(
        data_frame()->read(from_array($emails)),
        join_on(['id' => 'id'], join_prefix: 'joined_'),
        Join::left
    )
    ->collect()
    ->write(to_output(truncate: false))
    ->run();
Contributors

Built in the open.

Join us on GitHub
scroll back to top