You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/06/19 02:55:07 UTC

[GitHub] [flink] xuyang1706 commented on a change in pull request #8776: [FLINK-12881][ml] Add more functionalities for ML Params and ParamInfo class

xuyang1706 commented on a change in pull request #8776: [FLINK-12881][ml] Add more functionalities for ML Params and ParamInfo class
URL: https://github.com/apache/flink/pull/8776#discussion_r295102870
 
 

 ##########
 File path: flink-ml-parent/flink-ml-api/src/main/java/org/apache/flink/ml/api/misc/param/Params.java
 ##########
 @@ -44,17 +86,39 @@
 	 * @param <V>  the type of the specific parameter
 	 * @return the value of the specific parameter, or default value defined in the {@code info} if
 	 * this Params doesn't contain the parameter
-	 * @throws RuntimeException if the Params doesn't contains the specific parameter, while the
-	 *                          param is not optional but has no default value in the {@code info}
+	 * @throws IllegalArgumentException if the Params doesn't contains the specific parameter, while the
+	 *                          param is not optional but has no default value in the {@code info} or
+	 *                          if the Params contains the specific parameter and alias, but has more
+	 *                          than one value or
+	 *                          if the Params doesn't contains the specific parameter, while the ParamInfo
+	 *                          is optional but has no default value
 	 */
-	@SuppressWarnings("unchecked")
 	public <V> V get(ParamInfo<V> info) {
-		V value = (V) paramMap.getOrDefault(info.getName(), info.getDefaultValue());
-		if (value == null && !info.isOptional() && !info.hasDefaultValue()) {
-			throw new RuntimeException(info.getName() +
-				" not exist which is not optional and don't have a default value");
+		String value = null;
+		String usedParamName = null;
+		for (String nameOrAlias : getParamNameAndAlias(info)) {
+			if (params.containsKey(nameOrAlias)) {
+				if (usedParamName != null) {
+					throw new IllegalArgumentException(String.format("Duplicate parameters of %s and %s",
 
 Review comment:
   `usedParamName` is the first found in the list returned by `getParamNameAndAlias(info)`, so when the map contain the param name or the alias more than one, it will throw exception.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services