pola-rs/polars · error · NotImplementedError
sink to Iceberg table with sort order
Error message
sink to Iceberg table with sort order
What it means
The polars Iceberg sink does not support writing to tables that define a sort order. If `table.sort_order().fields` is non-empty, the sink raises NotImplementedError because it would produce data files that do not honor the table's declared sort order, violating table metadata expectations.
Solutions
- Sink into a table without a sort order (create a new table omitting the sort-order clause)
- If the sort order is unnecessary, replace/recreate the table with an unsorted spec (unsorted sort order)
- Sort the LazyFrame yourself (`.sort(...)`) so data honors the intent, though the sink still requires the table metadata to declare no sort order — combine with recreating the table
- Track polars releases; sink support for sorted tables may be added later
Example fix
// before: table created with a sort order # CREATE TABLE ... PARTITIONED BY (day) ... SORTED BY (event_time) // after: sink into an unsorted table # CREATE TABLE ... PARTITIONED BY (day) -- no sort order lf.sink_iceberg(table)
Defensive patterns
Strategy: validation
Validate before calling
if table.sort_order().fields:
raise ValueError(f"table '{table.name()}' has a sort order; polars sink_iceberg does not support sorted tables") Try / catch
try:
lf.sink_iceberg(table)
except NotImplementedError as e:
if 'sort order' in str(e):
raise RuntimeError("sink into an unsorted table or recreate the table without a sort order") from e
raise Prevention
- Check `table.sort_order().fields` before sinking
- Create target tables without SORTED BY / sort-order clauses if polars will write them
- If ordering matters, `.sort(...)` the LazyFrame yourself and use an unsorted table spec
When it happens
Trigger: `sink_iceberg` targeting an Iceberg table whose metadata sets a sort order (e.g. created by Spark with `SORTED BY` / `write ordered by`).
Common situations: Sinking into an existing production table that was created with a sort order; copying a sink pipeline from an unsorted dev table to a sorted prod table; engine migrations where the source table carried over its sort order.
Related errors
- schema_mode='overwrite' is not supported for Iceberg tables…
- cannot sink to static Iceberg table
- failed to load catalog for
- Iceberg sort transform
- Iceberg sort transform
AI-assisted analysis of pola-rs/polars@fc24390824 (2026-09-02).
Data as JSON: /api/errors/91385e6c1613caf1.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/iceberg/_sink.py:505
def _attach_resolved_sink(self, plf: PyLazyFrame) -> PyLazyFrame:
from pyiceberg.table import TableProperties
from pyiceberg.utils.properties import property_as_bool, property_as_int
import polars as pl
table = self.table()
table_metadata = table.metadata
table_properties = table_metadata.properties
if self.schema_mode == "overwrite" and table.spec().fields:
msg = "schema_mode='overwrite' is not supported for partitioned Iceberg tables"
raise NotImplementedError(msg)
partition_key_exprs = _partition_key_exprs(table, self.source_schema)
if table.sort_order().fields:
msg = "sink to Iceberg table with sort order"
raise NotImplementedError(msg)
if location_provider_impl := table_properties.get(
TableProperties.WRITE_PY_LOCATION_PROVIDER_IMPL
):
msg = (
"sink to Iceberg table with custom location provider"
f" '{location_provider_impl}'"
)
raise NotImplementedError(msg)
object_storage_enabled = property_as_bool(
table_properties,
TableProperties.OBJECT_STORE_ENABLED,
TableProperties.OBJECT_STORE_ENABLED_DEFAULT,
)
object_storage_partitioned_paths = (
property_as_bool(
table_properties,View on GitHub (pinned to fc24390824)