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
Iceberg's truncate(value, width) function supports value columns of tinyint, smallint, int, bigint, decimal, string, or binary only. Value columns of any other type (double, float, boolean, date, timestamp, complex types) have no truncation implementation, so bind() throws this UnsupportedOperationException during query analysis.
Solutions
- Cast the value to a supported type, e.g. truncate(CAST(d AS DECIMAL(10,4)), 2) for doubles.
- For temporal truncation use the dedicated functions: years(), months(), days(), hours().
- Pick a supported column (numeric, decimal, string, binary) for the partition transform.
- For doubles, consider scaling to bigint: truncate(CAST(d * 100 AS BIGINT), 1).
Example fix
// before SELECT truncate(price, 2) FROM t -- price is DOUBLE // after SELECT truncate(CAST(price AS DECIMAL(10,2)), 2) FROM t
Defensive patterns
Strategy: validation
Validate before calling
// Spark Scala
val dt = df.schema("value_col").dataType.catalogString.toLowerCase
val supported = Set("tinyint","smallint","int","bigint","decimal","string","binary")
require(supported.exists(s => dt.startsWith(s)), s"truncate() does not support value type: $dt") Type guard
def isTruncatableType(dt: org.apache.spark.sql.types.DataType): Boolean = dt match {
case _: org.apache.spark.sql.types.DecimalType => true
case t => Set(
org.apache.spark.sql.types.ByteType,
org.apache.spark.sql.types.ShortType,
org.apache.spark.sql.types.IntegerType,
org.apache.spark.sql.types.LongType,
org.apache.spark.sql.types.StringType,
org.apache.spark.sql.types.BinaryType).contains(t)
} Try / catch
try {
df.select(expr("truncate(value_col, 5)"))
} catch {
case e: UnsupportedOperationException if e.getMessage.contains("truncation col") =>
throw new IllegalArgumentException("truncate() value column type unsupported; cast or use days()/hours() for temporal", e)
} Prevention
- Never truncate float/double — cast to DECIMAL or scale to BIGINT first
- Use years()/months()/days()/hours() for date/timestamp truncation, not truncate()
- Inspect column types with printSchema before building partition transforms
- Validate partition specs against supported truncation types at table creation
When it happens
Trigger: Calling truncate(double_col, 2), truncate(bool_col, 1), truncate(ts_col, 10), or truncating struct/array/map columns.
Common situations: Truncating floats/doubles for bucket-like partitioning; attempting time truncation with truncate() instead of the dedicated years/months/days/hours functions; schema type drift to unsupported types.
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
- Expected column to be date, tinyint, smallint, int, bigint…
- Expected number of buckets to be tinyint, shortint or int
- Expected truncation width to be tinyint, shortint or int
- Cannot bind: does not accept arguments
- Cannot bind: does not accept arguments
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/da18cdb4417dce20.
Report an issue: GitHub.
Appendix: source
Thrown at spark/v4.2/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)