{"record":{"id":"9a686d4d5d55f6b6","repo":"apache/iceberg","slug":"wrong-number-of-inputs-expected-width-and-value-9a686d","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.1/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.1/spark/src/main/java/org/apache/iceberg/spark/functions/TruncateFunction.java#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Call truncate with exactly two arguments: truncate(width, col), e.g. truncate(10, some_string_column)","If a single-argument truncation was intended, use Spark's built-in substring or a cast instead","Check DESCRIBE FUNCTION truncate to confirm the expected signature in your Iceberg/Spark version"],"exampleFix":"// before\nSELECT truncate(some_col) FROM t;\n// after\nSELECT truncate(10, some_col) FROM t;","handlingStrategy":"validation","validationCode":"// Scala/SQL: verify argument count before invoking\nif (args.length != 2) throw new IllegalArgumentException(\"truncate requires (width, value)\")","typeGuard":null,"tryCatchPattern":"try { ... } catch { case e: UnsupportedOperationException if e.getMessage.contains(\"Wrong number of inputs\") => ... }","preventionTips":["Always pass two arguments: truncate(width, col)","Check DESCRIBE FUNCTION truncate for the signature","Validate dynamically generated SQL argument counts in tests"],"tags":["spark","sql","function-binding","wrong-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"}