{"record":{"id":"4ea052c433f1e58e","repo":"apache/iceberg","slug":"wrong-number-of-inputs-expected-width-and-value-4ea052","errorCode":null,"errorMessage":"Wrong number of inputs (expected width and value)","messagePattern":"Wrong number of inputs \\(expected width and value\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/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/v4.2/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT truncate(name) FROM t\n// after\nSELECT truncate(name, 5) FROM t","handlingStrategy":"validation","validationCode":"// Spark Scala — ensure exactly two expressions are passed\nval args: Seq[Column] = Seq(valueCol, lit(width))\nrequire(args.size == 2, s\"truncate() needs exactly 2 arguments (value, width), got ${args.size}\")","typeGuard":null,"tryCatchPattern":"try {\n  df.select(expr(\"truncate(value_col, 5)\"))\n} catch {\n  case e: UnsupportedOperationException if e.getMessage.contains(\"Wrong number of inputs\") =>\n    throw new IllegalArgumentException(\"truncate() requires exactly two arguments: truncate(value, width)\", e)\n}","preventionTips":["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"],"tags":["spark","sql-function","arity","argument-count"],"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"}