You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2017/07/01 10:06:41 UTC

[08/16] flink git commit: [FLINK-6638] Allow overriding default for primitive ConfigOption

[FLINK-6638] Allow overriding default for primitive ConfigOption

This closes #4016.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/60a59d27
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/60a59d27
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/60a59d27

Branch: refs/heads/master
Commit: 60a59d27012a0343d1c9bff8b8816284d6ef762a
Parents: f839018
Author: zentol <ch...@apache.org>
Authored: Tue May 30 09:42:31 2017 +0200
Committer: zentol <ch...@apache.org>
Committed: Sat Jul 1 10:02:08 2017 +0200

----------------------------------------------------------------------
 .../flink/configuration/Configuration.java      | 90 ++++++++++++++++++++
 .../configuration/DelegatingConfiguration.java  | 25 ++++++
 2 files changed, 115 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/60a59d27/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java b/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java
index ea0c419..a1da5b3 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java
@@ -219,6 +219,24 @@ public class Configuration extends ExecutionConfig.GlobalJobParameters
 	}
 
 	/**
+	 * 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 mapper for any key of the option
+	 * @return the configured value associated with the given config option, or the overrideDefault
+	 */
+	@PublicEvolving
+	public int getInteger(ConfigOption<Integer> configOption, int overrideDefault) {
+		Object o = getRawValueFromOption(configOption);
+		if (o == null) {
+			return overrideDefault;
+		}
+		return convertToInt(o, configOption.defaultValue());
+	}
+
+	/**
 	 * Adds the given key/value pair to the configuration object.
 	 * 
 	 * @param key
@@ -275,6 +293,24 @@ public class Configuration extends ExecutionConfig.GlobalJobParameters
 	}
 
 	/**
+	 * 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 mapper for any key of the option
+	 * @return the configured value associated with the given config option, or the overrideDefault
+	 */
+	@PublicEvolving
+	public long getLong(ConfigOption<Long> configOption, long overrideDefault) {
+		Object o = getRawValueFromOption(configOption);
+		if (o == null) {
+			return overrideDefault;
+		}
+		return convertToLong(o, configOption.defaultValue());
+	}
+
+	/**
 	 * Adds the given key/value pair to the configuration object.
 	 * 
 	 * @param key
@@ -331,6 +367,24 @@ public class Configuration extends ExecutionConfig.GlobalJobParameters
 	}
 
 	/**
+	 * Returns the value associated with the given config option as a boolean.
+	 * 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 mapper for any key of the option
+	 * @return the configured value associated with the given config option, or the overrideDefault
+	 */
+	@PublicEvolving
+	public boolean getBoolean(ConfigOption<Boolean> configOption, boolean overrideDefault) {
+		Object o = getRawValueFromOption(configOption);
+		if (o == null) {
+			return overrideDefault;
+		}
+		return convertToBoolean(o);
+	}
+
+	/**
 	 * Adds the given key/value pair to the configuration object.
 	 * 
 	 * @param key
@@ -387,6 +441,24 @@ public class Configuration extends ExecutionConfig.GlobalJobParameters
 	}
 
 	/**
+	 * 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 mapper for any key of the option
+	 * @return the configured value associated with the given config option, or the overrideDefault
+	 */
+	@PublicEvolving
+	public float getFloat(ConfigOption<Float> configOption, float overrideDefault) {
+		Object o = getRawValueFromOption(configOption);
+		if (o == null) {
+			return overrideDefault;
+		}
+		return convertToFloat(o, configOption.defaultValue());
+	}
+
+	/**
 	 * Adds the given key/value pair to the configuration object.
 	 * 
 	 * @param key
@@ -443,6 +515,24 @@ public class Configuration extends ExecutionConfig.GlobalJobParameters
 	}
 
 	/**
+	 * 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 mapper for any key of the option
+	 * @return the configured value associated with the given config option, or the overrideDefault
+	 */
+	@PublicEvolving
+	public double getDouble(ConfigOption<Double> configOption, double overrideDefault) {
+		Object o = getRawValueFromOption(configOption);
+		if (o == null) {
+			return overrideDefault;
+		}
+		return convertToDouble(o, configOption.defaultValue());
+	}
+
+	/**
 	 * Adds the given key/value pair to the configuration object.
 	 * 
 	 * @param key

http://git-wip-us.apache.org/repos/asf/flink/blob/60a59d27/flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java b/flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java
index 29f76b5..8cac66c 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/DelegatingConfiguration.java
@@ -111,6 +111,11 @@ public final class DelegatingConfiguration extends Configuration {
 	public int getInteger(ConfigOption<Integer> configOption) {
 		return  this.backingConfig.getInteger(prefixOption(configOption, prefix));
 	}
+	
+	@Override
+	public int getInteger(ConfigOption<Integer> configOption, int overrideDefault) {
+		return this.backingConfig.getInteger(configOption, overrideDefault);
+	}
 
 	@Override
 	public void setInteger(String key, int value) {
@@ -133,6 +138,11 @@ public final class DelegatingConfiguration extends Configuration {
 	}
 
 	@Override
+	public long getLong(ConfigOption<Long> configOption, long overrideDefault) {
+		return this.backingConfig.getLong(configOption, overrideDefault);
+	}
+
+	@Override
 	public void setLong(String key, long value) {
 		this.backingConfig.setLong(this.prefix + key, value);
 	}
@@ -163,6 +173,11 @@ public final class DelegatingConfiguration extends Configuration {
 	}
 
 	@Override
+	public boolean getBoolean(ConfigOption<Boolean> configOption, boolean overrideDefault) {
+		return this.backingConfig.getBoolean(configOption, overrideDefault);
+	}
+
+	@Override
 	public float getFloat(String key, float defaultValue) {
 		return this.backingConfig.getFloat(this.prefix + key, defaultValue);
 	}
@@ -173,6 +188,11 @@ public final class DelegatingConfiguration extends Configuration {
 	}
 
 	@Override
+	public float getFloat(ConfigOption<Float> configOption, float overrideDefault) {
+		return this.backingConfig.getFloat(configOption, overrideDefault);
+	}
+
+	@Override
 	public void setFloat(String key, float value) {
 		this.backingConfig.setFloat(this.prefix + key, value);
 	}
@@ -193,6 +213,11 @@ public final class DelegatingConfiguration extends Configuration {
 	}
 
 	@Override
+	public double getDouble(ConfigOption<Double> configOption, double overrideDefault) {
+		return this.backingConfig.getDouble(configOption, overrideDefault);
+	}
+
+	@Override
 	public void setDouble(String key, double value) {
 		this.backingConfig.setDouble(this.prefix + key, value);
 	}