Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,24 @@
*/
public abstract class AuronConfiguration {

public static final ConfigOption<Integer> BATCH_SIZE = ConfigOptions.key("auron.batchSize")
.description("Suggested batch size for arrow batches.")
.intType()
.defaultValue(10000);

public static final ConfigOption<Double> MEMORY_FRACTION = ConfigOptions.key("auron.memoryFraction")
.description("Suggested fraction of off-heap memory used in native execution. "
public static final ConfigOption<Integer> BATCH_SIZE = new ConfigOption<>(Integer.class)
.withKey("auron.batchSize")
.withDescription("Suggested batch size for arrow batches.")
.withDefaultValue(10000);

public static final ConfigOption<Double> MEMORY_FRACTION = new ConfigOption<>(Double.class)
.withKey("auron.memoryFraction")
.withDescription("Suggested fraction of off-heap memory used in native execution. "
+ "actual off-heap memory usage is expected to be spark.executor.memoryOverhead * fraction.")
.doubleType()
.defaultValue(0.6);
.withDefaultValue(0.6);

public static final ConfigOption<String> NATIVE_LOG_LEVEL = ConfigOptions.key("auron.native.log.level")
.description("Log level for native execution.")
.stringType()
.defaultValue("info");
public static final ConfigOption<String> NATIVE_LOG_LEVEL = new ConfigOption<>(String.class)
.withKey("auron.native.log.level")
.withDescription("Log level for native execution.")
.withDefaultValue("info");

public abstract <T> Optional<T> getOptional(ConfigOption<T> option);

public abstract <T> Optional<T> getOptional(String key);

public <T> T get(ConfigOption<T> option) {
return getOptional(option).orElseGet(() -> getOptionDefaultValue(option));
}
Expand All @@ -57,18 +55,6 @@ public String getString(ConfigOption<String> configOption) {
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
}

/**
* Returns the value associated with the given config option as a string. If no value is mapped
* under any key of the option, it returns the specified default instead of the option's default
* value.
*
* @param configOption The configuration option
* @return the (default) value associated with the given config option
*/
public String getString(ConfigOption<String> configOption, String overrideDefault) {
return getOptional(configOption).orElse(overrideDefault);
}

/**
* Returns the value associated with the given config option as an integer.
*
Expand All @@ -79,19 +65,6 @@ public int getInteger(ConfigOption<Integer> configOption) {
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
}

/**
* Returns the value associated with the given config option as an integer. If no value is
* mapped under any key of the option, it returns the specified default instead of the option's
* default value.
*
* @param configOption The configuration option
* @param overrideDefault The value to return if no value was mapped for any key of the option
* @return the configured value associated with the given config option, or the overrideDefault
*/
public int getInteger(ConfigOption<Integer> configOption, int overrideDefault) {
return getOptional(configOption).orElse(overrideDefault);
}

/**
* Returns the value associated with the given config option as a long integer.
*
Expand All @@ -102,19 +75,6 @@ public long getLong(ConfigOption<Long> configOption) {
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
}

/**
* Returns the value associated with the given config option as a long integer. If no value is
* mapped under any key of the option, it returns the specified default instead of the option's
* default value.
*
* @param configOption The configuration option
* @param overrideDefault The value to return if no value was mapped for any key of the option
* @return the configured value associated with the given config option, or the overrideDefault
*/
public long getLong(ConfigOption<Long> configOption, long overrideDefault) {
return getOptional(configOption).orElse(overrideDefault);
}

/**
* Returns the value associated with the given config option as a boolean.
*
Expand Down Expand Up @@ -148,19 +108,6 @@ public float getFloat(ConfigOption<Float> configOption) {
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
}

/**
* Returns the value associated with the given config option as a float. If no value is mapped
* under any key of the option, it returns the specified default instead of the option's default
* value.
*
* @param configOption The configuration option
* @param overrideDefault The value to return if no value was mapped for any key of the option
* @return the configured value associated with the given config option, or the overrideDefault
*/
public float getFloat(ConfigOption<Float> configOption, float overrideDefault) {
return getOptional(configOption).orElse(overrideDefault);
}

/**
* Returns the value associated with the given config option as a {@code double}.
*
Expand All @@ -171,19 +118,6 @@ public double getDouble(ConfigOption<Double> configOption) {
return getOptional(configOption).orElseGet(() -> getOptionDefaultValue(configOption));
}

/**
* Returns the value associated with the given config option as a {@code double}. If no value is
* mapped under any key of the option, it returns the specified default instead of the option's
* default value.
*
* @param configOption The configuration option
* @param overrideDefault The value to return if no value was mapped for any key of the option
* @return the configured value associated with the given config option, or the overrideDefault
*/
public double getDouble(ConfigOption<Double> configOption, double overrideDefault) {
return getOptional(configOption).orElse(overrideDefault);
}

/**
* Returns the value associated with the given config option as a {@code double}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/
package org.apache.auron.configuration;

import static org.apache.auron.util.Preconditions.checkNotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.apache.auron.jni.AuronAdaptor;

/**
* A {@code ConfigOption} describes a configuration parameter. It encapsulates the configuration
Expand All @@ -35,16 +36,22 @@ public class ConfigOption<T> {
public static final String EMPTY_DESCRIPTION = "";

/** The current key for that config option. */
private final String key;
private String key;

/** The current key for that config option. */
private List<String> altKeys = new ArrayList<>();

/** The default value for this option. */
private final T defaultValue;
private T defaultValue;

/** The current category for that config option. */
private String category = "Uncategorized";

/** The description for this option. */
private final String description;
private String description;

/** The function to compute the default value. */
private final Function<AuronConfiguration, T> dynamicDefaultValueFunction;
private Function<AuronConfiguration, T> dynamicDefaultValueFunction;

/**
* Type of the value that this ConfigOption describes.
Expand All @@ -55,27 +62,40 @@ public class ConfigOption<T> {
* <li>typeClass == atomic class and isList == true for {@code ConfigOption<List<Integer>>}
* </ul>
*/
private final Class<?> clazz;
private Class<T> clazz;

/**
* Creates a new config option with fallback keys.
*
* @param key The current key for that config option
* @param clazz describes type of the ConfigOption, see description of the clazz field
* @param description Description for that option
* @param defaultValue The default value for this option
*/
ConfigOption(
String key,
Class<?> clazz,
T defaultValue,
String description,
Function<AuronConfiguration, T> dynamicDefaultValueFunction) {
this.key = checkNotNull(key);
this.description = description;
public ConfigOption(Class<T> clazz) {
this.clazz = clazz;
}

public ConfigOption<T> withKey(String key) {
this.key = key;
return this;
}

public ConfigOption<T> addAltKey(String altKey) {
this.altKeys.add(altKey);
return this;
}

public ConfigOption<T> withDefaultValue(T defaultValue) {
this.defaultValue = defaultValue;
this.clazz = checkNotNull(clazz);
return this;
}

public ConfigOption<T> withCategory(String category) {
this.category = category;
return this;
}

public ConfigOption<T> withDescription(String description) {
this.description = description;
return this;
}

public ConfigOption<T> withDynamicDefaultValue(Function<AuronConfiguration, T> dynamicDefaultValueFunction) {
this.dynamicDefaultValueFunction = dynamicDefaultValueFunction;
return this;
}

/**
Expand All @@ -88,21 +108,24 @@ public String key() {
}

/**
* Gets the description of configuration key
*
* @return
* Gets the alternative configuration keys.
*/
public String description() {
return description;
public List<String> altKeys() {
return altKeys;
}

/**
* Checks if this option has a default value.
*
* @return True if it has a default value, false if not.
* Gets the category of configuration key
*/
public boolean hasDefaultValue() {
return defaultValue != null;
public String category() {
return category;
}

/**
* Gets the description of configuration key
*/
public String description() {
return description;
}

/**
Expand Down Expand Up @@ -131,4 +154,22 @@ public boolean hasDynamicDefaultValue() {
public Function<AuronConfiguration, T> dynamicDefaultValueFunction() {
return dynamicDefaultValueFunction;
}

/**
* Gets the type class of the value that this ConfigOption describes.
*
* @return The type class of the value that this ConfigOption describes.
*/
public Class<T> getValueClass() {
return clazz;
}

/**
* Retrieves the current value of this configuration option.
*
* @return the current value associated with this configuration option.
*/
public T get() {
return AuronAdaptor.getInstance().getAuronConfiguration().get(this);
}
}
Loading
Loading