Package org.apache.flink.util
Class ParameterTool
- java.lang.Object
-
- org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters
-
- org.apache.flink.util.AbstractParameterTool
-
- org.apache.flink.util.ParameterTool
-
- All Implemented Interfaces:
Serializable
,Cloneable
@Public public class ParameterTool extends AbstractParameterTool
This class provides simple utility methods for reading and parsing program arguments from different sources. Only single value parameter could be supported in args.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,String>
data
-
Fields inherited from class org.apache.flink.util.AbstractParameterTool
DEFAULT_UNDEFINED, defaultData, NO_VALUE_KEY, unrequestedParameters
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
clone()
void
createPropertiesFile(String pathToFile)
Create a properties file with all the known parameters (call after the last get*() call).void
createPropertiesFile(String pathToFile, boolean overwrite)
Create a properties file with all the known parameters (call after the last get*() call).boolean
equals(Object o)
static ParameterTool
fromArgs(String[] args)
ReturnsParameterTool
for the given arguments.static ParameterTool
fromMap(Map<String,String> map)
ReturnsParameterTool
for the given map.static ParameterTool
fromPropertiesFile(File file)
ReturnsParameterTool
for the givenProperties
file.static ParameterTool
fromPropertiesFile(InputStream inputStream)
ReturnsParameterTool
for the given InputStream fromProperties
file.static ParameterTool
fromPropertiesFile(String path)
ReturnsParameterTool
for the givenProperties
file.static ParameterTool
fromSystemProperties()
ReturnsParameterTool
from the system properties.String
get(String key)
Returns the String value for the given key.Configuration
getConfiguration()
Returns aConfiguration
object from thisParameterTool
.int
getNumberOfParameters()
Returns number of parameters inParameterTool
.Properties
getProperties()
Returns aProperties
object from thisParameterTool
.boolean
has(String value)
Check if value is set.int
hashCode()
ParameterTool
mergeWith(ParameterTool other)
Merges twoParameterTool
.Map<String,String>
toMap()
Convert UserConfig into aMap<String, String>
representation.-
Methods inherited from class org.apache.flink.util.AbstractParameterTool
addToDefaults, get, getBoolean, getBoolean, getByte, getByte, getDouble, getDouble, getFloat, getFloat, getInt, getInt, getLong, getLong, getRequired, getShort, getShort, getUnrequestedParameters
-
-
-
-
Method Detail
-
fromArgs
public static ParameterTool fromArgs(String[] args)
ReturnsParameterTool
for the given arguments. The arguments are keys followed by values. Keys have to start with '-' or '--'Example arguments: --key1 value1 --key2 value2 -key3 value3
- Parameters:
args
- Input array arguments- Returns:
- A
ParameterTool
-
fromPropertiesFile
public static ParameterTool fromPropertiesFile(String path) throws IOException
ReturnsParameterTool
for the givenProperties
file.- Parameters:
path
- Path to the properties file- Returns:
- A
ParameterTool
- Throws:
IOException
- If the file does not exist- See Also:
Properties
-
fromPropertiesFile
public static ParameterTool fromPropertiesFile(File file) throws IOException
ReturnsParameterTool
for the givenProperties
file.- Parameters:
file
- File object to the properties file- Returns:
- A
ParameterTool
- Throws:
IOException
- If the file does not exist- See Also:
Properties
-
fromPropertiesFile
public static ParameterTool fromPropertiesFile(InputStream inputStream) throws IOException
ReturnsParameterTool
for the given InputStream fromProperties
file.- Parameters:
inputStream
- InputStream from the properties file- Returns:
- A
ParameterTool
- Throws:
IOException
- If the file does not exist- See Also:
Properties
-
fromMap
public static ParameterTool fromMap(Map<String,String> map)
ReturnsParameterTool
for the given map.- Parameters:
map
- A map of arguments. Both Key and Value have to be Strings- Returns:
- A
ParameterTool
-
fromSystemProperties
public static ParameterTool fromSystemProperties()
ReturnsParameterTool
from the system properties. Example on how to pass system properties: -Dkey1=value1 -Dkey2=value2- Returns:
- A
ParameterTool
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classExecutionConfig.GlobalJobParameters
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classExecutionConfig.GlobalJobParameters
-
getNumberOfParameters
public int getNumberOfParameters()
Returns number of parameters inParameterTool
.- Specified by:
getNumberOfParameters
in classAbstractParameterTool
-
get
public String get(String key)
Returns the String value for the given key. If the key does not exist it will return null.- Specified by:
get
in classAbstractParameterTool
-
has
public boolean has(String value)
Check if value is set.- Specified by:
has
in classAbstractParameterTool
-
getConfiguration
public Configuration getConfiguration()
Returns aConfiguration
object from thisParameterTool
.- Returns:
- A
Configuration
-
getProperties
public Properties getProperties()
Returns aProperties
object from thisParameterTool
.- Returns:
- A
Properties
-
createPropertiesFile
public void createPropertiesFile(String pathToFile) throws IOException
Create a properties file with all the known parameters (call after the last get*() call). Set the default value, if available.Use this method to create a properties file skeleton.
- Parameters:
pathToFile
- Location of the default properties file.- Throws:
IOException
-
createPropertiesFile
public void createPropertiesFile(String pathToFile, boolean overwrite) throws IOException
Create a properties file with all the known parameters (call after the last get*() call). Set the default value, if overwrite is true.- Parameters:
pathToFile
- Location of the default properties file.overwrite
- Boolean flag indicating whether or not to overwrite the file- Throws:
IOException
- If overwrite is not allowed and the file exists
-
clone
protected Object clone() throws CloneNotSupportedException
- Specified by:
clone
in classAbstractParameterTool
- Throws:
CloneNotSupportedException
-
mergeWith
public ParameterTool mergeWith(ParameterTool other)
Merges twoParameterTool
.- Parameters:
other
- OtherParameterTool
object- Returns:
- The Merged
ParameterTool
-
toMap
public Map<String,String> toMap()
Description copied from class:ExecutionConfig.GlobalJobParameters
Convert UserConfig into aMap<String, String>
representation. This can be used by the runtime, for example for presenting the user config in the web frontend.- Specified by:
toMap
in classAbstractParameterTool
- Returns:
- Key/Value representation of the UserConfig
-
-