🚀 Jumpstart 2027: Custom, Secure AI Workflows to Adopt Now. Reserve your spot →

Polars 2.2

Hands-on in Dash: SQL that changes tables, out-of-core joins, and a faster engine

TL;DR

  • Polars 2.2.0 came out on November 24, 2026. The Polars team's highlights are joins that spill to disk when they don't fit in memory, SQL that changes tables (INSERT, UPDATE, DELETE, and COPY), writes and maintenance on Iceberg tables from SQL, a new scan_database, and 111 performance pull requests.
  • We added an SQL tab to Fleet Ops, the Dash app from our Polars tutorial, where analysts write Polars SQL over 21.2 million taxi trips with query parameters, views, macros, PIVOT, and an editable watch list. None of those statements run on Polars 2.1.
  • On the app's own queries, 2.2 gave the same answers as 2.1. value_counts with sorting ran about 3.4 times faster, and two joins over every trip ran 12% faster.
  • Six changes may need attention before you upgrade, among them str.find returning character offsets instead of byte offsets.
Fleet Ops SQL tab running a PIVOT query with $start and $end parameters for June 2026: trips by pickup hour in columns for Manhattan, Queens, Brooklyn, and the Bronx, drawn as one line per borough, with the result rows below

What is Polars?

Polars is a DataFrame library for Python with a query engine written in Rust. You describe a query, either with Polars expressions or in SQL, and Polars plans it, reads only the columns and rows it needs, and runs it on every core, on data in memory, in files, or in cloud storage. That makes it a good engine for Dash apps over data too big to load whole: meter reads, trades, sensor logs, claims, and trips.

Our Polars tutorial covers the basics and the full Fleet Ops app.

What's new in Polars 2.2

The release announcement groups the changes by area. These are the ones most data apps will notice:

  • Out-of-core joins. In 2.1 the group-by learned to spill to disk. In 2.2 streaming equi-joins do too: when the build side doesn't fit in the memory budget, Polars splits it by key hash and spills the partitions that don't fit. Operators that need hash tables now share one memory budget.
  • SQL that changes tables. Tables registered in a SQLContext can be changed with INSERT, UPDATE, DELETE, and COPY ... FROM, and COPY ... TO writes a query's result to a file. There are also views (CREATE VIEW, DESCRIBE), macros, query parameters passed with SQLContext.execute(..., params=...), PIVOT and UNPIVOT, PERCENTILE_CONT ... WITHIN GROUP, RANGE window frames with offsets, and functions such as COUNT_IF, MAX_BY, and DATE_DIFF.
  • Iceberg from SQL. Attached Iceberg catalog tables now take INSERT, UPDATE, DELETE, MERGE INTO, ALTER TABLE, time travel, and compaction with CALL rewrite_data_files.
  • Databases. pl.scan_database reads a table or query lazily and pushes column selection, filters, and limits into the SQL it sends.
  • Smaller additions. pl.date_diff, a pattern per row in str.replace, format specifications in pl.format, SQLContext(allow_file_reads=False) to stop SQL from reading files, and free-threaded Python wheels.
  • Performance. Multi-column keys packed into fixed-width integers, smarter build-side choice in streaming joins, quantiles by selection instead of sorting, and value_counts on the streaming group-by.
pip install -U polars

Before you upgrade. The announcement lists six changes that may need attention:

  • str.find returns character offsets instead of byte offsets;
  • some function arguments must be scalars when the query is planned;
  • SQL DELETE now changes the registered table;
  • mean, median, quantile, and sum now raise on dtypes where they used to return null;
  • SQL string length, position, and date part functions return Int64;
  • from_dicts raises on keys it didn't infer.

Hands-on: an SQL tab for Fleet Ops

Fleet Ops runs on six months of NYC Taxi and Limousine Commission (TLC) yellow taxi trips, April to September 2026, stored as six Parquet files. The Polars tutorial shows how they're prepared. The new SQL tab registers the trip files as a lazy table next to the zone lookup and a small watch list, and runs whatever SQL the analyst types, with $start and $end filled in from a date picker. Each example below runs in under 100 ms once the page has loaded.

Add an SQL tab to Fleet Ops. Register the trip files (lazy), the zone lookup and a small watch list table in a Polars 2.2 SQLContext with allow_file_reads=False. Show a textarea with example queries (PIVOT by borough, a CREATE VIEW with PERCENTILE_CONT, a CREATE MACRO with COUNT_IF, and INSERT and UPDATE on the watch list), run the statements in order, pass $start and $end from a date picker with params=, and show the time, a chart and the first 25 rows. Add a Download CSV button that runs COPY (query) TO a temporary file.

