{"record":{"id":"e569a478e0008442","repo":"apache/iceberg","slug":"wrong-number-of-inputs-expected-width-and-value-e569a4","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/v4.0/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.0/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java#L47-L83","documentation":"Iceberg's truncate() function requires exactly two inputs: a truncation width and the value column. bind() checks inputType.size() == 2 and throws UnsupportedOperationException when the argument count differs (0, 1, 3+ arguments).","triggerScenarios":"Calling iceberg.truncate(col) with only the value (forgetting width); calling iceberg.truncate(width, col, extra); generated SQL that dropped the width argument.","commonSituations":"Confusing truncate() with Spark's built-in truncate string function; partially edited SQL; template engines omitting an optional parameter rendered as fewer args.","solutions":["Supply both arguments: truncate(10, col).","For strings, the width is character count: truncate(5, name); for binary/int types it is the byte width.","Count the arguments in generated SQL and fix the template."],"exampleFix":"// before\nSELECT iceberg.truncate(name) FROM t;\n// after\nSELECT iceberg.truncate(10, name) FROM t;","handlingStrategy":"validation","validationCode":"-- truncate always takes exactly 2 args: width, value\nSELECT iceberg.truncate(10, col) FROM t;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't confuse iceberg.truncate(width, col) with Spark's built-in truncate-like functions","In templated SQL, assert the parameter list length before substitution"],"tags":["spark","sql-function-binding","argument-count"],"backgroundTag":"invalid-argument-count","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}