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 ConfigOptions

From Leeroopedia


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

Overview

ConfigOptions is a builder factory class for creating strongly-typed ConfigOption instances in Apache Paimon.

Description

ConfigOptions provides a fluent API for constructing ConfigOption objects with compile-time type safety. It implements the builder pattern, starting with a key specification and progressively adding type information, default values, and metadata through chained method calls.

The class defines two nested builder classes: OptionBuilder and TypedConfigOptionBuilder. OptionBuilder is the entry point created by the static `key()` method. It provides type specification methods (stringType, intType, booleanType, etc.) that return a TypedConfigOptionBuilder parameterized with the appropriate type. The TypedConfigOptionBuilder then offers methods to set default values or indicate no default value is needed.

ConfigOptions supports a comprehensive set of types including all Java primitives and their wrappers (Boolean, Integer, Long, Float, Double), String, Duration for time-based values, MemorySize for memory specifications, arbitrary Enum types, and Map<String, String> for key-value properties. This rich type system enables precise configuration specifications that match domain requirements.

The builder pattern ensures that ConfigOption instances are always constructed in a valid state. Type information must be specified before default values, preventing type mismatches at compile time. The final ConfigOption object is immutable, making it safe for concurrent access and use as a constant.

The class includes deprecated methods for backward compatibility that bypass the type specification step, but these are discouraged in favor of the explicit type-first approach.

Usage

Use ConfigOptions.key() as the starting point when defining configuration parameters in your Paimon modules. Follow the fluent chain by specifying the type, then either a default value or noDefaultValue(), and optionally add fallback keys and descriptions. The resulting ConfigOption constant can be used throughout your code for type-safe configuration access.

Code Reference

Source Location

Signature

@Public
public class ConfigOptions {
    public static OptionBuilder key(String key)

    public static final class OptionBuilder {
        public TypedConfigOptionBuilder<Boolean> booleanType()
        public TypedConfigOptionBuilder<Integer> intType()
        public TypedConfigOptionBuilder<Long> longType()
        public TypedConfigOptionBuilder<Float> floatType()
        public TypedConfigOptionBuilder<Double> doubleType()
        public TypedConfigOptionBuilder<String> stringType()
        public TypedConfigOptionBuilder<Duration> durationType()
        public TypedConfigOptionBuilder<MemorySize> memoryType()
        public <T extends Enum<T>> TypedConfigOptionBuilder<T> enumType(Class<T> enumClass)
        public TypedConfigOptionBuilder<Map<String, String>> mapType()

        @Deprecated public <T> ConfigOption<T> defaultValue(T value)
        @Deprecated public ConfigOption<String> noDefaultValue()
    }

    public static class TypedConfigOptionBuilder<T> {
        public ConfigOption<T> defaultValue(T value)
        public ConfigOption<T> noDefaultValue()
    }
}

Import

import org.apache.paimon.options.ConfigOptions;

I/O Contract

Inputs

Name Type Required Description
key String Yes Configuration key string
enumClass Class<T> For enum type Enum class for enumType() method
value T For default value Default value matching the specified type

Outputs

Name Type Description
optionBuilder OptionBuilder Builder for specifying option type
typedBuilder TypedConfigOptionBuilder<T> Typed builder for setting default value
configOption ConfigOption<T> Final immutable configuration option

Usage Examples

// String option with default value
ConfigOption<String> WAREHOUSE = ConfigOptions
    .key("warehouse")
    .stringType()
    .defaultValue("/tmp/paimon")
    .withDescription("Warehouse root path");

// Integer option with no default (required)
ConfigOption<Integer> PORT = ConfigOptions
    .key("server.port")
    .intType()
    .noDefaultValue()
    .withDescription("Server port number");

// Boolean option with default
ConfigOption<Boolean> ENABLED = ConfigOptions
    .key("feature.enabled")
    .booleanType()
    .defaultValue(false)
    .withDescription("Whether feature is enabled");

// Long option with fallback keys
ConfigOption<Long> MAX_SIZE = ConfigOptions
    .key("cache.max-size")
    .longType()
    .defaultValue(1000000L)
    .withFallbackKeys("cache.size", "old.cache-max-size")
    .withDescription("Maximum cache size");

// Duration option
ConfigOption<Duration> TIMEOUT = ConfigOptions
    .key("operation.timeout")
    .durationType()
    .defaultValue(Duration.ofMinutes(5))
    .withDescription("Operation timeout");

// Memory size option
ConfigOption<MemorySize> MEMORY = ConfigOptions
    .key("buffer.memory")
    .memoryType()
    .defaultValue(MemorySize.ofMebiBytes(128))
    .withDescription("Buffer memory allocation");

// Enum option
public enum CompressionType { NONE, GZIP, SNAPPY, ZSTD }

ConfigOption<CompressionType> COMPRESSION = ConfigOptions
    .key("file.compression")
    .enumType(CompressionType.class)
    .defaultValue(CompressionType.ZSTD)
    .withDescription("File compression algorithm");

// Map option for properties
ConfigOption<Map<String, String>> PROPERTIES = ConfigOptions
    .key("custom.properties")
    .mapType()
    .noDefaultValue()
    .withDescription("Custom configuration properties");

// Float and Double options
ConfigOption<Float> SAMPLE_RATE = ConfigOptions
    .key("sampling.rate")
    .floatType()
    .defaultValue(0.1f)
    .withDescription("Sampling rate");

ConfigOption<Double> THRESHOLD = ConfigOptions
    .key("quality.threshold")
    .doubleType()
    .defaultValue(0.95)
    .withDescription("Quality threshold");

// Using created options
public class MyConfig {
    public static final ConfigOption<String> HOST = ConfigOptions
        .key("host")
        .stringType()
        .defaultValue("localhost");

    public static final ConfigOption<Integer> PORT = ConfigOptions
        .key("port")
        .intType()
        .defaultValue(8080);

    public static final ConfigOption<Boolean> SSL_ENABLED = ConfigOptions
        .key("ssl.enabled")
        .booleanType()
        .defaultValue(true);
}

// Reading configuration
Options options = new Options(configMap);
String host = options.get(MyConfig.HOST);
int port = options.get(MyConfig.PORT);
boolean ssl = options.get(MyConfig.SSL_ENABLED);

// Setting configuration programmatically
Options opts = new Options();
opts.set(MyConfig.HOST, "example.com");
opts.set(MyConfig.PORT, 9090);
opts.set(MyConfig.SSL_ENABLED, false);

Related Pages

Page Connections

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