weibozhao commented on a change in pull request #24:
URL: https://github.com/apache/flink-ml/pull/24#discussion_r765478425



##########
File path: 
flink-ml-lib/src/test/java/org/apache/flink/ml/classification/knn/KnnTest.java
##########
@@ -0,0 +1,273 @@
+package org.apache.flink.ml.classification.knn;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.DenseMatrix;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import 
org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Schema;
+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.commons.collections.IteratorUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests Knn and KnnModel. */
+public class KnnTest {
+    private StreamExecutionEnvironment env;
+    private StreamTableEnvironment tEnv;
+    private Table trainData;
+    private static final String LABEL_COL = "test_label";
+    private static final String PRED_COL = "test_prediction";
+    private static final String VEC_COL = "test_features";
+    private static final List<Row> trainArray =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(1, Vectors.dense(2.0, 3.0)),
+                            Row.of(1, Vectors.dense(2.1, 3.1)),
+                            Row.of(2, Vectors.dense(200.1, 300.1)),
+                            Row.of(2, Vectors.dense(200.2, 300.2)),
+                            Row.of(2, Vectors.dense(200.3, 300.3)),
+                            Row.of(2, Vectors.dense(200.4, 300.4)),
+                            Row.of(2, Vectors.dense(200.4, 300.4)),
+                            Row.of(2, Vectors.dense(200.6, 300.6)),
+                            Row.of(1, Vectors.dense(2.1, 3.1)),
+                            Row.of(1, Vectors.dense(2.1, 3.1)),
+                            Row.of(1, Vectors.dense(2.1, 3.1)),
+                            Row.of(1, Vectors.dense(2.1, 3.1)),
+                            Row.of(1, Vectors.dense(2.3, 3.2)),
+                            Row.of(1, Vectors.dense(2.3, 3.2)),
+                            Row.of(3, Vectors.dense(2.8, 3.2)),
+                            Row.of(4, Vectors.dense(300., 3.2)),
+                            Row.of(1, Vectors.dense(2.2, 3.2)),
+                            Row.of(5, Vectors.dense(2.4, 3.2)),
+                            Row.of(5, Vectors.dense(2.5, 3.2)),
+                            Row.of(5, Vectors.dense(2.5, 3.2)),
+                            Row.of(1, Vectors.dense(2.1, 3.1))));
+
+    private static final List<Row> testArray =
+            new ArrayList<>(
+                    Arrays.asList(
+                            Row.of(5, Vectors.dense(4.0, 4.1)), Row.of(2, 
Vectors.dense(300, 42))));
+    private Table testData;
+
+    @Before
+    public void before() {
+        Configuration config = new Configuration();
+        
config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, 
true);
+        env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.setParallelism(4);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        tEnv = StreamTableEnvironment.create(env);
+
+        Schema schema =
+                Schema.newBuilder()
+                        .column("f0", DataTypes.INT())
+                        .column("f1", DataTypes.of(DenseVector.class))
+                        .build();
+
+        DataStream<Row> dataStream = env.fromCollection(trainArray);
+        trainData = tEnv.fromDataStream(dataStream, schema).as(LABEL_COL + "," 
+ VEC_COL);

Review comment:
       OK




-- 
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-unsubscr...@flink.apache.org

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


Reply via email to