apache/iceberg · error · UnsupportedOperationException
Expected truncation col to be tinyint, shortint, int…
Error message
Expected truncation col to be tinyint, shortint, int, bigint, decimal, string, or binary
What it means
After validating the width, TruncateFunction.bind() dispatches on the value column's type to a typed implementation. Only tinyint, smallint, int, bigint, decimal, string, and binary are supported; other types (timestamp, date, double, float, boolean, complex types) are rejected with this UnsupportedOperationException.
Solutions
- For temporal columns, use the appropriate transform instead: iceberg.days(ts), iceberg.hours(ts), or iceberg.months(ts).
- For floats/doubles, cast to DECIMAL: truncate(cast(x AS DECIMAL(38, 4)) width-adjusted).
- For other cases cast to a supported type, e.g. CAST(col AS STRING) before truncating.
- Verify the value column type with typeof(col).
Example fix
// before SELECT iceberg.truncate(10, event_ts) FROM t; -- TIMESTAMP not supported // after SELECT iceberg.days(event_ts) FROM t; -- or, for numeric SELECT iceberg.truncate(4, CAST(score AS DECIMAL(38, 4))) FROM t;
Defensive patterns
Strategy: type-guard
Validate before calling
val t = col.dataType val supported = Seq(ByteType, ShortType, IntegerType, LongType, StringType, BinaryType) require(supported.contains(t) || t.isInstanceOf[DecimalType], s"truncate value type $t unsupported")
Type guard
def isTruncatable(t: DataType): Boolean = t match {
case _: DecimalType => true
case ByteType | ShortType | IntegerType | LongType | StringType | BinaryType => true
case _ => false
} Prevention
- Use days()/hours()/months() for temporal columns instead of truncate()
- Avoid float/double columns in truncate expressions; cast to DECIMAL
When it happens
Trigger: Calling iceberg.truncate(width, col) where col is TIMESTAMP, DATE, DOUBLE, FLOAT, BOOLEAN, ARRAY, STRUCT, or MAP — e.g. truncate(10, event_ts).
Common situations: Trying to truncate a timestamp column (use the days/hours/months transforms instead); truncating float/double measurements; passing nested-typed columns.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Expected column to be date, tinyint, smallint, int, bigint…
- Expected value to be date or timestamp
- Expected value to be date or timestamp
- Expected value to be timestamp
- Cannot bind: does not accept arguments
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/d8d95deaeef34a8a.
Report an issue: GitHub.
Appendix: source
Thrown at spark/v4.0/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)