{"record":{"id":"afcab0822e55bcfe","repo":"pola-rs/polars","slug":"sink-to-iceberg-table-with-transform-partition-afcab0","errorCode":null,"errorMessage":"sink to Iceberg table with '{transform}' partition transform","messagePattern":"sink to Iceberg table with '(.+?)' partition transform","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_sink.py","lineNumber":342,"sourceCode":"            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\n    ) -> None:\n        self.transform = transform\n        self.source_type = source_type","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_sink.py#L324-L360","documentation":"The final branch of _partition_key_exprs raises when the partition field uses a transform Polars' sink does not implement at all (anything other than Identity, Year/Month/Day/Hour, or Truncate — typically BucketTransform). Partition value inference for such transforms is not supported, so the sink aborts with NotImplementedError.","triggerScenarios":"sink_iceberg targeting a table whose partition spec includes a BucketTransform (or any future/unrecognized transform type) on any field; e.g. partitioned by bucket(16, user_id).","commonSituations":"Writing to tables created by Spark/Trino/Flink that commonly partition by bucket; migrating an existing bucketed table as a sink target; copying a production partition spec unchanged.","solutions":["Choose a sink target whose partition spec uses only identity, year/month/day/hour, or truncate transforms (create a new table or rewrite the spec).","If bucketing semantics matter, pre-compute the bucket value in a supported way and partition by identity on that computed column.","Sink into a staging unpartitioned table and let the engine's rewrite/compaction produce the bucketed layout.","Track polars releases for bucket-transform sink support and upgrade when available."],"exampleFix":"// before: target partitioned by bucket(16, user_id)\nPartitionField(source_id=user_id, transform=BucketTransform(16), ...)\n// after: precompute and partition by identity on a bucket column\ndf = df.with_columns(bucket=(pl.col(\"user_id\").hash() % 16))\nPartitionField(source_id=bucket_col, transform=IdentityTransform(), ...)","handlingStrategy":"validation","validationCode":"from pyiceberg.transforms import (BucketTransform, DayTransform, HourTransform,\n    IdentityTransform, MonthTransform, TruncateTransform, YearTransform)\nSUPPORTED = (IdentityTransform, YearTransform, MonthTransform,\n             DayTransform, HourTransform, TruncateTransform)\nfor f in table.spec().fields:\n    if not isinstance(f.transform, SUPPORTED):\n        raise ValueError(f\"partition transform {f.transform} unsupported for polars sink\")","typeGuard":"def sinkable_partition_transform(transform) -> bool:\n    from pyiceberg.transforms import (BucketTransform, DayTransform, HourTransform,\n        IdentityTransform, MonthTransform, TruncateTransform, YearTransform)\n    return isinstance(transform, (IdentityTransform, YearTransform,\n        MonthTransform, DayTransform, HourTransform, TruncateTransform))","tryCatchPattern":"try:\n    lf.sink_iceberg(target_table)\nexcept NotImplementedError as e:\n    if \"partition transform\" in str(e):\n        target = unpartitioned_target_or_precomputed_identity_table(lf, target_table)\n        lf.sink_iceberg(target)\n    else:\n        raise","preventionTips":["Check the target partition spec for BucketTransform before using it as a sink target","Prefer temporal (year/month/day/hour), identity, or truncate partitioning for polars-written tables","For bucketed layouts, compute bucket columns yourself and partition by identity"],"tags":["iceberg","partitioning","not-implemented","bucket-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"}