{"record":{"id":"abb6a4218ee8a33e","repo":"apache/iceberg","slug":"wrong-number-of-inputs-expected-numbuckets-and-va-abb6a4","errorCode":null,"errorMessage":"Wrong number of inputs (expected numBuckets and value)","messagePattern":"Wrong number of inputs \\(expected numBuckets and value\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java","lineNumber":71,"sourceCode":" * <p>Example usage: {@code SELECT system.bucket(128, 'abc')}, which returns the bucket 122.\n *\n * <p>Note that for performance reasons, the given input number of buckets is not validated in the\n * implementations used in code-gen. The number of buckets must be positive to give meaningful\n * results.\n */\npublic class BucketFunction implements UnboundFunction {\n\n  private static final int NUM_BUCKETS_ORDINAL = 0;\n  private static final int VALUE_ORDINAL = 1;\n\n  private static final Set<DataType> SUPPORTED_NUM_BUCKETS_TYPES =\n      ImmutableSet.of(DataTypes.ByteType, DataTypes.ShortType, DataTypes.IntegerType);\n\n  @Override\n  @SuppressWarnings(\"checkstyle:CyclomaticComplexity\")\n  public BoundFunction bind(StructType inputType) {\n    if (inputType.size() != 2) {\n      throw new UnsupportedOperationException(\n          \"Wrong number of inputs (expected numBuckets and value)\");\n    }\n\n    StructField numBucketsField = inputType.fields()[NUM_BUCKETS_ORDINAL];\n    StructField valueField = inputType.fields()[VALUE_ORDINAL];\n\n    if (!SUPPORTED_NUM_BUCKETS_TYPES.contains(numBucketsField.dataType())) {\n      throw new UnsupportedOperationException(\n          \"Expected number of buckets to be tinyint, shortint or int\");\n    }\n\n    DataType type = valueField.dataType();\n    if (type instanceof DateType) {\n      return new BucketInt(type);\n    } else if (type instanceof ByteType\n        || type instanceof ShortType\n        || type instanceof IntegerType) {\n      return new BucketInt(DataTypes.IntegerType);","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java#L53-L89","documentation":"Arity validation in BucketFunction.bind: system.bucket was invoked with an input schema whose size is not exactly 2 (numBuckets and value). It fires at function binding, before execution; pass the bucket count as the first argument and the value as the second.","triggerScenarios":"Calling the SQL expression system.bucket(...) with one, three, or zero arguments instead of exactly two (numBuckets, value).","commonSituations":"Mistakenly passing only the value (forgetting numBuckets); passing extra column arguments; SQL generation tools emitting wrong arity.","solutions":["Pass exactly two arguments: bucket(numBuckets, expr), e.g. system.bucket(8, id)","Check your SQL/code that generates the call to ensure both numBuckets and value are supplied","For varying bucket counts, generate separate calls rather than extra arguments"],"exampleFix":"// before\nSELECT system.bucket(id) FROM t;            -- 1 arg\n// after\nSELECT system.bucket(8, id) FROM t;         -- numBuckets + value","handlingStrategy":"validation","validationCode":"if (args == null || args.length != 2) {\n  throw new IllegalArgumentException(\"bucket() requires exactly 2 arguments: (numBuckets, value)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  bound = fn.bind(structType);\n} catch (UnsupportedOperationException e) {\n  throw new IllegalArgumentException(\"Fix bucket() call arity: bucket(numBuckets, value)\", e);\n}","preventionTips":["Always pass numBuckets first, value second","Count arguments when generating bucket() calls programmatically","Check arity in SQL review tooling"],"tags":["spark","sql-function","arity","bucket-transform"],"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"}