apache/iceberg · error · UnsupportedOperationException
Wrong number of inputs (expected width and value)
Error message
Wrong number of inputs (expected width and value)
What it means
Iceberg's Spark `truncate` bound function requires exactly two arguments: a truncation width and a value column. The unbound function's `bind` throws this UnsupportedOperationException when the input StructType does not contain exactly 2 fields. It rejects a function invocation with the wrong arity before any binding proceeds.
Source
Thrown at spark/v3.5/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
- Pass exactly two arguments: `truncate(width, value)`, e.g. SELECT truncate(10, s) FROM t.
- If you intended a default width, supply the explicit width instead of relying on defaults.
- If this comes from generated SQL, fix the generator to emit width and value; confirm the signature with DESCRIBE FUNCTION truncate.
- Use Spark's native `truncate` if a 1-arg variant is needed rather than Iceberg's function.
Example fix
// before
spark.sql("SELECT truncate(s) FROM t")
// after
spark.sql("SELECT truncate(10, s) FROM t") Defensive patterns
Strategy: validation
Validate before calling
if (args.length != 2) throw new IllegalArgumentException("truncate expects exactly 2 arguments: (width, value)"); Try / catch
try { spark.sql("SELECT truncate(10, s) FROM t"); } catch (Exception e) { if (e.getMessage() != null && e.getMessage().contains("Wrong number of inputs")) { /* fix arity */ } throw e; } Prevention
- Always pass both width and value to Iceberg's truncate function.
- Check DESCRIBE FUNCTION EXTENDED truncate for the expected signature.
- Differentiate Iceberg's 2-arg truncate from Spark's native overloads.
When it happens
Trigger: Calling the `truncate` SQL function with not exactly 2 arguments, e.g. `truncate(col)` or `truncate(w, v, extra)`, or invoking `TruncateFunction.bind()` programmatically with a StructType whose size != 2.
Common situations: Typos in SQL (missing second argument), SQL generators emitting wrong arity, or migration from Spark's built-in 1-arg truncate overloads to Iceberg's truncate which requires both width and value.
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)
- Expected truncation col to be tinyint, shortint, int, bigint
- Wrong number of inputs (expected numBuckets and value)
- Cannot bind: %s does not accept arguments
- Cannot bind: ${name()} does not accept arguments
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/a78409608763bfe2.
Report an issue: GitHub.