{"record":{"id":"a78409608763bfe2","repo":"apache/iceberg","slug":"wrong-number-of-inputs-expected-width-and-value","errorCode":null,"errorMessage":"Wrong number of inputs (expected width and value)","messagePattern":"Wrong number of inputs \\(expected width and value\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java","lineNumber":65,"sourceCode":" * A Spark function implementation for the Iceberg truncate transform.\n *\n * <p>Example usage: {@code SELECT system.truncate(1, 'abc')}, which returns the String 'a'.\n *\n * <p>Note that for performance reasons, the given input width is not validated in the\n * implementations used in code-gen. The width must remain non-negative to give meaningful results.\n */\npublic class TruncateFunction implements UnboundFunction {\n\n  private static final int WIDTH_ORDINAL = 0;\n  private static final int VALUE_ORDINAL = 1;\n\n  private static final Set<DataType> SUPPORTED_WIDTH_TYPES =\n      ImmutableSet.of(DataTypes.ByteType, DataTypes.ShortType, DataTypes.IntegerType);\n\n  @Override\n  public BoundFunction bind(StructType inputType) {\n    if (inputType.size() != 2) {\n      throw new UnsupportedOperationException(\"Wrong number of inputs (expected width and value)\");\n    }\n\n    StructField widthField = inputType.fields()[WIDTH_ORDINAL];\n    StructField valueField = inputType.fields()[VALUE_ORDINAL];\n\n    if (!SUPPORTED_WIDTH_TYPES.contains(widthField.dataType())) {\n      throw new UnsupportedOperationException(\n          \"Expected truncation width to be tinyint, shortint or int\");\n    }\n\n    DataType valueType = valueField.dataType();\n    if (valueType instanceof ByteType) {\n      return new TruncateTinyInt();\n    } else if (valueType instanceof ShortType) {\n      return new TruncateSmallInt();\n    } else if (valueType instanceof IntegerType) {\n      return new TruncateInt();\n    } else if (valueType instanceof LongType) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nspark.sql(\"SELECT truncate(s) FROM t\")\n// after\nspark.sql(\"SELECT truncate(10, s) FROM t\")","handlingStrategy":"validation","validationCode":"if (args.length != 2) throw new IllegalArgumentException(\"truncate expects exactly 2 arguments: (width, value)\");","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["spark","sql-function","arity","unsupported-operation"],"backgroundTag":"missing-required-argument","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}