pola-rs/polars · error · NotImplementedError

schema_mode='overwrite' is not supported for partitioned…

Error message

schema_mode='overwrite' is not supported for partitioned Iceberg tables

What it means

schema_mode='overwrite' replaces the table schema, which is incompatible with partitioned tables: partition spec fields are tied to the existing schema. Polars raises NotImplementedError when the table's partition spec has fields and schema_mode='overwrite' is requested.

Solutions

  1. Use schema_mode='merge' or None for partitioned tables
  2. Drop and recreate the table without (or with a compatible) partition spec before overwriting

Example fix

// before
lf.sink_iceberg('db.partitioned_t', mode='overwrite', schema_mode='overwrite')
// after
lf.sink_iceberg('db.partitioned_t', mode='overwrite', schema_mode='merge')
Defensive patterns

Strategy: validation

Validate before calling

if schema_mode == 'overwrite' and table.spec().fields:
    raise NotImplementedError('choose schema_mode merge/None for partitioned tables')

Try / catch

try:
    lf.sink_iceberg(target, mode='overwrite', schema_mode=schema_mode)
except NotImplementedError as e:
    if 'partitioned Iceberg tables' in str(e):
        lf.sink_iceberg(target, mode='overwrite', schema_mode='merge')
    else:
        raise

Prevention

When it happens

Trigger: Calling sink_iceberg(mode='overwrite', schema_mode='overwrite') against an Iceberg table whose partition spec (table.spec().fields) is non-empty.

Common situations: Targeting a table partitioned by date/category while trying to rewrite the schema; copying sink settings from an unpartitioned table to a partitioned one.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/eb7ff3d763b39c5b. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/iceberg/_sink.py:643

        evolved_schema = transaction.table_metadata.schema()
        source_schema = pyarrow_to_schema(
            self._get_source_schema(), name_mapping=evolved_schema.name_mapping
        )
        return evolved_schema, schema_to_pyarrow(source_schema)

    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)

        sort_order = table.sort_order()
        if sort_order.fields and self.schema_mode == "overwrite":
            msg = "schema_mode='overwrite' is not supported for Iceberg tables with a 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(

View on GitHub (pinned to fe841f959e)