WencongLiu commented on code in PR #13890:
URL: https://github.com/apache/flink/pull/13890#discussion_r1387456047


##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/BatchGroupedReduceOperator.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.streaming.api.operators;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.ReduceFunction;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.state.ValueStateDescriptor;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.runtime.state.VoidNamespace;
+import org.apache.flink.runtime.state.VoidNamespaceSerializer;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/**
+ * A {@link StreamOperator} for executing a {@link ReduceFunction} on a
+ * {@link org.apache.flink.streaming.api.datastream.KeyedStream} in a
+ * {@link RuntimeExecutionMode#BATCH} mode.
+ */
+@Internal
+public class BatchGroupedReduceOperator<IN, KEY>
+               extends AbstractUdfStreamOperator<IN, ReduceFunction<IN>>
+               implements OneInputStreamOperator<IN, IN>, Triggerable<KEY, 
VoidNamespace> {
+
+       private static final long serialVersionUID = 1L;
+
+       private static final String STATE_NAME = "_op_state";
+
+       private transient ValueState<IN> values;
+
+       private final TypeSerializer<IN> serializer;
+
+       private InternalTimerService<VoidNamespace> timerService;
+
+       public BatchGroupedReduceOperator(ReduceFunction<IN> reducer, 
TypeSerializer<IN> serializer) {
+               super(reducer);
+               this.serializer = serializer;
+       }
+
+       @Override
+       public void open() throws Exception {
+               super.open();
+               ValueStateDescriptor<IN> stateId = new 
ValueStateDescriptor<>(STATE_NAME, serializer);
+               values = getPartitionedState(stateId);

Review Comment:
   Thanks for the great work on this. @dawidwys 
   I have a question about the implementation of `BatchGroupedReduceOperator`.  
Why we store the last reduced record by the state 
from`getPartitionedState(stateId)`? Could we just use a variable in a class?
   
   In the situation of batch processing, `BatchExecutionKeyValueState` could 
provide the ability to get value by namespace. But this functionality is not 
needed by Reduce. WDYT? 🤔️



##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/BatchGroupedReduceOperator.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.streaming.api.operators;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.ReduceFunction;
+import org.apache.flink.api.common.state.ValueState;
+import org.apache.flink.api.common.state.ValueStateDescriptor;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.runtime.state.VoidNamespace;
+import org.apache.flink.runtime.state.VoidNamespaceSerializer;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/**
+ * A {@link StreamOperator} for executing a {@link ReduceFunction} on a
+ * {@link org.apache.flink.streaming.api.datastream.KeyedStream} in a
+ * {@link RuntimeExecutionMode#BATCH} mode.
+ */
+@Internal
+public class BatchGroupedReduceOperator<IN, KEY>
+               extends AbstractUdfStreamOperator<IN, ReduceFunction<IN>>
+               implements OneInputStreamOperator<IN, IN>, Triggerable<KEY, 
VoidNamespace> {
+
+       private static final long serialVersionUID = 1L;
+
+       private static final String STATE_NAME = "_op_state";
+
+       private transient ValueState<IN> values;
+
+       private final TypeSerializer<IN> serializer;
+
+       private InternalTimerService<VoidNamespace> timerService;
+
+       public BatchGroupedReduceOperator(ReduceFunction<IN> reducer, 
TypeSerializer<IN> serializer) {
+               super(reducer);
+               this.serializer = serializer;
+       }
+
+       @Override
+       public void open() throws Exception {
+               super.open();
+               ValueStateDescriptor<IN> stateId = new 
ValueStateDescriptor<>(STATE_NAME, serializer);
+               values = getPartitionedState(stateId);

Review Comment:
   Thanks for the great work on this. @dawidwys 
   I have a question about the implementation of `BatchGroupedReduceOperator`.  
Why we store the last reduced record by the state 
from`getPartitionedState(stateId)`? Could we just use a variable in a class?
   
   In the situation of batch processing, `BatchExecutionKeyValueState` could 
provide the ability to get value by namespace. But this functionality is not 
needed by Reduce. WDYT? 🤔️



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