{"record":{"id":"4d239831a8eb760a","repo":"pola-rs/polars","slug":"schema-mode-overwrite-is-not-supported-for-iceberg-tables","errorCode":null,"errorMessage":"schema_mode='overwrite' is not supported for Iceberg tables with a sort order","messagePattern":"schema_mode='overwrite' is not supported for Iceberg tables with a sort order","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_sink.py","lineNumber":650,"sourceCode":"        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(\n            table_properties,\n            TableProperties.OBJECT_STORE_ENABLED,\n            TableProperties.OBJECT_STORE_ENABLED_DEFAULT,\n        )\n        object_storage_partitioned_paths = (\n            property_as_bool(\n                table_properties,","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_sink.py#L632-L668","documentation":"Sort orders in Iceberg are metadata bound to the schema columns; overwriting the schema could invalidate the defined sort order. Polars raises NotImplementedError when the table has sort order fields and schema_mode='overwrite' is requested.","triggerScenarios":"Calling sink_iceberg(mode='overwrite', schema_mode='overwrite') against a table whose sort_order() has fields (e.g. table written with an ORDER BY clause).","commonSituations":"Sinking into a table created with a sort order (write.order.enabled / SQL-created tables) while trying to replace the schema.","solutions":["Use schema_mode='merge' or None for tables with a sort order","Remove the table's sort order metadata, or recreate the table, before overwriting the schema"],"exampleFix":"// before\nlf.sink_iceberg('db.sorted_t', mode='overwrite', schema_mode='overwrite')\n// after\nlf.sink_iceberg('db.sorted_t', mode='overwrite', schema_mode=None)","handlingStrategy":"validation","validationCode":"if schema_mode == 'overwrite' and table.sort_order().fields:\n    raise NotImplementedError('choose schema_mode merge/None for sorted tables')","typeGuard":null,"tryCatchPattern":"try:\n    lf.sink_iceberg(target, mode='overwrite', schema_mode=schema_mode)\nexcept NotImplementedError as e:\n    if 'sort order' in str(e):\n        lf.sink_iceberg(target, mode='overwrite', schema_mode='merge')\n    else:\n        raise","preventionTips":["Inspect table.sort_order().fields before overwriting schemas","Avoid schema_mode='overwrite' on tables created with sort orders","Document that schema rewrite requires tables without sort-order metadata"],"tags":["python","polars","iceberg","sort-order"],"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"}