You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "lindong28 (via GitHub)" <gi...@apache.org> on 2023/04/16 16:11:09 UTC

[GitHub] [flink-ml] lindong28 commented on a diff in pull request #216: [Flink-31173] Fix serveral iteration bugs

lindong28 commented on code in PR #216:
URL: https://github.com/apache/flink-ml/pull/216#discussion_r1167966461


##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedPerRoundCheckpointITCase.java:
##########
@@ -106,7 +106,7 @@ public void testFailoverAndRestore() throws Exception {
             }
 
             // 0 ~ 4 round and termination information
-            assertEquals(4, roundsStat.size());
+            assertEquals(5, roundsStat.size());

Review Comment:
   Can you help explain why it should be the expected result according to the Iteration API semantics?



##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/proxy/state/ProxyOperatorStateBackend.java:
##########
@@ -58,12 +62,24 @@ public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> st
         return wrappedBackend.getBroadcastState(newDescriptor);
     }
 
+    private <S> TypeInformation<S> getTypeInfo(ListStateDescriptor<S> stateDescriptor)
+            throws Exception {
+        Field f = StateDescriptor.class.getDeclaredField("typeInfo");
+        f.setAccessible(true);
+        return ((ListTypeInfo) f.get(stateDescriptor)).getElementTypeInfo();
+    }
+
     @Override
     public <S> ListState<S> getListState(ListStateDescriptor<S> stateDescriptor) throws Exception {
         ListStateDescriptor<S> newDescriptor =
-                new ListStateDescriptor<>(
-                        stateNamePrefix.prefix(stateDescriptor.getName()),
-                        stateDescriptor.getElementSerializer());
+                stateDescriptor.isSerializerInitialized()

Review Comment:
   Does `getUnionListState()` also need to check this?



##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedTailOperatorWithUnionInputIterationITCase.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.test.iteration;
+
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/** Tests the case that Tail operator contains multiple inputs. */
+public class BoundedTailOperatorWithUnionInputIterationITCase {
+
+    @Test
+    public void testTailOperatorWithUnionInput() {
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+        DataStream<Long> input1 = env.fromSequence(0, 10);
+        DataStream<Long> input2 = env.fromSequence(0, 10);
+        String expectedErrorMessage =
+                "Tail operator should have only one input. Please check whether operator "
+                        + "\"Union\" contains multiple inputs.";
+
+        try {
+            Iterations.iterateBoundedStreamsUntilTermination(
+                    DataStreamList.of(input1),
+                    ReplayableDataStreamList.replay(input2),
+                    new IterationConfig(OperatorLifeCycle.PER_ROUND),
+                    new IterationBodyWithUnionAsFeedback());
+        } catch (UnsupportedOperationException e) {
+            assertEquals(expectedErrorMessage, e.getMessage());
+        }
+    }
+
+    private static class IterationBodyWithUnionAsFeedback implements IterationBody {
+
+        @Override
+        public IterationBodyResult process(
+                DataStreamList variableStreams, DataStreamList dataStreams) {
+
+            DataStream<Long> variableStream = variableStreams.get(0);
+            DataStream<Long> constantStream = dataStreams.get(0);
+            DataStream<Integer> terminationCriteria =
+                    constantStream.flatMap(new TerminateOnMaxIter<>(3));
+            return new IterationBodyResult(
+                    DataStreamList.of(variableStream.union(constantStream)),

Review Comment:
   The program seems semantically correct: it wants to use the union of "the constant input and the feedack stream" as the feedback stream in the next iteration.
   
   Can you explain why we should not support programs like this?
   
   And if we do need this it, would it be simpler to move it to `BoundedPerRoundStreamIterationITCase#testPerRoundIterationWithUnion`?



##########
flink-ml-tests/src/test/java/org/apache/flink/test/iteration/BoundedIterationWithBroadcastITCase.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.test.iteration;
+
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.iteration.DataStreamList;
+import org.apache.flink.iteration.IterationBody;
+import org.apache.flink.iteration.IterationBodyResult;
+import org.apache.flink.iteration.IterationConfig;
+import org.apache.flink.iteration.IterationConfig.OperatorLifeCycle;
+import org.apache.flink.iteration.Iterations;
+import org.apache.flink.iteration.ReplayableDataStreamList;
+import org.apache.flink.ml.common.broadcast.BroadcastUtils;
+import org.apache.flink.ml.common.iteration.TerminateOnMaxIter;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.minicluster.MiniCluster;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.testutils.junit.SharedObjects;
+import org.apache.flink.testutils.junit.SharedReference;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.apache.flink.test.iteration.UnboundedStreamIterationITCase.createMiniClusterConfiguration;
+import static org.junit.Assert.assertEquals;
+
+/** Tests using {@link BroadcastUtils#withBroadcastStream} in iterations. */
+public class BoundedIterationWithBroadcastITCase extends TestLogger {
+
+    @Rule public final SharedObjects sharedObjects = SharedObjects.create();
+
+    private MiniCluster miniCluster;
+
+    private SharedReference<BlockingQueue<Long>> result;
+
+    @Before
+    public void setup() throws Exception {
+        miniCluster = new MiniCluster(createMiniClusterConfiguration(1, 1));
+        miniCluster.start();
+
+        result = sharedObjects.add(new LinkedBlockingQueue<>());
+    }
+
+    @After
+    public void teardown() throws Exception {
+        if (miniCluster != null) {
+            miniCluster.close();
+        }
+    }
+
+    @Test
+    public void testIterationWithBroadcastJobGraph() throws Exception {

Review Comment:
   Can you help explain why `ListStateDescriptor` is not initialized in this test but initialized in other tests?



##########
flink-ml-iteration/src/main/java/org/apache/flink/iteration/proxy/state/ProxyOperatorStateBackend.java:
##########
@@ -58,12 +62,24 @@ public <K, V> BroadcastState<K, V> getBroadcastState(MapStateDescriptor<K, V> st
         return wrappedBackend.getBroadcastState(newDescriptor);
     }
 
+    private <S> TypeInformation<S> getTypeInfo(ListStateDescriptor<S> stateDescriptor)
+            throws Exception {
+        Field f = StateDescriptor.class.getDeclaredField("typeInfo");

Review Comment:
   It is probably more readable to use `ReflectionUtils` in a way similar to `OutputReflectionContext`.



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