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

TruncateFunction is an Iceberg Spark unbound function requiring exactly two inputs: a truncation width and the value to truncate. When bind() sees a StructType whose field count is not 2, it throws this UnsupportedOperationException because the call shape is unambiguous and cannot be resolved to any bound overload.

Source

Thrown at spark/v4.1/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

  1. Call truncate with exactly two arguments: truncate(width, col), e.g. truncate(10, some_string_column)
  2. If a single-argument truncation was intended, use Spark's built-in substring or a cast instead
  3. Check DESCRIBE FUNCTION truncate to confirm the expected signature in your Iceberg/Spark version

Example fix

// before
SELECT truncate(some_col) FROM t;
// after
SELECT truncate(10, some_col) FROM t;
Defensive patterns

Strategy: validation

Validate before calling

// Scala/SQL: verify argument count before invoking
if (args.length != 2) throw new IllegalArgumentException("truncate requires (width, value)")

Try / catch

try { ... } catch { case e: UnsupportedOperationException if e.getMessage.contains("Wrong number of inputs") => ... }

Prevention

When it happens

Trigger: Calling truncate('col') with one argument, or truncate('col', w, extra) with three or more arguments, in a Spark SQL query that resolves to the Iceberg truncate function.

Common situations: Confusing Spark's built-in truncate-like string functions (single-arg substring forms) with Iceberg's truncate(width, col) signature; typos or dynamically generated SQL that omits the width 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


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