{"record":{"id":"f656332483c7c6fb","repo":"pola-rs/polars","slug":"sink-to-iceberg-table-with-transform-partition","errorCode":null,"errorMessage":"sink to Iceberg table with '{transform}' partition transform on '{source_type}'","messagePattern":"sink to Iceberg table with '(.+?)' partition transform on '(.+?)'","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_sink.py","lineNumber":339,"sourceCode":"        if isinstance(transform, IdentityTransform):\n            pass\n        elif isinstance(\n            transform, (YearTransform, MonthTransform, DayTransform, HourTransform)\n        ):\n            expr = _temporal_transform_expr(expr, source_type, transform)\n        elif isinstance(transform, TruncateTransform):\n            if isinstance(source_type, (IntegerType, LongType)):\n                expr = expr - expr % transform.width\n            elif isinstance(source_type, StringType):\n                expr = expr.str.slice(0, transform.width)\n            elif isinstance(source_type, BinaryType):\n                expr = expr.bin.slice(0, transform.width)\n            else:\n                msg = (\n                    \"sink to Iceberg table with \"\n                    f\"'{transform}' partition transform on '{source_type}'\"\n                )\n                raise NotImplementedError(msg)\n        else:\n            msg = f\"sink to Iceberg table with '{transform}' partition transform\"\n            raise NotImplementedError(msg)\n\n        key_name = f\"__POLARS_ICEBERG_PARTITION_{field.field_id}\"\n        while key_name in reserved_names:\n            key_name += \"_\"\n        reserved_names.add(key_name)\n        exprs.append(expr.alias(key_name))\n\n    return exprs\n\n\nclass _SortTransform:\n    \"\"\"Apply an Iceberg sort transform without pickling its cached callable.\"\"\"\n\n    def __init__(\n        self, transform: Transform[Any, Any], source_type: IcebergType","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_sink.py#L321-L357","documentation":"_partition_key_exprs supports TruncateTransform only for integer (int/long), string, and binary source columns. If the partition spec applies a truncate transform to any other source type (e.g. decimal, double, date), Polars cannot build the partition key expression and raises NotImplementedError. It is a guard against unsupported partition transform/type combinations.","triggerScenarios":"sink_iceberg into a table whose partition spec contains a TruncateTransform W on a source column whose Iceberg type is not IntegerType/LongType/StringType/BinaryType (e.g. truncate on a decimal or float column).","commonSituations":"Tables partitioned with truncate on decimal columns created by Spark/Trino; copying a spec from another engine where such combinations are legal; manually authoring a partition spec with truncate on a numeric non-integer column.","solutions":["Recreate or alter the target table's partition spec to use truncate only on int/long/string/binary columns (e.g. replace truncate on decimal with identity or a temporal transform).","Cast the partition source column to a supported type (string for truncation) and update the spec accordingly.","Sink to an unpartitioned table and partition later via a rewrite/compaction job in your catalog engine.","Check whether a newer polars/pyiceberg version added support for this transform/type pair."],"exampleFix":"// before: spec truncates a decimal column\nspec = PartitionSpec(PartitionField(source_id=dec_id, transform=TruncateTransform(10), ...))\n// after: use identity on the decimal column\nspec = PartitionSpec(PartitionField(source_id=dec_id, transform=IdentityTransform(), ...))","handlingStrategy":"validation","validationCode":"from pyiceberg.transforms import TruncateTransform\nfrom pyiceberg.types import IntegerType, LongType, StringType, BinaryType\nfor f in table.spec().fields:\n    src = table.schema().find_field(f.source_id)\n    if isinstance(f.transform, TruncateTransform) and not isinstance(\n        src.field_type, (IntegerType, LongType, StringType, BinaryType)\n    ):\n        raise ValueError(f\"truncate partition on unsupported type {src.field_type}\")","typeGuard":"def truncate_supported(field_type) -> bool:\n    from pyiceberg.types import IntegerType, LongType, StringType, BinaryType\n    return isinstance(field_type, (IntegerType, LongType, StringType, BinaryType))","tryCatchPattern":"try:\n    lf.sink_iceberg(target_table)\nexcept NotImplementedError as e:\n    if \"partition transform on\" in str(e):\n        target = recreate_table_without_unsupported_partition_transforms(target_table)\n        lf.sink_iceberg(target)\n    else:\n        raise","preventionTips":["When creating sink target tables, restrict truncate partition transforms to int/long/string/binary columns","Inspect table.spec() before choosing a sink target","Avoid copying partition specs verbatim from Spark/Trino tables"],"tags":["iceberg","partitioning","not-implemented","transform"],"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"}