{"record":{"id":"c873d2dab251dd2e","repo":"apache/iceberg","slug":"wrong-number-of-inputs-expected-value-c873d2","errorCode":null,"errorMessage":"Wrong number of inputs (expected value)","messagePattern":"Wrong number of inputs \\(expected value\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/UnaryUnboundFunction.java","lineNumber":39,"sourceCode":"import org.apache.spark.sql.connector.catalog.functions.BoundFunction;\nimport org.apache.spark.sql.connector.catalog.functions.UnboundFunction;\nimport org.apache.spark.sql.types.DataType;\nimport org.apache.spark.sql.types.StructType;\n\n/** An unbound function that accepts only one argument */\nabstract class UnaryUnboundFunction implements UnboundFunction {\n\n  @Override\n  public BoundFunction bind(StructType inputType) {\n    DataType valueType = valueType(inputType);\n    return doBind(valueType);\n  }\n\n  protected abstract BoundFunction doBind(DataType valueType);\n\n  private DataType valueType(StructType inputType) {\n    if (inputType.size() != 1) {\n      throw new UnsupportedOperationException(\"Wrong number of inputs (expected value)\");\n    }\n\n    return inputType.fields()[0].dataType();\n  }\n}\n","sourceCodeStart":21,"sourceCodeEnd":45,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/UnaryUnboundFunction.java#L21-L45","documentation":"UnaryUnboundFunction is the base class for Iceberg Spark functions that take exactly one argument (e.g. years, months, days, bucket-less unary transforms). Its private valueType() throws this UnsupportedOperationException when the input StructType does not have exactly one field.","triggerScenarios":"Calling a unary Iceberg function like years('2023-01-01') with zero arguments, or with two or more arguments.","commonSituations":"Confusing Iceberg's partition-transform functions (years/months/days/hours take one value) with multi-arg date functions; SQL templating bugs that duplicate or drop an argument.","solutions":["Call the function with exactly one argument, e.g. days(event_ts)","If you intended a two-argument function (like date_add), use the correct Spark function instead","Run DESCRIBE FUNCTION <name> to confirm the signature"],"exampleFix":"// before\nSELECT years('2023-01-01', '2024-01-01');\n// after\nSELECT years(TIMESTAMP '2023-01-01 00:00:00');","handlingStrategy":"validation","validationCode":"if (args.length != 1) throw new IllegalArgumentException(s\"$fnName expects exactly one argument\")","typeGuard":null,"tryCatchPattern":"try { ... } catch { case e: UnsupportedOperationException if e.getMessage.contains(\"Wrong number of inputs\") => ... }","preventionTips":["Iceberg transform functions years/months/days/hours are unary — pass one value","Compare against Spark built-ins with different arities","Unit-test generated SQL for these calls"],"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"}