[ https://issues.apache.org/jira/browse/FLINK-2021?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15141305#comment-15141305 ]
ASF GitHub Bot commented on FLINK-2021: --------------------------------------- Github user fhueske commented on a diff in the pull request: https://github.com/apache/flink/pull/1581#discussion_r52496167 --- Diff: flink-examples/flink-examples-batch/src/main/java/org/apache/flink/examples/java/clustering/KMeans.java --- @@ -61,42 +62,46 @@ * <li>Cluster centers are represented by an integer id and a point value.<br> * For example <code>"1 6.2 3.2\n2 2.9 5.7\n"</code> gives two centers (id=1, x=6.2, y=3.2) and (id=2, x=2.9, y=5.7). * </ul> - * + * * <p> - * Usage: <code>KMeans <points path> <centers path> <result path> <num iterations></code><br> - * If no parameters are provided, the program is run with default data from {@link org.apache.flink.examples.java.clustering.util.KMeansData} and 10 iterations. - * + * Usage: <code>KMeans --points <path> --centroids <path> --output <path> --iterations <n></code><br> + * If no parameters are provided, the program is run with default data from {@link org.apache.flink.examples.java.clustering.util.KMeansData} and 10 iterations. + * * <p> * This example shows how to use: * <ul> * <li>Bulk iterations * <li>Broadcast variables in bulk iterations - * <li>Custom Java objects (PoJos) + * <li>Custom Java objects (POJOs) * </ul> */ @SuppressWarnings("serial") public class KMeans { - - // ************************************************************************* - // PROGRAM - // ************************************************************************* - + public static void main(String[] args) throws Exception { - - if(!parseParameters(args)) { - return; + + // Checking input parameters + final ParameterTool params = ParameterTool.fromArgs(args); + if (params.getNumberOfParameters() < 4) { --- End diff -- Otherwise we will use the file input if a user provides only the --points parameter although the printed message says differently. > Rework examples to use ParameterTool > ------------------------------------ > > Key: FLINK-2021 > URL: https://issues.apache.org/jira/browse/FLINK-2021 > Project: Flink > Issue Type: Improvement > Components: Examples > Affects Versions: 0.9 > Reporter: Robert Metzger > Assignee: Stefano Baghino > Priority: Minor > Labels: starter > > In FLINK-1525, we introduced the {{ParameterTool}}. > We should port the examples to use the tool. > The examples could look like this (we should maybe discuss it first on the > mailing lists): > {code} > public static void main(String[] args) throws Exception { > ParameterTool pt = ParameterTool.fromArgs(args); > boolean fileOutput = pt.getNumberOfParameters() == 2; > String textPath = null; > String outputPath = null; > if(fileOutput) { > textPath = pt.getRequired("input"); > outputPath = pt.getRequired("output"); > } > // set up the execution environment > final ExecutionEnvironment env = > ExecutionEnvironment.getExecutionEnvironment(); > env.getConfig().setUserConfig(pt); > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)