{"record":{"id":"2b8fc70fe615abae","repo":"pola-rs/polars","slug":"sink-to-iceberg-table-with-partition-field-field","errorCode":null,"errorMessage":"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","messagePattern":"sink to Iceberg table with partition field '(.+?)' on source column '(.+?)' with '(.+?)' metrics; partition value inference requires lower and upper bounds","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_sink.py","lineNumber":315,"sourceCode":"    exprs: list[pl.Expr] = []\n\n    for field in spec.fields:\n        source_field = schema.find_field(field.source_id)\n        statistics = statistics_plan.get(field.source_id)\n        if field.source_id not in nested_source_ids and (\n            statistics is None or statistics.mode.type not in bounds_metrics_modes\n        ):\n            source_name = schema.find_column_name(field.source_id)\n            metrics_mode = (\n                statistics.mode.type.value if statistics is not None else \"unavailable\"\n            )\n            msg = (\n                \"sink to Iceberg table with partition field \"\n                f\"'{field.name}' on source column '{source_name}' with \"\n                f\"'{metrics_mode}' metrics; partition value inference requires \"\n                \"lower and upper bounds\"\n            )\n            raise NotImplementedError(msg)\n\n        source_type = source_field.field_type\n        transform = field.transform\n        expr = _iceberg_source_expr(schema, field.source_id)\n\n        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)","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_sink.py#L297-L333","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"spec = table.spec()\nplan = compute_statistics_plan(table.schema(), table.metadata.properties)\nfor f in spec.fields:\n    stats = plan.get(f.source_id)\n    mode = stats.mode.type if stats else None\n    if mode is None or mode.value not in (\"truncate\", \"full\"):\n        raise ValueError(f\"partition field {f.name} lacks bounds metrics; set write.metrics.mode for its source column\")","typeGuard":"def has_bounds_metrics(stats) -> bool:\n    return stats is not None and stats.mode.type.value in (\"truncate\", \"full\")","tryCatchPattern":"try:\n    lf.sink_iceberg(target_table)\nexcept NotImplementedError as e:\n    if \"lower and upper bounds\" in str(e):\n        enable_column_metrics(table, source_col)  # fix table properties, then retry\n    else:\n        raise","preventionTips":["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"],"tags":["iceberg","partitioning","not-implemented","sink"],"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"}