yunfengzhou-hub commented on a change in pull request #8:
URL: https://github.com/apache/flink-ml/pull/8#discussion_r725457783



##########
File path: 
flink-ml-iteration/src/main/java/org/apache/flink/ml/iteration/proxy/ProxyOutput.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.iteration.proxy;
+
+import org.apache.flink.ml.iteration.IterationRecord;
+import org.apache.flink.ml.iteration.typeinfo.IterationRecordTypeInfo;
+import org.apache.flink.streaming.api.operators.Output;
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.LatencyMarker;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.util.OutputTag;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/** Proxy output to provide to the wrapped operator. */
+public class ProxyOutput<T> implements Output<StreamRecord<T>> {
+
+    private final Output<StreamRecord<IterationRecord<T>>> output;
+
+    private final StreamRecord<IterationRecord<T>> reuseRecord;
+
+    private final Map<String, SideOutputCache> sideOutputCaches = new 
HashMap<>();
+
+    private Integer contextRound;
+
+    public ProxyOutput(Output<StreamRecord<IterationRecord<T>>> output) {
+        this.output = Objects.requireNonNull(output);
+        this.reuseRecord = new StreamRecord<>(IterationRecord.newRecord(null, 
0));
+    }
+
+    public void setContextRound(Integer contextRound) {
+        this.contextRound = contextRound;
+    }
+
+    @Override
+    public void emitWatermark(Watermark mark) {
+        output.emitWatermark(mark);
+    }
+
+    @Override
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    public <X> void collect(OutputTag<X> outputTag, StreamRecord<X> record) {
+        SideOutputCache sideOutputCache =
+                sideOutputCaches.computeIfAbsent(
+                        outputTag.getId(),
+                        (ignored) ->
+                                new SideOutputCache(
+                                        new OutputTag<IterationRecord<?>>(
+                                                outputTag.getId(),
+                                                new IterationRecordTypeInfo(
+                                                        
outputTag.getTypeInfo())),
+                                        new 
StreamRecord<>(IterationRecord.newRecord(null, 0))));
+        sideOutputCache.cachedRecord.replace(
+                IterationRecord.newRecord(record.getValue(), contextRound), 
record.getTimestamp());
+        output.collect(sideOutputCache.tag, sideOutputCache.cachedRecord);
+    }
+
+    @Override
+    public void emitLatencyMarker(LatencyMarker latencyMarker) {
+        output.emitLatencyMarker(latencyMarker);
+    }
+
+    @Override
+    public void collect(StreamRecord<T> tStreamRecord) {
+        reuseRecord.getValue().setValue(tStreamRecord.getValue());
+        reuseRecord.getValue().setRound(contextRound);

Review comment:
       The round or epoch of a record does not increase when it finishes a loop 
and returns to `HeadOperator`. Instead, it increases in this `ProxyOutput` with 
`contextRound`, whose value equals to epoch watermark. What is the 
consideration of this design choice over the other?
   
   From my perspective, If the round of a record always equals to the previous 
epoch watermark, it might be unnecessary to assign `round` to each record. 
Operators inside the iteration could keep a context of the current round and 
make it the default round value for the incoming records.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to