ex00 commented on a change in pull request #8632: [FLINK-12744][ml] add shared
params in ml package
URL: https://github.com/apache/flink/pull/8632#discussion_r293368947
##########
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)) {
+ String v = params.get(nameOrAlias);
+ if (value != null && v != null) {
+ throw new
IllegalArgumentException(String.format("Duplicate parameters of %s and %s",
Review comment:
The `params` is `HashMap` by `String` as key. It is mean that
`usedParamName` == `nameOrAlias` in this case. and an error message will look
like as `Duplicate parameters of param1 and param1`.
The `HashMap<String,String>` can't content two records by one key value.
I suppose that it is the wrong place to check duplicates, could we check
duplicates in another place?
probably it can be before to call `params.put` (and `putAll` from json) or
constructor of `ParamInfo` - before set aliases field check array for
duplicates and that `name` not contains in aliases array.
----------------------------------------------------------------
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