flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] xuyang1706 commented on a change in pull request #9413: [FLINK-13676][ml] Add class of Vector to Columns mapper
Date Thu, 16 Jan 2020 09:57:29 GMT
xuyang1706 commented on a change in pull request #9413: [FLINK-13676][ml] Add class of Vector
to Columns mapper
URL: https://github.com/apache/flink/pull/9413#discussion_r367326208
 
 

 ##########
 File path: flink-ml-parent/flink-ml-lib/src/test/java/org/apache/flink/ml/common/dataproc/vector/VectorToColumnsMapperTest.java
 ##########
 @@ -0,0 +1,101 @@
+/*
+ * 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.dataproc.vector;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.ml.api.misc.param.Params;
+import org.apache.flink.ml.common.linalg.DenseVector;
+import org.apache.flink.ml.common.linalg.SparseVector;
+import org.apache.flink.ml.common.utils.RowCollector;
+import org.apache.flink.ml.params.dataproc.vector.VectorToColumnsParams;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.types.Row;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit test for VectorToColumnsMapper.
+ */
+public class VectorToColumnsMapperTest {
+	@Test
+	public void test1() throws Exception {
+		TableSchema schema = new TableSchema(new String[]{"vec"}, new TypeInformation<?>[]{Types.STRING});
+
+		Params params = new Params()
+			.set(VectorToColumnsParams.SELECTED_COL, "vec")
+			.set(VectorToColumnsParams.OUTPUT_COLS, new String[]{"f0", "f1"});
+
+		VectorToColumnsMapper mapper = new VectorToColumnsMapper(schema, params);
+		RowCollector collector = new RowCollector();
+		mapper.flatMap(Row.of(new DenseVector(new double[]{3.0, 4.0})), collector);
+		List<Row> rows = collector.getRows();
+		assertEquals(rows.get(0).getField(1), 3.0);
+		assertEquals(rows.get(0).getField(2), 4.0);
+		assertEquals(mapper.getOutputSchema(), new TableSchema(new String[]{"vec", "f0", "f1"},
+			new TypeInformation<?>[]{Types.STRING, Types.DOUBLE, Types.DOUBLE}));
+
+	}
+
+	@Test
+	public void test2() throws Exception {
 
 Review comment:
   Thanks, renamed the test case.

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


With regards,
Apache Git Services

Mime
View raw message