aljoscha commented on a change in pull request #13890:
URL: https://github.com/apache/flink/pull/13890#discussion_r516021344



##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/BatchGroupedReduce.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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 BatchGroupedReduce<IN, KEY> extends AbstractUdfStreamOperator<IN, 
ReduceFunction<IN>>

Review comment:
       So far we have mostly (or always? 🤔) kept `Operator` in the name somehow 
for newer operators. For example: `BatchGroupedReduceOperator`.

##########
File path: 
flink-tests/src/test/java/org/apache/flink/test/streaming/runtime/ReduceITCase.java
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.streaming.runtime;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.ReduceFunction;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.KeyedStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.util.CloseableIterator;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link KeyedStream#reduce(ReduceFunction)}.
+ */
+public class ReduceITCase extends AbstractTestBase {
+       @Test
+       public void testStreamReduce() throws Exception {
+               StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+               env.setParallelism(1);
+               Configuration conf = new Configuration();
+               conf.set(ExecutionOptions.RUNTIME_MODE, 
RuntimeExecutionMode.STREAMING);
+               env.configure(conf, this.getClass().getClassLoader());
+               DataStreamSource<Long> numbers = env
+                       .fromSequence(0, 10);
+
+               // send all records into a single reducer
+               KeyedStream<Long, Long> stream = numbers.keyBy(i -> i % 2);
+               DataStream<Long> sums = stream.reduce(
+                       Long::sum
+               );
+
+               try (CloseableIterator<Long> sumsIterator = 
sums.executeAndCollect()) {
+                       List<Long> results = 
CollectionUtil.iteratorToList(sumsIterator);
+                       assertThat(results, equalTo(Arrays.asList(
+                               0L, 1L, 2L, 4L, 6L, 9L, 12L, 16L, 20L, 25L, 30L
+                       )));
+               }
+       }
+
+       @Test
+       public void testBatchReduce() throws Exception {

Review comment:
       Maybe we should add this to the `DataStreamBatchExecutionITCase` that 
I'm introducing in #13891. But we should at least not choose `ReduceITCase` 
because there's already too many classes with that name... 😅

##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/BatchGroupedReduce.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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 BatchGroupedReduce<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";

Review comment:
       It's good to keep the same name! Just in case we _ever_ want to do some 
batch/streaming/savepoint interop business.




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


Reply via email to