lindong28 commented on code in PR #230: URL: https://github.com/apache/flink-ml/pull/230#discussion_r1163453972
########## flink-ml-core/src/test/java/org/apache/flink/ml/common/datastream/DataStreamUtilsTest.java: ########## @@ -59,6 +64,54 @@ public void testMapPartition() throws Exception { new int[] {5, 5, 5, 5}, counts.stream().mapToInt(Integer::intValue).toArray()); } + @Test + public void testCoGroup() throws Exception { + DataStream<Tuple2<Integer, Integer>> data1 = + env.fromCollection( + Arrays.asList(Tuple2.of(1, 1), Tuple2.of(2, 2), Tuple2.of(3, 3))); + DataStream<Tuple2<Integer, Double>> data2 = + env.fromCollection( + Arrays.asList( + Tuple2.of(1, 1.5), + Tuple2.of(5, 5.5), + Tuple2.of(3, 3.5), + Tuple2.of(1, 2.5))); + DataStream<Double> result = + DataStreamUtils.coGroup( + data1, + data2, + (KeySelector<Tuple2<Integer, Integer>, Integer>) tuple -> tuple.f0, + (KeySelector<Tuple2<Integer, Double>, Integer>) tuple -> tuple.f0, + BasicTypeInfo.DOUBLE_TYPE_INFO, + new CoGroupFunction< + Tuple2<Integer, Integer>, Tuple2<Integer, Double>, Double>() { + @Override + public void coGroup( + Iterable<Tuple2<Integer, Integer>> iterableA, + Iterable<Tuple2<Integer, Double>> iterableB, + Collector<Double> collector) { + List<Tuple2<Integer, Integer>> valuesA = + IteratorUtils.toList(iterableA.iterator()); + List<Tuple2<Integer, Double>> valuesB = + IteratorUtils.toList(iterableB.iterator()); + + double sum = 0; + for (Tuple2<Integer, Integer> value : valuesA) { + sum += value.f1; + } + for (Tuple2<Integer, Double> value : valuesB) { + sum += value.f1; + } + collector.collect(sum); + } + }); + + List<Double> resultValues = IteratorUtils.toList(result.executeAndCollect()); + double[] resultPrimitiveValues = + resultValues.stream().mapToDouble(Double::doubleValue).toArray(); + assertArrayEquals(new double[] {5.0, 2.0, 6.5, 5.5}, resultPrimitiveValues, 1e-5); Review Comment: Yes, I think this assert should always work. Can you explain why the result of this particular co-group does not preserve order? Note that `StreamExecutionEnvironment#fromCollection` returns a DataStream with parallelism=1. And therefore the co-group operator is executed with parallelism=1. -- 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