Skip to content
Search
Examples

Joins

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

A join matches rows from two frames on a condition.

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' => 'john@email.com'],
    ['id' => 3, 'email' => 'jane@emial.com'],
    ['id' => 4, 'email' => 'bruno@email.com'],
];

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