pola-rs/polars · error · NotImplementedError

sink to Iceberg table with

Error message

sink to Iceberg table with '{transform}' partition transform

What it means

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.

Solutions

  1. 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).
  2. If bucketing semantics matter, pre-compute the bucket value in a supported way and partition by identity on that computed column.
  3. Sink into a staging unpartitioned table and let the engine's rewrite/compaction produce the bucketed layout.
  4. Track polars releases for bucket-transform sink support and upgrade when available.

Example fix

// before: target partitioned by bucket(16, user_id)
PartitionField(source_id=user_id, transform=BucketTransform(16), ...)
// after: precompute and partition by identity on a bucket column
df = df.with_columns(bucket=(pl.col("user_id").hash() % 16))
PartitionField(source_id=bucket_col, transform=IdentityTransform(), ...)
Defensive patterns

Strategy: validation

Validate before calling

from pyiceberg.transforms import (BucketTransform, DayTransform, HourTransform,
    IdentityTransform, MonthTransform, TruncateTransform, YearTransform)
SUPPORTED = (IdentityTransform, YearTransform, MonthTransform,
             DayTransform, HourTransform, TruncateTransform)
for f in table.spec().fields:
    if not isinstance(f.transform, SUPPORTED):
        raise ValueError(f"partition transform {f.transform} unsupported for polars sink")

Type guard

def sinkable_partition_transform(transform) -> bool:
    from pyiceberg.transforms import (BucketTransform, DayTransform, HourTransform,
        IdentityTransform, MonthTransform, TruncateTransform, YearTransform)
    return isinstance(transform, (IdentityTransform, YearTransform,
        MonthTransform, DayTransform, HourTransform, TruncateTransform))

Try / catch

try:
    lf.sink_iceberg(target_table)
except NotImplementedError as e:
    if "partition transform" in str(e):
        target = unpartitioned_target_or_precomputed_identity_table(lf, target_table)
        lf.sink_iceberg(target)
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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/afcab0822e55bcfe. Report an issue: GitHub.

Appendix: source

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

            transform, (YearTransform, MonthTransform, DayTransform, HourTransform)
        ):
            expr = _temporal_transform_expr(expr, source_type, transform)
        elif isinstance(transform, TruncateTransform):
            if isinstance(source_type, (IntegerType, LongType)):
                expr = expr - expr % transform.width
            elif isinstance(source_type, StringType):
                expr = expr.str.slice(0, transform.width)
            elif isinstance(source_type, BinaryType):
                expr = expr.bin.slice(0, transform.width)
            else:
                msg = (
                    "sink to Iceberg table with "
                    f"'{transform}' partition transform on '{source_type}'"
                )
                raise NotImplementedError(msg)
        else:
            msg = f"sink to Iceberg table with '{transform}' partition transform"
            raise NotImplementedError(msg)

        key_name = f"__POLARS_ICEBERG_PARTITION_{field.field_id}"
        while key_name in reserved_names:
            key_name += "_"
        reserved_names.add(key_name)
        exprs.append(expr.alias(key_name))

    return exprs


class _SortTransform:
    """Apply an Iceberg sort transform without pickling its cached callable."""

    def __init__(
        self, transform: Transform[Any, Any], source_type: IcebergType
    ) -> None:
        self.transform = transform
        self.source_type = source_type

View on GitHub (pinned to fe841f959e)