{"record":{"id":"ad5a76074a5805ba","repo":"apache/iceberg","slug":"expected-column-to-be-date-tinyint-smallint-int-ad5a76","errorCode":null,"errorMessage":"Expected column to be date, tinyint, smallint, int, bigint, decimal, timestamp, string, or binary","messagePattern":"Expected column to be date, tinyint, smallint, int, bigint, decimal, timestamp, string, or binary","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java","lineNumber":103,"sourceCode":"      return new BucketInt(type);\n    } else if (type instanceof ByteType\n        || type instanceof ShortType\n        || type instanceof IntegerType) {\n      return new BucketInt(DataTypes.IntegerType);\n    } else if (type instanceof LongType) {\n      return new BucketLong(type);\n    } else if (type instanceof TimestampType) {\n      return new BucketLong(type);\n    } else if (type instanceof TimestampNTZType) {\n      return new BucketLong(type);\n    } else if (type instanceof DecimalType) {\n      return new BucketDecimal(type);\n    } else if (type instanceof StringType) {\n      return new BucketString();\n    } else if (type instanceof BinaryType) {\n      return new BucketBinary();\n    } else {\n      throw new UnsupportedOperationException(\n          \"Expected column to be date, tinyint, smallint, int, bigint, decimal, timestamp, string, or binary\");\n    }\n  }\n\n  @Override\n  public String description() {\n    return name()\n        + \"(numBuckets, col) - Call Iceberg's bucket transform\\n\"\n        + \"  numBuckets :: number of buckets to divide the rows into, e.g. bucket(100, 34) -> 79 (must be a tinyint, smallint, or int)\\n\"\n        + \"  col :: column to bucket (must be a date, integer, long, timestamp, decimal, string, or binary)\";\n  }\n\n  @Override\n  public String name() {\n    return \"bucket\";\n  }\n\n  public abstract static class BucketBase extends BaseScalarFunction<Integer>","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java#L85-L121","documentation":"Type validation in BucketFunction.bind: the second argument (the value to hash) is not one of the hashable types (date, tinyint, smallint, int, bigint, decimal, timestamp, string, binary). The %s names the value field; note codegen does not re-validate, so the bound type must truly be hashable.","triggerScenarios":"Calling system.bucket(n, <column>) where the column is a float, double, boolean, struct, array, map, or another unsupported type.","commonSituations":"Bucketing float/double columns (e.g. price); bucketing nested types; bucketing boolean flags; tables where the transform column type evolved to an unsupported type.","solutions":["Bucket a supported column instead (int/bigint key, string, etc.)","Cast the value to a supported type before bucketing, e.g. system.bucket(8, CAST(flag AS INT))","For float/double keys, round/encode to decimal or bigint first: system.bucket(8, CAST(x AS DECIMAL(18,6)))"],"exampleFix":"// before\nSELECT system.bucket(8, is_active) FROM t;   -- boolean unsupported\n// after\nSELECT system.bucket(8, CAST(is_active AS INT)) FROM t;","handlingStrategy":"type-guard","validationCode":"java.util.Set<DataType> ok = Set.of(DateType, ByteType, ShortType, IntegerType, LongType, DecimalType.USER_DEFAULT, TimestampType, StringType, BinaryType);\nif (!ok.contains(valueCol.dataType())) throw new IllegalArgumentException(\"Unsupported bucket value type: \" + valueCol.dataType());","typeGuard":"boolean bucketable(DataType t) {\n  return t instanceof DateType || t instanceof ByteType || t instanceof ShortType || t instanceof IntegerType\n    || t instanceof LongType || t instanceof DecimalType || t instanceof TimestampType\n    || t instanceof StringType || t instanceof BinaryType;\n}","tryCatchPattern":"try {\n  bound = bucketFn.bind(inputType);\n} catch (UnsupportedOperationException e) {\n  throw new IllegalArgumentException(\"Cast the value column to a bucketable type\", e);\n}","preventionTips":["Avoid bucketing float/double/boolean/nested columns","Cast values to decimal/int/string before bucketing","Check partition transform compatibility when defining table specs"],"tags":["spark","sql-function","bucket-transform","type-mismatch"],"backgroundTag":"unsupported-enum-value","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"}