{"record":{"id":"eb7ff3d763b39c5b","repo":"pola-rs/polars","slug":"schema-mode-overwrite-is-not-supported-for-parti","errorCode":null,"errorMessage":"schema_mode='overwrite' is not supported for partitioned Iceberg tables","messagePattern":"schema_mode='overwrite' is not supported for partitioned Iceberg tables","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_sink.py","lineNumber":643,"sourceCode":"        evolved_schema = transaction.table_metadata.schema()\n        source_schema = pyarrow_to_schema(\n            self._get_source_schema(), name_mapping=evolved_schema.name_mapping\n        )\n        return evolved_schema, schema_to_pyarrow(source_schema)\n\n    def _attach_resolved_sink(self, plf: PyLazyFrame) -> PyLazyFrame:\n        from pyiceberg.table import TableProperties\n        from pyiceberg.utils.properties import property_as_bool, property_as_int\n\n        import polars as pl\n\n        table = self.table()\n        table_metadata = table.metadata\n        table_properties = table_metadata.properties\n\n        if self.schema_mode == \"overwrite\" and table.spec().fields:\n            msg = \"schema_mode='overwrite' is not supported for partitioned Iceberg tables\"\n            raise NotImplementedError(msg)\n\n        partition_key_exprs = _partition_key_exprs(table, self.source_schema)\n\n        sort_order = table.sort_order()\n        if sort_order.fields and self.schema_mode == \"overwrite\":\n            msg = \"schema_mode='overwrite' is not supported for Iceberg tables with a sort order\"\n            raise NotImplementedError(msg)\n\n        if location_provider_impl := table_properties.get(\n            TableProperties.WRITE_PY_LOCATION_PROVIDER_IMPL\n        ):\n            msg = (\n                \"sink to Iceberg table with custom location provider\"\n                f\" '{location_provider_impl}'\"\n            )\n            raise NotImplementedError(msg)\n\n        object_storage_enabled = property_as_bool(","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_sink.py#L625-L661","documentation":"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.","triggerScenarios":"Calling sink_iceberg(mode='overwrite', schema_mode='overwrite') against an Iceberg table whose partition spec (table.spec().fields) is non-empty.","commonSituations":"Targeting a table partitioned by date/category while trying to rewrite the schema; copying sink settings from an unpartitioned table to a partitioned one.","solutions":["Use schema_mode='merge' or None for partitioned tables","Drop and recreate the table without (or with a compatible) partition spec before overwriting"],"exampleFix":"// before\nlf.sink_iceberg('db.partitioned_t', mode='overwrite', schema_mode='overwrite')\n// after\nlf.sink_iceberg('db.partitioned_t', mode='overwrite', schema_mode='merge')","handlingStrategy":"validation","validationCode":"if schema_mode == 'overwrite' and table.spec().fields:\n    raise NotImplementedError('choose schema_mode merge/None for partitioned tables')","typeGuard":null,"tryCatchPattern":"try:\n    lf.sink_iceberg(target, mode='overwrite', schema_mode=schema_mode)\nexcept NotImplementedError as e:\n    if 'partitioned Iceberg tables' in str(e):\n        lf.sink_iceberg(target, mode='overwrite', schema_mode='merge')\n    else:\n        raise","preventionTips":["Check table.spec().fields before selecting schema_mode","Restrict schema_mode='overwrite' to unpartitioned tables in your tooling","Recreate tables when schema changes require it, rather than overwriting in place"],"tags":["python","polars","iceberg","partitioning"],"backgroundTag":"unsupported-operation","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}