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 Options

From Leeroopedia


Knowledge Sources
Domains Configuration, Key-Value Store
Last Updated 2026-02-08 00:00 GMT

Overview

Options is a thread-safe, serializable container for storing and retrieving configuration key-value pairs in Apache Paimon.

Description

Options provides a comprehensive configuration management system for Paimon. It stores configuration as string key-value pairs internally but provides strongly-typed access through ConfigOption objects. This design bridges the gap between text-based configuration sources (property files, command-line arguments, etc.) and type-safe programmatic access.

The class is thread-safe, with all public methods synchronized to ensure consistency in concurrent environments. It implements Serializable, allowing configuration to be transmitted across process boundaries in distributed systems. The internal storage uses a HashMap, providing efficient key-based lookup.

Options supports multiple construction patterns: empty initialization, initialization from a single map, initialization from two maps (allowing layered configuration), and initialization from an iterable of entries. The fromMap factory method provides a convenient static constructor.

The class integrates deeply with ConfigOption objects, automatically handling type conversion, fallback keys, and prefix-based configuration maps. When retrieving a value with a ConfigOption, Options checks the primary key first, then any fallback keys in order. For map-typed options, it can extract all keys with a given prefix and return them as a map.

Beyond ConfigOption-based access, Options provides primitive accessors (getBoolean, getInteger, getLong, getDouble, getString) that accept raw string keys and default values. These methods handle type conversion automatically using the OptionsUtils utility class.

The class supports removing keys individually or by prefix, checking key existence, converting to Properties objects, and extracting subsets of configuration by prefix. This rich API makes Options suitable for both application-level configuration and fine-grained component configuration.

Usage

Use Options as the primary configuration container throughout Paimon applications. Construct it from framework-provided configuration maps, then use ConfigOption constants to retrieve typed values. The thread-safe design makes it suitable for sharing across components, while the serializable nature enables passing configuration in distributed contexts.

Code Reference

Source Location

Signature

@Public
@ThreadSafe
public class Options implements Serializable {
    private final HashMap<String, String> data;

    public Options()
    public Options(Map<String, String> map)
    public Options(Map<String, String> map1, Map<String, String> map2)
    public Options(Iterable<Map.Entry<String, String>> map)

    public static Options fromMap(Map<String, String> map)

    public synchronized void setString(String key, String value)
    public synchronized void set(String key, String value)
    public synchronized <T> Options set(ConfigOption<T> option, T value)

    public synchronized <T> T get(ConfigOption<T> option)
    public synchronized String get(String key)
    public synchronized <T> Optional<T> getOptional(ConfigOption<T> option)

    public synchronized boolean contains(ConfigOption<?> configOption)
    public synchronized boolean containsKey(String key)

    public synchronized Set<String> keySet()
    public synchronized Map<String, String> toMap()

    public synchronized Options removePrefix(String prefix)
    public synchronized String remove(String key)
    public synchronized void remove(ConfigOption<?> option)

    public synchronized void addAllToProperties(Properties props)

    public synchronized String getString(ConfigOption<String> option)
    public synchronized boolean getBoolean(String key, boolean defaultValue)
    public synchronized int getInteger(String key, int defaultValue)
    public synchronized double getDouble(String key, double defaultValue)
    public synchronized String getString(String key, String defaultValue)
    public synchronized void setInteger(String key, int value)
    public synchronized long getLong(String key, long defaultValue)
}

Import

import org.apache.paimon.options.Options;

I/O Contract

Inputs

Name Type Required Description
map Map<String, String> No Initial configuration map
map1, map2 Map<String, String> No Two maps for layered initialization
key String Yes Configuration key
value String/T Yes Configuration value
option ConfigOption<T> Yes Typed configuration option
defaultValue T For primitive accessors Default value if key not found

Outputs

Name Type Description
options Options Configuration container instance
value T Retrieved configuration value
optionalValue Optional<T> Configuration value wrapped in Optional
keySet Set<String> All configuration keys
map Map<String, String> Configuration as map
containsKey boolean Whether key exists
removed String Removed value

Usage Examples

// Creating from map
Map<String, String> configMap = new HashMap<>();
configMap.put("warehouse", "/data/warehouse");
configMap.put("metastore", "hive");
configMap.put("port", "9083");

Options options = new Options(configMap);
// or
Options options2 = Options.fromMap(configMap);

// Using with ConfigOption
ConfigOption<String> WAREHOUSE = ConfigOptions.key("warehouse")
    .stringType()
    .noDefaultValue();

String warehouse = options.get(WAREHOUSE);

// Setting values
options.set(WAREHOUSE, "/new/warehouse");
options.setString("metastore", "jdbc");
options.setInteger("pool-size", 5);

// Type-safe access with defaults
ConfigOption<Integer> POOL_SIZE = ConfigOptions.key("pool-size")
    .intType()
    .defaultValue(2);

int poolSize = options.get(POOL_SIZE); // returns 5 or default 2

// Optional access
Optional<String> uri = options.getOptional(URI_OPTION);
uri.ifPresent(u -> System.out.println("URI: " + u));

// Primitive accessors
boolean enabled = options.getBoolean("cache.enabled", true);
int timeout = options.getInteger("timeout", 30);
double threshold = options.getDouble("threshold", 0.95);
String name = options.getString("name", "default");
long maxSize = options.getLong("max-size", 1000000L);

// Checking existence
if (options.contains(WAREHOUSE)) {
    // configuration is present
}

if (options.containsKey("metastore")) {
    // key exists
}

// Removing configuration
options.remove(WAREHOUSE);
String removed = options.remove("metastore");

// Extracting by prefix
Options hadoopConf = options.removePrefix("hadoop.");
// If options had "hadoop.fs.defaultFS" and "hadoop.dfs.replication",
// hadoopConf will have "fs.defaultFS" and "dfs.replication"

// Converting to Properties
Properties props = new Properties();
options.addAllToProperties(props);

// Getting all keys and values
Set<String> keys = options.keySet();
Map<String, String> allConfig = options.toMap();

// Layered configuration
Map<String, String> defaults = loadDefaults();
Map<String, String> userConfig = loadUserConfig();
Options finalConfig = new Options(defaults, userConfig);
// userConfig overrides defaults

// Iterable construction
List<Map.Entry<String, String>> entries = getConfigEntries();
Options options3 = new Options(entries);

// Thread-safe access
Options shared = new Options(sharedConfig);
// Multiple threads can safely read and write
executor.submit(() -> shared.set(OPTION1, value1));
executor.submit(() -> shared.set(OPTION2, value2));

Related Pages

Page Connections

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