prestodb/presto · error · GenericInternalException

KdbTree type cannot be serialized

Error message

KdbTree type cannot be serialized

What it means

KdbTreeType represents the KDB tree hyperloglog-like structure used in approximate set building. KdbTree values live only inside the engine as object representations and have no block/serialization representation, so createBlockBuilder throws GenericInternalException("KdbTree type cannot be serialized") to fail fast if anyone tries to write a KdbTree into a Block. It signals a misuse of the type rather than corrupt data.

Source

Thrown at presto-common/src/main/java/com/facebook/presto/common/type/KdbTreeType.java:48

        super(new TypeSignature(NAME), Object.class);
    }

    @Override
    public Object getObjectValue(SqlFunctionProperties properties, Block block, int position)
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public void appendTo(Block block, int position, BlockBuilder blockBuilder)
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries, int expectedBytesPerEntry)
    {
        throw new GenericInternalException("KdbTree type cannot be serialized");
    }

    @Override
    public BlockBuilder createBlockBuilder(BlockBuilderStatus blockBuilderStatus, int expectedEntries)
    {
        throw new GenericInternalException("KdbTree type cannot be serialized");
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Do not write KdbTree values into Blocks; KdbTree is only for in-engine state — stop serializing that column.
  2. Use the intended intermediate type (e.g. setdigest via varbinary digest form) if you need to persist approximate-set state.
  3. If you need to materialize results, extract aggregates from the KdbTree via the appropriate UDFs instead of serializing the tree itself.

Example fix

// before: pageBuilder writing kdbTree value via its type
kdbTreeType.writeLong(blockBuilder, tree)
// after: avoid serializing; extract or use setdigest varbinary
blockBuilder.writeBytes(setDigestVarbinary).closeEntry()
Defensive patterns

Strategy: type-guard

Validate before calling

if (type instanceof KdbTreeType) { throw new IllegalStateException("KdbTree columns cannot be serialized"); }

Type guard

boolean isSerializableType(Type t) { return !(t instanceof KdbTreeType); }

Try / catch

try { type.createBlockBuilder(status, entries); } catch (GenericInternalException e) { /* fall back to non-serialized representation */ }

Prevention

When it happens

Trigger: Calling KdbTreeType.createBlockBuilder(status, expectedEntries) (or the expectedEntries+expectedBytesPerEntry overload, error 441) — e.g. writing a KdbTree value into a page builder or trying to persist/cast a KdbTree column.

Common situations: Attempts to serialize a state_merge/setdigest output column to storage, spill, or exchange; custom connectors/operators treating KdbTree as an ordinary scalar; casting or outputting setdigest columns to text/block form.

Related errors


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