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 2022/11/03 02:42:58 UTC

[GitHub] [flink-ml] zhipeng93 commented on a diff in pull request #160: [FLINK-29434] Add AlgoOperator for Splitter

zhipeng93 commented on code in PR #160:
URL: https://github.com/apache/flink-ml/pull/160#discussion_r1012438620


##########
docs/content/docs/operators/feature/randomsplitter.md:
##########
@@ -0,0 +1,148 @@
+---
+title: "RandomSplitter"
+weight: 1
+type: docs
+aliases:
+- /operators/feature/randomSplitter.html
+---
+
+<!--
+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.
+-->
+
+## RandomSplitter
+
+An AlgoOperator which splits a table into N tables according to the given weights.
+
+### Parameters
+
+| Key     | Default | Type      | Required | Description                    |
+|:--------|:--------|:----------|:---------|:-------------------------------|
+| weights | `[0.5]` | Do uble[] | no       | The weights of data splitting. |

Review Comment:
   The default values should be `[1.0, 1.0]` and the Type should be `Double[]`.



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/randomsplitter/RandomSplitterParams.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.feature.randomsplitter;
+
+import org.apache.flink.ml.param.DoubleArrayParam;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.param.ParamValidator;
+import org.apache.flink.ml.param.WithParams;
+
+/**
+ * Params of {@link RandomSplitter}.
+ *
+ * @param <T> The class type of this instance.
+ */
+public interface RandomSplitterParams<T> extends WithParams<T> {
+    Param<Double[]> WEIGHTS =
+            new DoubleArrayParam(
+                    "weights",
+                    "The weights of data splitting.",
+                    new Double[] {1.0, 1.0},
+                    weightsValidator());
+
+    default Double[] getWeights() {
+        return get(WEIGHTS);
+    }
+
+    default T setWeights(Double... value) {
+        return set(WEIGHTS, value);
+    }
+
+    // Checks the weights parameter.
+    static ParamValidator<Double[]> weightsValidator() {
+        return weights -> {
+            if (weights == null) {
+                return false;
+            }
+            for (Double ele : weights) {
+                if (ele < 0.0) {

Review Comment:
   It should be `ele <= 0`.
   
   nit: How about rename `ele` to `weight`?



##########
flink-ml-python/pyflink/ml/lib/feature/randomsplitter.py:
##########
@@ -0,0 +1,77 @@
+################################################################################
+#  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.
+################################################################################
+import typing
+from typing import Tuple
+from pyflink.ml.core.param import Param, FloatArrayParam, ParamValidator
+from pyflink.ml.core.wrapper import JavaWithParams
+from pyflink.ml.lib.feature.common import JavaFeatureTransformer
+
+
+class _SplitterParams(
+    JavaWithParams
+):
+    """
+    Checks the weights parameter.
+    """
+    def weights_validator(self) -> ParamValidator[Tuple[float]]:
+        class WeightsValidator(ParamValidator[Tuple[float]]):
+            def validate(self, weights: Tuple[float]) -> bool:
+                for val in weights:
+                    if val <= 0.0:
+                        return False
+                return True
+        return WeightsValidator()
+
+    """
+    Params for :class:`RandomSplitter`.
+    """
+    WEIGHTS: Param[Tuple[float]] = FloatArrayParam(

Review Comment:
   Let's also add a doc to explain that the weight array will be normalized.



##########
flink-ml-lib/src/test/java/org/apache/flink/ml/feature/RandomSplitterTest.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.feature;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.feature.randomsplitter.RandomSplitter;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+/** Tests {@link RandomSplitter}. */
+public class RandomSplitterTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamExecutionEnvironment env;
+    private StreamTableEnvironment tEnv;
+
+    @Before
+    public void before() {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+
+        env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.setParallelism(1);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+
+        tEnv = StreamTableEnvironment.create(env);
+    }
+
+    private Table getTable(int size) {
+        DataStreamSource<Long> dataStream = env.fromSequence(0L, size);
+        return tEnv.fromDataStream(dataStream);
+    }
+
+    @Test
+    public void testParam() {
+        RandomSplitter splitter = new RandomSplitter();
+        splitter.setWeights(0.3, 0.4);
+        assertArrayEquals(new Double[] {0.3, 0.4}, splitter.getWeights());
+    }
+
+    @Test
+    public void testOutputSchema() {
+        Table tempTable =
+                tEnv.fromDataStream(env.fromElements(Row.of("", "")))
+                        .as("test_input", "dummy_input");
+
+        RandomSplitter splitter = new RandomSplitter().setWeights(0.5, 0.1);
+        Table[] output = splitter.transform(tempTable);
+        assertEquals(2, output.length);
+        for (Table table : output) {
+            assertEquals(
+                    Arrays.asList("test_input", "dummy_input"),
+                    table.getResolvedSchema().getColumnNames());
+        }
+    }
+
+    @Test
+    public void testWeights() throws Exception {
+        Table data = getTable(1000);
+        RandomSplitter splitter = new RandomSplitter().setWeights(2.0, 1.0, 2.0);
+        Table[] output = splitter.transform(data);
+
+        List<Row> result0 = IteratorUtils.toList(tEnv.toDataStream(output[0]).executeAndCollect());
+        List<Row> result1 = IteratorUtils.toList(tEnv.toDataStream(output[1]).executeAndCollect());
+        List<Row> result2 = IteratorUtils.toList(tEnv.toDataStream(output[2]).executeAndCollect());
+        assertEquals(result0.size() / 400.0, 1.0, 0.1);
+        assertEquals(result1.size() / 200.0, 1.0, 0.1);
+        assertEquals(result2.size() / 400.0, 1.0, 0.1);
+        verifyResultTables(data, output);
+    }
+
+    @Test
+    public void testSaveLoadAndTransform() throws Exception {
+        Table data = getTable(2000);
+        RandomSplitter randomSplitter = new RandomSplitter().setWeights(4.0, 6.0);
+
+        RandomSplitter splitterLoad =
+                TestUtils.saveAndReload(
+                        tEnv, randomSplitter, TEMPORARY_FOLDER.newFolder().getAbsolutePath());
+
+        Table[] output = splitterLoad.transform(data);
+        List<Row> result0 = IteratorUtils.toList(tEnv.toDataStream(output[0]).executeAndCollect());
+        List<Row> result1 = IteratorUtils.toList(tEnv.toDataStream(output[1]).executeAndCollect());
+        assertEquals(result0.size() / 800.0, 1.0, 0.1);
+        assertEquals(result1.size() / 1200.0, 1.0, 0.1);
+        verifyResultTables(data, output);
+    }
+
+    private void verifyResultTables(Table input, Table[] output) throws Exception {

Review Comment:
   The logic seems a bit confusing here. How about we directly compare the elements in `input` and `output` by adding them to two lists?



##########
flink-ml-python/pyflink/ml/lib/feature/tests/test_randomsplitter.py:
##########
@@ -0,0 +1,78 @@
+################################################################################
+#  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.
+################################################################################
+
+import os
+
+from pyflink.common import Types
+
+from pyflink.ml.lib.feature.randomsplitter import RandomSplitter
+from pyflink.ml.tests.test_utils import PyFlinkMLTestCase
+
+
+class RandomSplitterTest(PyFlinkMLTestCase):
+    def setUp(self):
+        super(RandomSplitterTest, self).setUp()
+        data = []
+        for i in range(1, 10000):
+            data.append((i, ))
+        self.input_table = self.t_env.from_data_stream(
+            self.env.from_collection(
+                data,
+                type_info=Types.ROW_NAMED(
+                    ['f0', ],
+                    [Types.INT(), ])))
+
+    def test_param(self):
+        splitter = RandomSplitter()
+        splitter.set_weights(0.2, 0.8)
+        self.assertEqual(0.2, splitter.weights[0])
+        self.assertEqual(0.8, splitter.weights[1])
+
+    def test_output_schema(self):
+        splitter = RandomSplitter()
+        input_data_table = self.t_env.from_data_stream(
+            self.env.from_collection([
+                ('', ''),
+            ],
+                type_info=Types.ROW_NAMED(
+                    ['test_input', 'dummy_input'],
+                    [Types.STRING(), Types.STRING()])))
+        output = splitter.set_weights(0.5, 0.5) \
+            .transform(input_data_table)[0]
+
+        self.assertEqual(
+            ['test_input', 'dummy_input'],
+            output.get_schema().get_field_names())
+
+    def test_fit_and_predict(self):
+        splitter = RandomSplitter().set_weights(0.4, 0.6)
+
+        output = splitter.transform(self.input_table)
+        results = [result for result in self.t_env.to_data_stream(output[0]).execute_and_collect()]
+        self.assertAlmostEqual(len(results) / 4000.0, 1.0, delta=0.1)
+
+    def test_save_load_predict(self):
+        splitter = RandomSplitter().set_weights(0.4, 0.6)
+
+        estimator_path = os.path.join(self.temp_dir, 'test_save_load_predict_splitter')

Review Comment:
   `RandomSplitter` is not an estimator. Let's update it as"
   `path = os.path.join(self.temp_dir, 'test_save_load_random_splitter')`



##########
flink-ml-python/pyflink/ml/lib/feature/randomsplitter.py:
##########
@@ -0,0 +1,77 @@
+################################################################################
+#  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.
+################################################################################
+import typing
+from typing import Tuple
+from pyflink.ml.core.param import Param, FloatArrayParam, ParamValidator
+from pyflink.ml.core.wrapper import JavaWithParams
+from pyflink.ml.lib.feature.common import JavaFeatureTransformer
+
+
+class _SplitterParams(
+    JavaWithParams
+):
+    """
+    Checks the weights parameter.
+    """
+    def weights_validator(self) -> ParamValidator[Tuple[float]]:
+        class WeightsValidator(ParamValidator[Tuple[float]]):

Review Comment:
   The python validator seems inconsistent with that in java --- The java version also checks the length of the array.



##########
flink-ml-python/pyflink/ml/lib/feature/randomsplitter.py:
##########
@@ -0,0 +1,77 @@
+################################################################################
+#  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.
+################################################################################
+import typing
+from typing import Tuple
+from pyflink.ml.core.param import Param, FloatArrayParam, ParamValidator
+from pyflink.ml.core.wrapper import JavaWithParams
+from pyflink.ml.lib.feature.common import JavaFeatureTransformer
+
+
+class _SplitterParams(
+    JavaWithParams
+):
+    """
+    Checks the weights parameter.
+    """
+    def weights_validator(self) -> ParamValidator[Tuple[float]]:

Review Comment:
   Let's make it a staic method following existing practive in `params.py`



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/randomsplitter/RandomSplitterParams.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.feature.randomsplitter;
+
+import org.apache.flink.ml.param.DoubleArrayParam;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.param.ParamValidator;
+import org.apache.flink.ml.param.WithParams;
+
+/**
+ * Params of {@link RandomSplitter}.
+ *
+ * @param <T> The class type of this instance.
+ */
+public interface RandomSplitterParams<T> extends WithParams<T> {
+    Param<Double[]> WEIGHTS =

Review Comment:
   Could you add a javadoc to explain that the input weights will be normalized? 



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/feature/randomsplitter/RandomSplitter.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.feature.randomsplitter;
+
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.ml.api.AlgoOperator;
+import org.apache.flink.ml.common.datastream.TableUtils;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.util.ParamUtils;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.OutputTag;
+import org.apache.flink.util.Preconditions;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+/** An AlgoOperator which splits a Table into N Tables according to the given weights. */
+public class RandomSplitter
+        implements AlgoOperator<RandomSplitter>, RandomSplitterParams<RandomSplitter> {
+    private final Map<Param<?>, Object> paramMap = new HashMap<>();
+
+    public RandomSplitter() {
+        ParamUtils.initializeMapWithDefaultValues(paramMap, this);
+    }
+
+    @Override
+    public Table[] transform(Table... inputs) {
+        Preconditions.checkArgument(inputs.length == 1);
+        StreamTableEnvironment tEnv =
+                (StreamTableEnvironment) ((TableImpl) inputs[0]).getTableEnvironment();
+        RowTypeInfo outputTypeInfo = TableUtils.getRowTypeInfo(inputs[0].getResolvedSchema());
+
+        final Double[] weights = getWeights();
+        OutputTag<Row>[] outputTags = new OutputTag[weights.length - 1];
+        for (int i = 0; i < outputTags.length; ++i) {
+            outputTags[i] = new OutputTag<Row>("outputTag_" + i, outputTypeInfo) {};
+        }
+
+        SingleOutputStreamOperator<Row> results =
+                tEnv.toDataStream(inputs[0])
+                        .transform(
+                                "SplitterOperator",
+                                outputTypeInfo,
+                                new SplitterOperator(outputTags, weights));
+
+        Table[] outputTables = new Table[weights.length];
+        outputTables[0] = tEnv.fromDataStream(results);
+
+        for (int i = 0; i < outputTags.length; ++i) {
+            DataStream<Row> dataStream = results.getSideOutput(outputTags[i]);
+            outputTables[i + 1] = tEnv.fromDataStream(dataStream);
+        }
+        return outputTables;
+    }
+
+    private static class SplitterOperator extends AbstractStreamOperator<Row>
+            implements OneInputStreamOperator<Row, Row> {
+        private final Random random = new Random(0);
+        OutputTag<Row>[] outputTag;
+        final double[] fractions;
+
+        public SplitterOperator(OutputTag<Row>[] outputTag, Double[] weights) {
+            this.outputTag = outputTag;
+            this.fractions = new double[weights.length - 1];
+            double weightSum = 0.0;
+            for (Double weight : weights) {
+                weightSum += weight;
+            }
+            double currentSum = 0.0;
+            for (int i = 0; i < fractions.length; ++i) {
+                currentSum += weights[i];
+                fractions[i] = currentSum / weightSum;
+            }
+        }
+
+        @Override
+        public void processElement(StreamRecord<Row> streamRecord) throws Exception {
+            double randVal = random.nextDouble();
+
+            if (randVal <= fractions[0]) {

Review Comment:
   How about we simplify the logic with `Arrays.binarySearch()`?



##########
flink-ml-python/pyflink/ml/lib/feature/randomsplitter.py:
##########
@@ -0,0 +1,77 @@
+################################################################################
+#  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.
+################################################################################
+import typing
+from typing import Tuple
+from pyflink.ml.core.param import Param, FloatArrayParam, ParamValidator
+from pyflink.ml.core.wrapper import JavaWithParams
+from pyflink.ml.lib.feature.common import JavaFeatureTransformer
+
+
+class _SplitterParams(

Review Comment:
   Let's update it as `_RandomSplitterParams`.



##########
flink-ml-python/pyflink/ml/lib/feature/tests/test_randomsplitter.py:
##########
@@ -0,0 +1,78 @@
+################################################################################
+#  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.
+################################################################################
+
+import os
+
+from pyflink.common import Types
+
+from pyflink.ml.lib.feature.randomsplitter import RandomSplitter
+from pyflink.ml.tests.test_utils import PyFlinkMLTestCase
+
+
+class RandomSplitterTest(PyFlinkMLTestCase):
+    def setUp(self):
+        super(RandomSplitterTest, self).setUp()
+        data = []
+        for i in range(1, 10000):
+            data.append((i, ))
+        self.input_table = self.t_env.from_data_stream(
+            self.env.from_collection(
+                data,
+                type_info=Types.ROW_NAMED(
+                    ['f0', ],
+                    [Types.INT(), ])))
+
+    def test_param(self):
+        splitter = RandomSplitter()
+        splitter.set_weights(0.2, 0.8)
+        self.assertEqual(0.2, splitter.weights[0])
+        self.assertEqual(0.8, splitter.weights[1])
+
+    def test_output_schema(self):
+        splitter = RandomSplitter()
+        input_data_table = self.t_env.from_data_stream(
+            self.env.from_collection([
+                ('', ''),
+            ],
+                type_info=Types.ROW_NAMED(
+                    ['test_input', 'dummy_input'],
+                    [Types.STRING(), Types.STRING()])))
+        output = splitter.set_weights(0.5, 0.5) \
+            .transform(input_data_table)[0]
+
+        self.assertEqual(
+            ['test_input', 'dummy_input'],
+            output.get_schema().get_field_names())
+
+    def test_fit_and_predict(self):
+        splitter = RandomSplitter().set_weights(0.4, 0.6)
+
+        output = splitter.transform(self.input_table)
+        results = [result for result in self.t_env.to_data_stream(output[0]).execute_and_collect()]
+        self.assertAlmostEqual(len(results) / 4000.0, 1.0, delta=0.1)
+
+    def test_save_load_predict(self):

Review Comment:
   Let's update the function name as `test_save_load_transform()`.



##########
flink-ml-python/pyflink/ml/lib/feature/tests/test_randomsplitter.py:
##########
@@ -0,0 +1,78 @@
+################################################################################
+#  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.
+################################################################################
+
+import os
+
+from pyflink.common import Types
+
+from pyflink.ml.lib.feature.randomsplitter import RandomSplitter
+from pyflink.ml.tests.test_utils import PyFlinkMLTestCase
+
+
+class RandomSplitterTest(PyFlinkMLTestCase):
+    def setUp(self):
+        super(RandomSplitterTest, self).setUp()
+        data = []
+        for i in range(1, 10000):
+            data.append((i, ))
+        self.input_table = self.t_env.from_data_stream(
+            self.env.from_collection(
+                data,
+                type_info=Types.ROW_NAMED(
+                    ['f0', ],
+                    [Types.INT(), ])))
+
+    def test_param(self):
+        splitter = RandomSplitter()
+        splitter.set_weights(0.2, 0.8)
+        self.assertEqual(0.2, splitter.weights[0])
+        self.assertEqual(0.8, splitter.weights[1])
+
+    def test_output_schema(self):
+        splitter = RandomSplitter()
+        input_data_table = self.t_env.from_data_stream(
+            self.env.from_collection([
+                ('', ''),
+            ],
+                type_info=Types.ROW_NAMED(
+                    ['test_input', 'dummy_input'],
+                    [Types.STRING(), Types.STRING()])))
+        output = splitter.set_weights(0.5, 0.5) \
+            .transform(input_data_table)[0]
+
+        self.assertEqual(
+            ['test_input', 'dummy_input'],
+            output.get_schema().get_field_names())
+
+    def test_fit_and_predict(self):

Review Comment:
   Let's update the function name as `test_transform`.



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

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org