xuyang1706 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_r293210991
 
 

 ##########
 File path: 
flink-ml-parent/flink-ml-api/src/main/java/org/apache/flink/ml/api/misc/param/Params.java
 ##########
 @@ -47,14 +70,33 @@
         * @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}
         */
-       @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");
+               Stream<V> paramValue = getParamNameAndAlias(info)
+                       .filter(this.params::containsKey)
+                       .map(x -> this.params.get(x))
+                       .map(x -> valueFromJson(x, info.getValueClass()))
+                       .limit(1);
+
+               if (info.isOptional()) {
+                       if (info.hasDefaultValue()) {
+                               return 
paramValue.reduce(info.getDefaultValue(), (a, b) -> b);
+                       } else {
+                               return 
paramValue.collect(Collectors.collectingAndThen(Collectors.toList(),
+                                       a -> {
+                                               if (a.isEmpty()) {
 
 Review comment:
   Some optional parameter have no default value. For example, in the LR model 
prediction, user need get the predict result, and most of times, the extra 
predict detail info is not needed. Thus, PredResultColName is required, and 
PredDetailColName is optional without default value.    

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


With regards,
Apache Git Services

Reply via email to