shaomengwang 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_r293789454
##########
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:
`params.put` can use `ParamInfo.getName` to get the key. It will not be able
to generate duplicates and there is no information about paramName and alias at
`putAll` from json. Probably `params.get` here is the proper place to check
duplicates
I agree with you it should be check duplicates in `ParamInfoFactory.setAlias`
----------------------------------------------------------------
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