wangyang0918 commented on a change in pull request #10084: [FLINK-14382][yarn] 
Incorrect handling of FLINK_PLUGINS_DIR on Yarn
URL: https://github.com/apache/flink/pull/10084#discussion_r345835519
 
 

 ##########
 File path: 
flink-java/src/main/java/org/apache/flink/api/java/utils/MultipleParameterTool.java
 ##########
 @@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.java.utils;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.api.java.Utils;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.lang3.math.NumberUtils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+/**
+ * This class provides simple utility methods for reading and parsing program 
arguments from different sources. This is
+ * a enhanced tool for {@link ParameterTool} with multiple parameters support.
+ */
+@PublicEvolving
+public class MultipleParameterTool extends ParameterTool {
+       private static final long serialVersionUID = 1L;
+
+       // ------------------ Constructors ------------------------
+
+       /**
+        * Returns {@link MultipleParameterTool} for the given arguments. The 
arguments are keys followed by values.
+        * Keys have to start with '-' or '--'
+        *
+        * <p><strong>Example arguments:</strong>
+        * --key1 value1 --key2 value2 -key3 value3
+        * --multi multiValue1 --multi multiValue2
+        *
+        * @param args Input array arguments
+        * @return A {@link MultipleParameterTool}
+        */
+       public static MultipleParameterTool fromArgs(String[] args) {
+               final Map<String, Collection<String>> map = new 
HashMap<>(args.length / 2);
+
+               int i = 0;
+               while (i < args.length) {
+                       final String key = Utils.getKeyFromArgs(args, i);
+
+                       i += 1; // try to find the value
+
+                       map.putIfAbsent(key, new ArrayList<>());
+                       if (i >= args.length) {
+                               map.get(key).add(NO_VALUE_KEY);
+                       } else if (NumberUtils.isNumber(args[i])) {
+                               map.get(key).add(args[i]);
+                               i += 1;
+                       } else if (args[i].startsWith("--") || 
args[i].startsWith("-")) {
+                               // the argument cannot be a negative number 
because we checked earlier
+                               // -> the next argument is a parameter name
+                               map.get(key).add(NO_VALUE_KEY);
+                       } else {
+                               map.get(key).add(args[i]);
+                               i += 1;
+                       }
+               }
+
+               return fromMultiMap(map);
+       }
+
+       /**
+        * Returns {@link MultipleParameterTool} for the given multi map.
+        *
+        * @param multiMap A map of arguments. Key is String and value is a 
Collection.
+        * @return A {@link MultipleParameterTool}
+        */
+       public static MultipleParameterTool fromMultiMap(Map<String, 
Collection<String>> multiMap) {
+               Preconditions.checkNotNull(multiMap, "Unable to initialize from 
empty map");
+               return new MultipleParameterTool(multiMap);
+       }
+
+       // ------------------ ParameterUtil  ------------------------
+       protected final Map<String, Collection<String>> data;
 
 Review comment:
   @pnowojski Thanks for your quick response.
   
   I also realize that add `MultipleParameterTool` is an overkill for just one 
e2e test. However, it is more elegant and will be a valuable addition. 
   
   For now implementation of `MultipleParameterTool`, it is compatible with 
`ParameterTool`. Even the `#getConfiguration` `#getProperties` could be used. 
But it is still confusing. So i will follow your suggestion to add 
`AbstractParameterTool ` with no data. `ParameterTool ` and 
`MultipleParameterTool ` will have different implementations.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to