apache/iceberg · error · java.lang.UnsupportedOperationException
Wrong number of inputs (expected width and value)
Error message
Wrong number of inputs (expected width and value)
What it means
Iceberg's truncate(x, width) Spark function requires exactly two arguments: the truncation width and the value column. Passing any other number of arguments (one, three, etc.) fails binding with this UnsupportedOperationException. Thrown during query analysis.
Source
Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java:65
* A Spark function implementation for the Iceberg truncate transform.
*
* <p>Example usage: {@code SELECT system.truncate(1, 'abc')}, which returns the String 'a'.
*
* <p>Note that for performance reasons, the given input width is not validated in the
* implementations used in code-gen. The width must remain non-negative to give meaningful results.
*/
public class TruncateFunction implements UnboundFunction {
private static final int WIDTH_ORDINAL = 0;
private static final int VALUE_ORDINAL = 1;
private static final Set<DataType> SUPPORTED_WIDTH_TYPES =
ImmutableSet.of(DataTypes.ByteType, DataTypes.ShortType, DataTypes.IntegerType);
@Override
public BoundFunction bind(StructType inputType) {
if (inputType.size() != 2) {
throw new UnsupportedOperationException("Wrong number of inputs (expected width and value)");
}
StructField widthField = inputType.fields()[WIDTH_ORDINAL];
StructField valueField = inputType.fields()[VALUE_ORDINAL];
if (!SUPPORTED_WIDTH_TYPES.contains(widthField.dataType())) {
throw new UnsupportedOperationException(
"Expected truncation width to be tinyint, shortint or int");
}
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) {View on GitHub (pinned to 86d9c8fc54)
Solutions
- Supply both arguments: truncate(value, width), e.g. truncate(name, 5).
- Remove extra arguments if more than two were passed.
- Ensure width comes as the dedicated argument, not via cast or nested call.
- Check the partition spec / SQL for the correct two-argument form.
Example fix
// before SELECT truncate(name) FROM t // after SELECT truncate(name, 5) FROM t
Defensive patterns
Strategy: validation
Validate before calling
// Spark Scala — ensure exactly two expressions are passed
val args: Seq[Column] = Seq(valueCol, lit(width))
require(args.size == 2, s"truncate() needs exactly 2 arguments (value, width), got ${args.size}") Try / catch
try {
df.select(expr("truncate(value_col, 5)"))
} catch {
case e: UnsupportedOperationException if e.getMessage.contains("Wrong number of inputs") =>
throw new IllegalArgumentException("truncate() requires exactly two arguments: truncate(value, width)", e)
} Prevention
- Always pass both value and width: truncate(col, n)
- Don't confuse Spark's built-in string functions with Iceberg's truncate transform
- Validate generated SQL templates emit both arguments
- Check partition specs use truncate(value, width) ordering
When it happens
Trigger: Calling truncate(value) with only the value; truncate(a, b, c) with three arguments; or misordering so an argument is missing, e.g. truncate(5) in a partition spec.
Common situations: Copy-pasted partition specs missing the width argument; confusing Spark's built-in truncate-like string functions with Iceberg's truncate(value, width); refactoring that dropped an argument.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Wrong number of inputs (expected value)
- Wrong number of inputs (expected width and value)
- Wrong number of inputs (expected value)
- Wrong number of inputs (expected numBuckets and value)
- Cannot bind: %s does not accept arguments
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/4ea052c433f1e58e.
Report an issue: GitHub.