phplyr
Examples

One pipeline, three backends

Join, summarize, and rank sales on phibble's DataFrame, on SQLite, and on Polars, with timings and a check that every backend returns the same rows.
Uses phibble phplyr

Inputs

Backend
Running

phplyr functions call the methods of phibble's Table contract, so one pipeline runs on several backends. DataFrame evaluates it in PHP. SqlTable compiles col() expressions and helpers such as mean() to SQL, and collect() runs the query. PolarsTable runs the same expressions in Polars through the php_polars extension. This pipeline joins sales to stores, sums revenue per region and product, and keeps each region's top products.

$top = $sales |>
    filter(col('units')->gt(0)) |>
    left_join($stores, by: 'store') |>
    group_by('region', 'product') |>
    summarize(orders: n(), revenue: sum(col('units')->mul(col('price'))), avg_price: mean('price')) |>
    group_by('region') |>
    mutate(rank: min_rank(desc('revenue'))) |>
    filter(col('rank')->le(3)) |>
    arrange('region', 'rank') |>
    collect();
$top = phplyr($sales)
    ->filter(col('units')->gt(0))
    ->leftJoin($stores, by: 'store')
    ->groupBy('region', 'product')
    ->summarize(orders: n(), revenue: sum(col('units')->mul(col('price'))), avg_price: mean('price'))
    ->groupBy('region')
    ->mutate(rank: min_rank(desc('revenue')))
    ->filter(col('rank')->le(3))
    ->arrange('region', 'rank')
    ->collect()
    ->get();
Pipeline time (ms)
24.4
Rows in
10000
Rows out
15

Choose another backend to check its rows against DataFrame.

Revenue of the top products in each region

Result

region product orders revenue avg_price rank
Central p44 49 30,533.28 58.23 1
Central p45 41 29,228.55 53.53 2
Central p17 50 29,185.46 49.35 3
East p49 54 31,208.42 47.07 1
East p30 56 27,478.25 45.28 2
East p15 39 24,994.01 56.73 3
North p13 43 29,461.78 64.90 1
North p43 43 28,182.83 52.89 2
North p20 50 26,918.09 50.73 3
South p16 48 28,577.31 56.62 1
South p31 44 28,503.83 58.78 2
South p29 48 28,301.87 53.28 3
West p43 41 29,264.92 56.60 1
West p18 51 28,001.14 56.37 2
West p35 48 25,946.65 55.53 3

The timing covers the pipeline only, on the site's server. Building the tables is not timed. The performance page has benchmarks at a million rows, with dplyr for comparison.

Script: site/vignettes/backends.php in phpstats/phplyr@d319dc5.