Polars pipeline
phplyr works on any phibble table. This example runs the pipeline from the SQL example on an in-memory DataFrame and on a PolarsTable, which holds the data in Polars through the php_polars extension from phpolars. The steps use col() expressions, so the Polars side runs them in Polars instead of in PHP.
The input stacks copies of the 3,000 simulated rentals, up to 300,000 rows. Polars runs the steps quickly, and the time to copy data in and out of Polars matters more at small sizes.
Code
$pipeline = fn (Table $rentals) => $rentals |>
filter(col('bedrooms')->ge($minBedrooms)) |>
mutate(rent_per_m2: col('monthly_rent')->div(col('area_m2'))) |>
group_by('neighborhood') |>
summarise(rentals: n(), mean_rent_per_m2: mean('rent_per_m2')) |>
arrange(desc('mean_rent_per_m2'));
$inMemory = $df |> $pipeline;
$inPolars = PolarsTable::fromTable($df) |> $pipeline;
$pipeline = fn (Table $rentals) => phplyr($rentals)
->filter(col('bedrooms')->ge($minBedrooms))
->mutate(rent_per_m2: col('monthly_rent')->div(col('area_m2')))
->groupBy('neighborhood')
->summarise(rentals: n(), mean_rent_per_m2: mean('rent_per_m2'))
->arrange(desc('mean_rent_per_m2'))
->get();
$inMemory = $pipeline($df);
$inPolars = $pipeline(PolarsTable::fromTable($df));