{"record":{"id":"1770dc60738ef00e","repo":"apache/iceberg","slug":"expected-column-to-be-date-tinyint-smallint-int","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/v3.5/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java","lineNumber":95,"sourceCode":"    }\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);\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() {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java#L77-L113","documentation":"The bucket function's value argument must be one of the types Iceberg's murmur3 bucket transform supports: date, tinyint, smallint, int, bigint, decimal, timestamp (and timestamp_ntz), string, or binary. Any other value type fails bind.","triggerScenarios":"Calling system.bucket(n, value) where value is e.g. float, double, boolean, array, struct, or map — types that have no bucket transform in Iceberg.","commonSituations":"Bucketing floating point columns (Iceberg spec does not define bucket for float/double); bucketing complex types; bucketing a timestamp column typed differently than expected after casts.","solutions":["Cast the value to a supported type, e.g. CAST(double_col AS DECIMAL(38,10)) or CAST(col AS STRING) before bucketing","Pick a different partition/transform for unsupported types (e.g. truncate for strings, identity for booleans if needed)","Remove the column from the bucket expression and use a supported column instead"],"exampleFix":"// before\nspark.sql(\"SELECT system.bucket(8, double_col) FROM tbl\")\n// after\nspark.sql(\"SELECT system.bucket(8, CAST(double_col AS DECIMAL(38,10))) FROM tbl\")","handlingStrategy":"type-guard","validationCode":"// Only bucket these types\nSet<DataType> ok = Set.of(DateType, ByteType, ShortType, IntegerType, LongType,\n    DecimalType, TimestampType, TimestampNTZType, StringType, BinaryType);\n// check valueField.dataType() instanceof ok before calling system.bucket","typeGuard":"boolean bucketable(DataType t) { return t instanceof DateType || t instanceof ByteType || t instanceof ShortType\n  || t instanceof IntegerType || t instanceof LongType || t instanceof DecimalType\n  || t instanceof TimestampType || t instanceof TimestampNTZType\n  || t instanceof StringType || t instanceof BinaryType; }","tryCatchPattern":null,"preventionTips":["Do not bucket float/double columns; cast to decimal first","Do not bucket complex types (array/map/struct/boolean)","Match bucket expressions to Iceberg partition-transform-supported types"],"tags":["spark","sql-functions","bucketing","unsupported-type"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}