xuyang1706 commented on a change in pull request #9300: [FLINK-13513][ml] Add 
the FlatMapper and related classes for later al…
URL: https://github.com/apache/flink/pull/9300#discussion_r337473854
 
 

 ##########
 File path: 
flink-ml-parent/flink-ml-lib/src/main/java/org/apache/flink/ml/common/mapper/FlatMapper.java
 ##########
 @@ -0,0 +1,108 @@
+/*
+ * 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.ml.common.mapper;
+
+import org.apache.flink.ml.api.misc.param.Params;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Collector;
+
+import java.io.Serializable;
+
+/**
+ * Abstract class for flatMappers.
+ * FlatMapper maps a row to zero, one or multiple rows.
+ */
+public abstract class FlatMapper implements Serializable {
+
+       /**
+        * schema of the input.
+        */
+       protected TableSchema dataSchema;
+
+       /**
+        * params used for FlatMapper.
+        * User can set the params before that the FlatMapper is executed.
+        */
+       protected Params params;
+
+       public FlatMapper(TableSchema dataSchema, Params params) {
+               this.dataSchema = dataSchema;
+               this.params = (null == params) ? new Params() : params.clone();
+       }
+
+       /**
+        * The core method of the FlatMapper.
+        * Takes a row from the input and maps it to multiple rows.
+        *
+        * @param row    The input row.
+        * @param output The collector for returning the result values.
+        * @throws Exception This method may throw exceptions. Throwing an 
exception will cause the operation
+        *                   to fail.
+        */
+       public abstract void flatMap(Row row, Collector<Row> output) throws 
Exception;
+
+       /**
+        * Get the table schema(includes column names and types) of the 
calculation result.
+        *
+        * @return the table schema of output Row type data
+        */
+       public abstract TableSchema getOutputSchema();
+
+       /**
+        * Generate new instance of given FlatMapper class.
+        *
+        * @param flatMapperClassName Name of the FlatMapper class
+        * @param dataSchema          The schema of the input data represented 
in Table format.
+        * @param params              The parameters for the instance 
construction.
+        * @return new instance of given FlatMapper class
+        * @throws Exception if flatMapperClass is not the class of {@link 
FlatMapper}
+        */
+       public static FlatMapper of(
 
 Review comment:
   Thanks, changed the static method.

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