Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Paimon CompressOptions

From Leeroopedia


Knowledge Sources
Domains Compression, Configuration
Last Updated 2026-02-08 00:00 GMT

Overview

CompressOptions is a serializable configuration class that encapsulates compression settings for Apache Paimon data files.

Description

The CompressOptions class provides a simple, immutable container for compression configuration in Paimon. It specifies two key parameters: the compression algorithm to use and the compression level for zstd compression.

Paimon supports various compression algorithms for data files, and this class provides a type-safe way to pass these settings throughout the system. The zstd (Zstandard) compression algorithm supports configurable compression levels, allowing users to trade off between compression ratio and speed. Level 1 provides fast compression with reasonable compression ratios, while higher levels increase compression at the cost of more CPU time.

The class is immutable and implements proper equals, hashCode, and toString methods, making it safe to use as a configuration parameter in distributed systems. A factory method provides default options (zstd at level 1), which offers a good balance between performance and compression for most use cases.

Usage

Use CompressOptions when configuring table properties or file write operations that require compression settings. This class is typically constructed from user-provided configuration options and passed to file writers and format handlers that need to compress data before writing to storage.

Code Reference

Source Location

Signature

public class CompressOptions implements Serializable {
    private final String compress;
    private final int zstdLevel;

    public CompressOptions(String compress, int zstdLevel)
    public String compress()
    public int zstdLevel()
    public static CompressOptions defaultOptions()

    @Override public boolean equals(Object o)
    @Override public int hashCode()
    @Override public String toString()
}

Import

import org.apache.paimon.compression.CompressOptions;

I/O Contract

Inputs

Name Type Required Description
compress String Yes Compression algorithm name (e.g., "zstd", "lz4", "snappy", "gzip", "none")
zstdLevel int Yes Compression level for zstd algorithm (typically 1-22)

Outputs

Name Type Description
compress String The configured compression algorithm
zstdLevel int The configured zstd compression level

Usage Examples

// Using default compression options
CompressOptions defaultOpts = CompressOptions.defaultOptions();
System.out.println(defaultOpts.compress()); // "zstd"
System.out.println(defaultOpts.zstdLevel()); // 1

// Custom compression with higher level for better compression
CompressOptions highCompress = new CompressOptions("zstd", 9);

// Using different compression algorithm
CompressOptions lz4Opts = new CompressOptions("lz4", 1);
CompressOptions snappyOpts = new CompressOptions("snappy", 1);

// No compression
CompressOptions noCompress = new CompressOptions("none", 1);

// Applying compression options to a file writer
FileWriter writer = new FileWriter(outputPath, schema, compressOptions);

// Building from table configuration
Options tableOptions = new Options(tableProperties);
String algorithm = tableOptions.get("file.compression");
int level = tableOptions.get("file.compression.zstd-level");
CompressOptions opts = new CompressOptions(algorithm, level);

// Comparing compression options
CompressOptions opts1 = new CompressOptions("zstd", 1);
CompressOptions opts2 = new CompressOptions("zstd", 1);
boolean same = opts1.equals(opts2); // true

// Using in format configuration
ParquetWriterFactory writerFactory = new ParquetWriterFactory(
    schema,
    compressOptions,
    writeProperties
);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment