prestodb/presto · error · UnsupportedOperationException

unknown java type

Error message

unknown java type

What it means

While adapting rows for bucket filtering, HiveBucketAdapterRecordCursor reads each column via delegate.getXxx and stores it in scratch[]. The JavaType of a column must be one of the supported boxed/object types (Boolean, Long, Double, Slice, Block). Any other JavaType hits the final else and throws UnsupportedOperationException "unknown java type".

Source

Thrown at presto-hive/src/main/java/com/facebook/presto/hive/HiveBucketAdapterRecordCursor.java:124

                }
                Class<?> javaType = javaTypeList.get(i);
                if (javaType == boolean.class) {
                    scratch[i] = delegate.getBoolean(index);
                }
                else if (javaType == long.class) {
                    scratch[i] = delegate.getLong(index);
                }
                else if (javaType == double.class) {
                    scratch[i] = delegate.getDouble(index);
                }
                else if (javaType == Slice.class) {
                    scratch[i] = delegate.getSlice(index);
                }
                else if (javaType == Block.class) {
                    scratch[i] = (Block) delegate.getObject(index);
                }
                else {
                    throw new UnsupportedOperationException("unknown java type");
                }
            }
            int bucket = HiveBucketing.getHiveBucket(tableBucketCount, typeInfoList, scratch, useLegacyTimestampBucketing);
            if ((bucket - bucketToKeep) % partitionBucketCount != 0) {
                throw new PrestoException(HIVE_INVALID_BUCKET_FILES, format(
                        "A row that is supposed to be in bucket %s is encountered. Only rows in bucket %s (modulo %s) are expected",
                        bucket, bucketToKeep % partitionBucketCount, partitionBucketCount));
            }
            if (bucket == bucketToKeep) {
                return true;
            }
        }
    }

    @Override
    public boolean getBoolean(int field)
    {
        return delegate.getBoolean(field);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Upgrade Presto to a version where the bucket adapter handles the column's JavaType (recent releases cover more types).
  2. Identify the offending column type and, if feasible, avoid the bucket adapter by making partition files use the table's bucket count (rewrite data with the correct bucketing) or by reading from a non-bucketed copy.
  3. If a custom type/plugin is involved, ensure its Type maps to a supported JavaType (Boolean, Long, Double, Slice, Block).
  4. Work around by casting the column in the query or excluding it if the failure is type-mapping specific.

Example fix

// before: DATE column surfaces unsupported java type in adapter
// after: use a Presto build that maps DATE to long in the adapter, or rewrite the table without mismatched bucketing:
CREATE TABLE orders_fixed WITH (bucketed_by = ARRAY['id'], bucket_count = 32) AS SELECT * FROM orders;
Defensive patterns

Strategy: validation

Validate before calling

// pre-check column java types against the adapter's supported set
Set<Class<?>> supported = Set.of(Boolean.class, Long.class, Double.class, Slice.class, Block.class);
for (HiveColumnHandle col : columns) {
    if (!supported.contains(col.getType().getJavaType())) {
        throw new IllegalStateException("Unsupported java type in bucket adapter: " + col.getType());
    }
}

Type guard

boolean bucketAdapterSupported(Type type) {
    Class<?> jt = type.getJavaType();
    return jt == Boolean.class || jt == Long.class || jt == Double.class
        || jt == Slice.class || jt == Block.class;
}

Try / catch

try {
    while (cursor.advanceNextPosition()) { /* consume */ }
} catch (UnsupportedOperationException e) {
    if ("unknown java type".equals(e.getMessage())) {
        throw new IllegalStateException("Table has a column type the bucket adapter cannot read; rewrite or upgrade");
    }
    throw e;
}

Prevention

When it happens

Trigger: A column in the table's column handle list has a JavaType not handled by the switch — e.g. a type with an unusual Java binding (some Date/Timestamp/Json/varbinary mappings or custom types) — encountered during advanceNextPosition on a bucketed table with mismatched bucket counts.

Common situations: Tables with DATE/TIMESTAMP or other non-primitive columns read through the bucket adapter when partition bucket count differs from table bucket count; Presto version where HiveType-to-JavaType translation produces a binding not covered here; custom type plugins adding new Java types.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/87b115ce730ae8e7. Report an issue: GitHub.