Skip to content

HIVE-30271: Iceberg: Compress split payloads so delete-heavy scans stay under the split serialization threshold - #6973

Open
deniskuzZ wants to merge 1 commit into
apache:masterfrom
deniskuzZ:HIVE-30271
Open

deniskuzZ wants to merge 1 commit into
apache:masterfrom
deniskuzZ:HIVE-30271

Conversation

@deniskuzZ

@deniskuzZ deniskuzZ commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

IcebergSplit compresses its payload with the codec named by the new hive.iceberg.split.compression.codec
(snappy by default, zstd or none). The payload is [codec id][stored length][stored bytes]; the task group is
still Java-serialized as before, only the bytes are compressed. The reader takes the codec from the payload, so only the
split generator reads the setting.

Why are the changes needed?

HiveSplitGenerator keeps split payloads in the Tez AM until their total reaches
hive.tez.input.fs.serialization.threshold (256 MiB); every split after that is written to the staging file system as
a file of its own and read back by its task. IcebergSplit serializes each task group as a separate stream, so every split
repeats the class descriptors and the schema and partition spec of its tasks: ~5.5 KB per split, of which only
264-568 bytes are unique to it.

On a 1TRC table with ~49.6k splits the scan before the DML stays just under the threshold (258 MB in memory, events in
0.1 s); the scans after a V2 / V3 merge-on-read DML go over it (70 / 51 MB written to the file system) and split
generation grows from ~3 s to ~18 / ~12 s (cluster table below).

Does this PR introduce any user-facing change?

A new configuration, hive.iceberg.split.compression.codec. Split payloads are smaller; a split written by another
Hive version cannot be read (AM and tasks run the same build).

How was this patch tested?

TestIcebergSplit: round trip with every codec on a task group with position deletes (locations, start/length, sequence
numbers), compression smaller than none, a split without configuration using the default, an unknown codec id failing.
TestIcebergInputFormats, TestInputFormatReaderDeletes, TestHiveIcebergSelects, TestHiveIcebergDeletionVectors and
TestHiveIcebergVectorization pass with the snappy default (the Tez local runs serialize the split events).
Per split, measured locally on the 1TRC table layout: snappy 1.75-1.9x smaller (12x for splits carrying 300
partition-scoped delete files) at ~5 us of AM time per split; zstd 2.1-2.35x (41x) at ~12-15 us.

On a 40-node LLAP cluster with that table, split generation (Map 1 initialization in the Tez AM) and split payloads,
without -> with this patch (snappy):

scan splits split generation payload: in memory + staging FS
before the DML 43,511 3.1-3.5 s -> 3.3-3.7 s 258 MB + 0 -> 150 MB + 0
after a V2 DML 49,628 17.5-18.0 s -> 3.9-4.2 s 268 MB + 70 MB -> 183 MB + 0
after a V3 DML 49,628 11.5-12.2 s -> 3.7-3.8 s 268 MB + 51 MB -> 178 MB + 0
~320 position delete files per data file 5,428 13.1-13.4 s -> 7.1-7.3 s 268 MB + 545 MB -> 98 MB + 0

No split is written to the staging file system any more. Compression costs ~5 us of AM time per split (measured
locally), ~0.2 s for the 43.5k splits of the scan before the DML. Most of what remains on the delete-heavy scan is the
Java serialization of its task groups (~6 s for 1.75M delete file references), which this patch does not change. Query
results are identical to those of a build without the patch.

@sonarqubecloud

Copy link
Copy Markdown

<artifactId>hive-exec</artifactId>
</dependency>
<dependency>
<!-- the codecs of the split payloads; zstd-jni comes with ORC, and hive-exec bundles it -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but snappy is not shaded in hive-exec , zstd is part of sharding here https://github.com/apache/hive/blob/master/ql/pom.xml#L1097-L1161

its not a big problem as tez project has direct dependency on snappy unless snappy version has incompatiblity but better to add in ql/pom.xml or we can leverage aircompressor which is already shaded like trino uses but artifactId (import) needs to be changed then.
WDYT?


@Override
byte[] decompress(byte[] stored) {
return Zstd.decompress(stored, (int) Zstd.getFrameContentSize(stored));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zstd.getFrameContentSize(stored)); can return negative as well as per its javadoc:

/**
     * Return the original size of a compressed buffer (if known)
     *
     * @param src the compressed buffer
     * @return the number of bytes of the original buffer
     *         0 if the original size is not known,
     *         negative if there is an error decoding the frame header
     */

and returnign -ve in decompress can throw exception

public byte[] decompress(byte[] src, int srcOffset, int srcSize, int originalSize) throws ZstdException {
        if (originalSize < 0) {
            throw new ZstdException(Zstd.errGeneric(), "Original size should not be negative");
        }

this.id = (byte) id;
}

static Codec of(byte id) throws IOException {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a switch can be used as codec are fixed rather than for loop?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants