Chesnay Schepler created FLINK-6577:
---------------------------------------

             Summary: Expand supported types for ConfigOptions
                 Key: FLINK-6577
                 URL: https://issues.apache.org/jira/browse/FLINK-6577
             Project: Flink
          Issue Type: Wish
          Components: Configuration
            Reporter: Chesnay Schepler


The type of a {{ConfigOption}} is currently limited to the types the that 
{{Configuration}} supports, which boils down to basic types and byte arrays.

It would be useful if they could also return things like enums, or the recently 
added {{MemorySize}}.

I propose adding a {{fromConfiguration(Configuration}} method to the 
{{ConfigOption}} class.

{code}
// ConfigOption definition
ConfigOption<MemorySize> MEMORY =
    key("memory")
        .defaultValue(new MemorySize(12345))
        .from(new ExtractorFunction<MemorySize>() {
            MemorySize extract(Configuration config) {
                // add check for unconfigured option
                return MemorySize.parse(config.getString("memory");}
        });

// usage
MemorySize memory = MEMORY.fromConfiguration(config);

// with default
MemorySize memory = MEMORY.fromConfiguration(config, new MemorySize(12345);

// internals of ConfigOption#fromConfiguration
<T> fromConfiguration(Configuration config) {
    if (this.extractor == null) { // throw error or something }
    T value = this.extractor.extract(config);
    return value == null ? defaultValue : value;
}
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to