apache/iceberg · error · UnsupportedOperationException

Expected truncation col to be tinyint, shortint, int, bigint

Error message

Expected truncation col to be tinyint, shortint, int, bigint, decimal, string, or binary

What it means

The truncate function supports truncating tinyint, shortint, int, bigint, decimal, string, and binary values. bind() throws this UnsupportedOperationException when the value argument's type is outside that set (e.g. date, timestamp, float, double, boolean, array, struct).

Source

Thrown at spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java:93

    DataType valueType = valueField.dataType();
    if (valueType instanceof ByteType) {
      return new TruncateTinyInt();
    } else if (valueType instanceof ShortType) {
      return new TruncateSmallInt();
    } else if (valueType instanceof IntegerType) {
      return new TruncateInt();
    } else if (valueType instanceof LongType) {
      return new TruncateBigInt();
    } else if (valueType instanceof DecimalType) {
      return new TruncateDecimal(
          ((DecimalType) valueType).precision(), ((DecimalType) valueType).scale());
    } else if (valueType instanceof StringType) {
      return new TruncateString();
    } else if (valueType instanceof BinaryType) {
      return new TruncateBinary();
    } else {
      throw new UnsupportedOperationException(
          "Expected truncation col to be tinyint, shortint, int, bigint, decimal, string, or binary");
    }
  }

  @Override
  public String description() {
    return name()
        + "(width, col) - Call Iceberg's truncate transform\n"
        + "  width :: width for truncation, e.g. truncate(10, 255) -> 250 (must be an integer)\n"
        + "  col :: column to truncate (must be an integer, decimal, string, or binary)";
  }

  @Override
  public String name() {
    return "truncate";
  }

  public abstract static class TruncateBase<T> extends BaseScalarFunction<T> {

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Cast the value to a supported type first (e.g. CAST(ts AS STRING) or CAST(f AS DECIMAL(38,s)))
  2. For date/timestamp truncation use date_trunc instead of truncate
  3. For float/double rounding use round, floor, or cast to DECIMAL before truncating

Example fix

// before
SELECT truncate(10, price) FROM t; -- price is DOUBLE
// after
SELECT truncate(2, CAST(price AS DECIMAL(38, 2))) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

require(Seq("tinyint","shortint","int","bigint","decimal","string","binary").contains(valueColType), s"truncate unsupported on $valueColType")

Try / catch

try { ... } catch { case e: UnsupportedOperationException if e.getMessage.contains("truncation col") => ... }

Prevention

When it happens

Trigger: Calling truncate(width, col) where col is a DOUBLE/FLOAT, DATE, TIMESTAMP, BOOLEAN, or complex type; also passing a null-typed literal that Spark cannot coerce.

Common situations: Attempting float truncation via the Iceberg function (truncation only supports integral/decimal/string/binary per the Iceberg spec); truncating timestamps instead of using date_trunc; applying truncate to struct/array columns.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/0847a46c731b133b. Report an issue: GitHub.