The core of the tab is a few lines:

ctx = pl.SQLContext(trips=pl.scan_parquet(files), zones=zones, watchlist=watch,
eager=True, allow_file_reads=False, allow_file_writes=False)
for statement in sql.split(";"):
params = {k: v for k, v in {"start": start, "end": end}.items() if f"${k}" in statement}
result = ctx.execute(statement, params=params or None)

Pivot with query parameters

The example at the top turns trips by pickup hour into one column per borough with PIVOT, for the dates in the picker. Passing the dates as parameters instead of pasting them into the SQL string keeps user input out of the query text.

A view and percentiles

Fleet Ops SQL tab with a CREATE VIEW of trips from the three airport zones and a query of median and 90th percentile trip minutes by pickup hour using PERCENTILE_CONT WITHIN GROUP, drawn as two lines

CREATE VIEW names a filtered query once, here the trips that start at the three airports, and PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY minutes) gives the median and 90th percentile trip time by hour. The same view can feed several queries on the page.

A macro for a business rule

Fleet Ops SQL tab with CREATE MACRO tip_rate(tip, fare) and a query of card trips, average tip rate and fares of $70 or more by borough using COUNT_IF, drawn as a bar chart by borough

A macro stores a formula the team agrees on, such as the tip rate, so every query computes it the same way. COUNT_IF counts the long fares in the same pass.

A watch list you can edit

Fleet Ops SQL tab running INSERT and UPDATE on a watch list table, then a query of pickups and median fare for each watched zone in June 2026, drawn as a bar chart: Upper East Side South, Midtown Center labeled Hotel corridor, and JFK Airport

INSERT and UPDATE change a table registered in the context, so an analyst can add zones to a watch list and see their numbers in the next statement. Each run starts from the same small list, so running the example twice doesn't add a zone twice, and one person's edits never reach anyone else.

Putting Polars 2.2 to the test

We ran six steps from Fleet Ops on 2.1.0 and 2.2.0, in two Python 3.13 virtual environments that differed only in Polars, on four CPUs. Each step ran in its own process, three timed runs after one warm-up, over three rounds alternating the versions, and we kept the best of nine runs.

  • Same answers. All six steps gave identical results on both versions.
  • value_counts with sort=True over every trip's pickup zone took 0.051 s on 2.2 against 0.175 s on 2.1, about 3.4 times faster. The release moved it onto the streaming group-by.
  • Two joins of every trip to the zone lookup, then a group-by of borough pairs, took 0.215 s against 0.245 s, 12% faster.
  • The other four steps (daily buckets, a weekday-by-hour group-by, per-zone medians, and hourly quantiles) were within about 11% either way, which is inside run-to-run noise on this machine.
  • SQL. We tried 16 SQL statements that use the features above. On 2.1, 15 raise an error; on 2.2, all 16 run. The one that runs on both is a plain SELECT.

Running Polars SQL on Plotly Cloud and Dash Enterprise

What we learned adding the tab to Fleet Ops, which applies the same way on Dash Enterprise:

  • Lock down typed SQL. Create the context with allow_file_reads=False and allow_file_writes=False, so a query can only touch the tables you registered, and run exports through a separate context that writes to a path the app chooses.
  • One context per callback. Creating a SQLContext over lazy frames costs almost nothing, so build one per request. A shared context would let one user's INSERT show up in another user's results.
  • Pass only the parameters a statement uses. Polars raises an error for a parameter that doesn't appear in the query, so when one page runs several statements, filter the dictionary per statement as above.
  • Pin the version. SQL that runs on 2.2 fails on 2.1, so pin polars==2.2.0 in requirements.txt.
  • Expect slower first loads. When a page first loads, every tab's callbacks run at once on the same CPUs, and our pivot query took over a second instead of under 100 ms.

FAQ

Glossary

SQLContext. A Polars object that maps table names to DataFrames or LazyFrames so SQL can query them.

Query parameter. A placeholder such as $start in an SQL query, filled in with a value when the query runs.

Macro. A named SQL expression, defined once with CREATE MACRO and reused in later queries.

Out-of-core. Processing data larger than memory by spilling part of it to disk.

Streaming engine. Polars' engine that processes data in batches instead of all at once.

bluesly
x
instagram
youtube
medium
fcaebook

Product

© 2026
Plotly. All rights reserved.
Cookie Preferences
aicpa/soc2