pola-rs/polars · error · NotImplementedError
sink to Iceberg table with partition field
Error message
sink to Iceberg table with partition field '{field.name}' on source column '{source_name}' with '{metrics_mode}' metrics; partition value inference requires lower and upper bounds What it means
Polars' Iceberg sink infers partition values from the source data, which requires lower/upper bounds column metrics for each partition source column. When the target table's metrics mode for a partition source column is 'none' (or metrics are unavailable), the bounds needed to compute partition values are missing, so _partition_key_exprs raises NotImplementedError. This is an explicit unsupported-configuration guard, not a data corruption issue.
Solutions
- Enable column metrics on the partition source column: set table property write.metrics.mode.<column>=truncate (or full), e.g. via table metadata update, then retry the sink.
- Remove/disable the partition field in the target spec, or sink into an unpartitioned table and let a compaction/rewrite step partition the data.
- Pre-compute partition columns yourself and write with a different writer (e.g. pyiceberg append) that does not need bounds-based partition inference.
- Upgrade pyiceberg/polars if the metrics plan was expected to include bounds (statistics may be missing due to older library behavior).
Defensive patterns
Strategy: validation
Validate before calling
spec = table.spec()
plan = compute_statistics_plan(table.schema(), table.metadata.properties)
for f in spec.fields:
stats = plan.get(f.source_id)
mode = stats.mode.type if stats else None
if mode is None or mode.value not in ("truncate", "full"):
raise ValueError(f"partition field {f.name} lacks bounds metrics; set write.metrics.mode for its source column") Type guard
def has_bounds_metrics(stats) -> bool:
return stats is not None and stats.mode.type.value in ("truncate", "full") Try / catch
try:
lf.sink_iceberg(target_table)
except NotImplementedError as e:
if "lower and upper bounds" in str(e):
enable_column_metrics(table, source_col) # fix table properties, then retry
else:
raise Prevention
- Never set write.metrics.mode=none globally on tables you plan to sink into with partition specs
- Audit table properties for write.metrics.mode.* overrides before sinking
- Prefer truncate or full metrics mode on partition source columns
When it happens
Trigger: Calling pl.scan_iceberg(...).sink_iceberg(...) (via _attach_resolved_sink -> _partition_key_exprs) against an Iceberg table whose partition spec has a field whose source column has write.metrics.mode=none (or whose statistics plan has no entry), so statistics.mode.type is not 'truncate' or 'full'.
Common situations: Target table properties set 'write.metrics.mode.default=none' (or 'write.metrics.default') to shrink metadata; table created by another engine with metrics disabled on the partitioned column; partitioning on a column the writer excluded from stats collection.
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
- sink to Iceberg table with
- sink to Iceberg table with
- Cannot infer partition value from Parquet metadata for…
- Iceberg sort order is no longer available
- Iceberg sort transform
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/2b8fc70fe615abae.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/iceberg/_sink.py:315
exprs: list[pl.Expr] = []
for field in spec.fields:
source_field = schema.find_field(field.source_id)
statistics = statistics_plan.get(field.source_id)
if field.source_id not in nested_source_ids and (
statistics is None or statistics.mode.type not in bounds_metrics_modes
):
source_name = schema.find_column_name(field.source_id)
metrics_mode = (
statistics.mode.type.value if statistics is not None else "unavailable"
)
msg = (
"sink to Iceberg table with partition field "
f"'{field.name}' on source column '{source_name}' with "
f"'{metrics_mode}' metrics; partition value inference requires "
"lower and upper bounds"
)
raise NotImplementedError(msg)
source_type = source_field.field_type
transform = field.transform
expr = _iceberg_source_expr(schema, field.source_id)
if isinstance(transform, IdentityTransform):
pass
elif isinstance(
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)View on GitHub (pinned to fe841f959e)