You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "reswqa (via GitHub)" <gi...@apache.org> on 2024/03/01 07:16:33 UTC

[PR] [FLINK-xxxxx][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

reswqa opened a new pull request, #24422:
URL: https://github.com/apache/flink/pull/24422

   ## What is the purpose of the change
   
   *This is the first PR for DataStream V2, and aim to  implement FLIP-409: DataStream V2 Building Blocks: DataStream, Partitioning and ProcessFunction *
   
   
   ## Brief change log
   
     - *Introduce four type of `streams` in FLIP-409.*
     - *Introduce `ProcessFunction` and all it's variants. *
     - *Introduce new `ExecutionEnvironment` to submit job written in the new API.*
     - *Supports FLIP-27 based `Source` and `Sink-v2`*
   
   
   ## Verifying this change
   
   This change added new tests.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? yes
     - Documentation needs to be added in subsequent PR.
   


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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1528192344


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/BroadcastStream.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+
+/** This interface represents a stream that each parallel task processes the same data. */
+@Experimental
+public interface BroadcastStream<T> {
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * @param other {@link KeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <K, T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            KeyedPartitionStream<K, T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link NonKeyedPartitionStream}.
+     *
+     * @param other {@link NonKeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            NonKeyedPartitionStream<T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * <p>This method is used to avoid shuffle after applying the process function. It is required
+     * that for the record from non-broadcast input, the new {@link KeySelector} must extract the
+     * same key as the original {@link KeySelector}s on the {@link KeyedPartitionStream}. For the
+     * record from broadcast input, the output key from keyed partition itself instead of new key
+     * selector, so it is safe already.

Review Comment:
   Updated.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527986902


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/operators/ProcessOperator.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.process.impl.operators;
+
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.impl.common.OutputCollector;
+import org.apache.flink.process.impl.common.TimestampCollector;
+import org.apache.flink.process.impl.context.DefaultNonPartitionedContext;
+import org.apache.flink.process.impl.context.DefaultRuntimeContext;
+import org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/** Operator for {@link OneInputStreamProcessFunction}. */
+public class ProcessOperator<IN, OUT>
+        extends AbstractUdfStreamOperator<OUT, OneInputStreamProcessFunction<IN, OUT>>
+        implements OneInputStreamOperator<IN, OUT>, BoundedOneInput {
+
+    protected transient DefaultRuntimeContext context;
+
+    protected transient DefaultNonPartitionedContext<OUT> nonPartitionedContext;
+
+    protected transient TimestampCollector<OUT> outputCollector;
+
+    public ProcessOperator(OneInputStreamProcessFunction<IN, OUT> userFunction) {
+        super(userFunction);
+
+        chainingStrategy = ChainingStrategy.ALWAYS;

Review Comment:
   After discussing it offline, I think setting it to ALWAYS is also acceptable, since ALWAYS is the default anyway.



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


Re: [PR] [FLINK-xxxxx][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #24422:
URL: https://github.com/apache/flink/pull/24422#issuecomment-1972653582

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "cb4615792281b375a45da41795e9f1a0cd70ae2d",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "cb4615792281b375a45da41795e9f1a0cd70ae2d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * cb4615792281b375a45da41795e9f1a0cd70ae2d UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1542480801


##########
flink-core/src/main/java/org/apache/flink/api/connector/dsv2/DataStreamV2SourceUtils.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.api.connector.dsv2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to create the DataStream V2 supported {@link Source}. */
+@Experimental
+public final class DataStreamV2SourceUtils {
+    /**
+     * Wrap a FLIP-27 based source to a DataStream V2 supported source.
+     *
+     * @param source The FLIP-27 based source to wrap.
+     * @return The DataStream V2 supported source.
+     */
+    public static <T> Source<T> wrapSource(

Review Comment:
   It is a only user-facing API that is not called by other functions. But yes, I have introduced a new test to cover this.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "Sxnan (via GitHub)" <gi...@apache.org>.
Sxnan commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1540748320


##########
flink-datastream-api/src/main/java/org/apache/flink/datastream/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.datastream.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getInstance() throws ReflectiveOperationException {

Review Comment:
   This should be `getExecutionEnvironment` according to the FLIP.



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentFactory.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * 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.datastream.impl;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.datastream.api.ExecutionEnvironment;
+
+/** Factory class for execution environments. */
+@FunctionalInterface
+public interface ExecutionEnvironmentFactory {
+    /**
+     * Creates a StreamExecutionEnvironment from this factory.
+     *
+     * @return A StreamExecutionEnvironment.

Review Comment:
   `StreamExecutionEnvironment` should be `ExecutionEnvironment`



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/common/TimestampCollector.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.datastream.impl.common;
+
+import org.apache.flink.datastream.api.common.Collector;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/** The base {@link Collector} which take care of records timestamp. */
+public abstract class TimestampCollector<OUT> implements Collector<OUT> {
+    protected final StreamRecord<OUT> reuse = new StreamRecord<>(null);
+
+    public void setTimestamp(StreamRecord<?> timestampBase) {
+        if (timestampBase.hasTimestamp()) {
+            setAbsoluteTimestamp(timestampBase.getTimestamp());
+        } else {
+            eraseTimestamp();
+        }
+    }
+
+    public void setAbsoluteTimestamp(long timestamp) {

Review Comment:
   The name `absoluteTimestamp` is a little bit confusing to me. Maybe just name it `setTimestamp`. 
   
   And we may rename the `setTimestamp(StreamRecord)` to something like `setTiemstampFromStreamRecord`. 



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.datastream.impl.operators;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.impl.common.OutputCollector;
+import org.apache.flink.datastream.impl.common.TimestampCollector;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.OutputTag;
+
+import javax.annotation.Nullable;
+
+/** */
+public class KeyedTwoOutputProcessOperator<KEY, IN, OUT_MAIN, OUT_SIDE>
+        extends TwoOutputProcessOperator<IN, OUT_MAIN, OUT_SIDE> {
+
+    @Nullable private final KeySelector<OUT_MAIN, KEY> mainOutKeySelector;
+
+    @Nullable private final KeySelector<OUT_SIDE, KEY> sideOutKeySelector;
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag) {
+        this(userFunction, outputTag, null, null);
+    }
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag,
+            @Nullable KeySelector<OUT_MAIN, KEY> mainOutKeySelector,
+            @Nullable KeySelector<OUT_SIDE, KEY> sideOutKeySelector) {
+        super(userFunction, outputTag);
+        this.mainOutKeySelector = mainOutKeySelector;
+        this.sideOutKeySelector = sideOutKeySelector;
+    }
+
+    @Override
+    protected TimestampCollector<OUT_MAIN> getMainCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(new OutputCollector<>(output), mainOutKeySelector)
+                : new OutputCollector<>(output);
+    }
+
+    @Override
+    public TimestampCollector<OUT_SIDE> getSideCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(
+                        new SideOutputCollector(output), sideOutKeySelector)
+                : new SideOutputCollector(output);
+    }
+
+    private class KeyCheckedOutputCollector<T> extends TimestampCollector<T> {

Review Comment:
   Can we reuse the `org.apache.flink.datastream.impl.common.KeyCheckedOutputCollector`?



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionContextEnvironment.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.datastream.impl;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.datastream.api.ExecutionEnvironment;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Special {@link ExecutionEnvironment} that will be used in cases where the CLI client or testing
+ * utilities create a {@link ExecutionEnvironment} that should be used when {@link
+ * ExecutionEnvironment#getInstance()} ()} is called.
+ */
+public class ExecutionContextEnvironment extends ExecutionEnvironmentImpl {
+    private final boolean suppressSysout;
+
+    private final boolean enforceSingleJobExecution;
+    private final Configuration clusterConfiguration;
+
+    private final boolean programConfigEnabled;
+    private final Collection<String> programConfigWildcards;

Review Comment:
   Currently, none of these are used. Do we have a plan to use these fields? Or should we add them when they are needed in the future?



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.datastream.impl.operators;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.impl.common.OutputCollector;
+import org.apache.flink.datastream.impl.common.TimestampCollector;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.OutputTag;
+
+import javax.annotation.Nullable;
+
+/** */
+public class KeyedTwoOutputProcessOperator<KEY, IN, OUT_MAIN, OUT_SIDE>
+        extends TwoOutputProcessOperator<IN, OUT_MAIN, OUT_SIDE> {
+
+    @Nullable private final KeySelector<OUT_MAIN, KEY> mainOutKeySelector;
+
+    @Nullable private final KeySelector<OUT_SIDE, KEY> sideOutKeySelector;
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag) {
+        this(userFunction, outputTag, null, null);
+    }
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag,
+            @Nullable KeySelector<OUT_MAIN, KEY> mainOutKeySelector,
+            @Nullable KeySelector<OUT_SIDE, KEY> sideOutKeySelector) {
+        super(userFunction, outputTag);
+        this.mainOutKeySelector = mainOutKeySelector;
+        this.sideOutKeySelector = sideOutKeySelector;
+    }
+
+    @Override
+    protected TimestampCollector<OUT_MAIN> getMainCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null

Review Comment:
   IIUC, we require that the two key selectors must be both null or both not-null. Should we check that?



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionContextEnvironment.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.datastream.impl;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.datastream.api.ExecutionEnvironment;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Special {@link ExecutionEnvironment} that will be used in cases where the CLI client or testing
+ * utilities create a {@link ExecutionEnvironment} that should be used when {@link
+ * ExecutionEnvironment#getInstance()} ()} is called.
+ */
+public class ExecutionContextEnvironment extends ExecutionEnvironmentImpl {
+    private final boolean suppressSysout;
+
+    private final boolean enforceSingleJobExecution;
+    private final Configuration clusterConfiguration;
+
+    private final boolean programConfigEnabled;
+    private final Collection<String> programConfigWildcards;
+
+    public ExecutionContextEnvironment(

Review Comment:
   The constructor is not used. Maybe we can remove it to keep it simple.



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/stream/KeyedPartitionStreamImpl.java:
##########
@@ -0,0 +1,389 @@
+/*
+ * 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.datastream.impl.stream;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.api.stream.BroadcastStream;
+import org.apache.flink.datastream.api.stream.GlobalStream;
+import org.apache.flink.datastream.api.stream.KeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+import org.apache.flink.datastream.impl.operators.KeyedProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputNonBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoOutputProcessOperator;
+import org.apache.flink.datastream.impl.stream.NonKeyedPartitionStreamImpl.TwoNonKeyedPartitionStreamsImpl;
+import org.apache.flink.datastream.impl.utils.StreamUtils;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner;
+import org.apache.flink.util.OutputTag;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link KeyedPartitionStream}. */
+public class KeyedPartitionStreamImpl<K, V> extends AbstractDataStream<V>
+        implements KeyedPartitionStream<K, V> {
+
+    /**
+     * The key selector that can get the key by which the stream if partitioned from the elements.
+     */
+    private final KeySelector<V, K> keySelector;
+
+    /** The type of the key by which the stream is partitioned. */
+    private final TypeInformation<K> keyType;
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream, KeySelector<V, K> keySelector) {
+        this(
+                dataStream,
+                keySelector,
+                TypeExtractor.getKeySelectorTypes(keySelector, dataStream.getType()));
+    }
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        this(
+                dataStream,
+                new PartitionTransformation<>(
+                        dataStream.getTransformation(),
+                        new KeyGroupStreamPartitioner<>(
+                                keySelector,
+                                StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM)),
+                keySelector,
+                keyType);
+    }
+
+    /**
+     * This can construct a keyed stream directly without partitionTransformation to avoid shuffle.
+     */
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            Transformation<V> partitionTransformation,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        super(dataStream.getEnvironment(), partitionTransformation);
+        this.keySelector = keySelector;
+        this.keyType = keyType;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction) {
+        TypeInformation<OUT> outType;
+        outType = StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+
+        KeyedProcessOperator<K, V, OUT> operator = new KeyedProcessOperator<>(processFunction);
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        environment.addOperator(transform);
+        return new NonKeyedPartitionStreamImpl<>(environment, transform);
+    }
+
+    @Override
+    public <OUT> KeyedPartitionStream<K, OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction,
+            KeySelector<OUT, K> newKeySelector) {
+        TypeInformation<OUT> outType =
+                StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+        KeyedProcessOperator<K, V, OUT> operator =
+                new KeyedProcessOperator<>(processFunction, checkNotNull(newKeySelector));
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        NonKeyedPartitionStreamImpl<OUT> outputStream =
+                new NonKeyedPartitionStreamImpl<>(environment, transform);
+        environment.addOperator(transform);
+        // Construct a keyed stream directly without partitionTransformation to avoid shuffle.
+        return new KeyedPartitionStreamImpl<>(
+                outputStream,
+                transform,
+                newKeySelector,
+                TypeExtractor.getKeySelectorTypes(newKeySelector, outputStream.getType()));
+    }
+
+    @Override
+    public <OUT1, OUT2> TwoKeyedPartitionStreams<K, OUT1, OUT2> process(
+            TwoOutputStreamProcessFunction<V, OUT1, OUT2> processFunction,
+            KeySelector<OUT1, K> keySelector1,
+            KeySelector<OUT2, K> keySelector2) {
+        Tuple2<TypeInformation<OUT1>, TypeInformation<OUT2>> twoOutputType =
+                StreamUtils.getOutputTypesForTwoOutputProcessFunction(processFunction, getType());
+        TypeInformation<OUT1> firstOutputType = twoOutputType.f0;
+        TypeInformation<OUT2> secondTOutputType = twoOutputType.f1;
+        OutputTag<OUT2> secondOutputTag = new OutputTag<>("Second-Output", secondTOutputType);

Review Comment:
   We need to define the OutputTag as an anonymous inner class, i.e. `new OutputTag<>("Second-Output", secondTOutputType){}`. Maybe, we can reuse the same OutputTag for the second output of all the two-output operations.



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.datastream.impl.operators;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.impl.common.OutputCollector;
+import org.apache.flink.datastream.impl.common.TimestampCollector;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.OutputTag;
+
+import javax.annotation.Nullable;
+
+/** */
+public class KeyedTwoOutputProcessOperator<KEY, IN, OUT_MAIN, OUT_SIDE>
+        extends TwoOutputProcessOperator<IN, OUT_MAIN, OUT_SIDE> {
+
+    @Nullable private final KeySelector<OUT_MAIN, KEY> mainOutKeySelector;
+
+    @Nullable private final KeySelector<OUT_SIDE, KEY> sideOutKeySelector;
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag) {
+        this(userFunction, outputTag, null, null);
+    }
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag,
+            @Nullable KeySelector<OUT_MAIN, KEY> mainOutKeySelector,
+            @Nullable KeySelector<OUT_SIDE, KEY> sideOutKeySelector) {
+        super(userFunction, outputTag);
+        this.mainOutKeySelector = mainOutKeySelector;
+        this.sideOutKeySelector = sideOutKeySelector;
+    }
+
+    @Override
+    protected TimestampCollector<OUT_MAIN> getMainCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(new OutputCollector<>(output), mainOutKeySelector)
+                : new OutputCollector<>(output);
+    }
+
+    @Override
+    public TimestampCollector<OUT_SIDE> getSideCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(
+                        new SideOutputCollector(output), sideOutKeySelector)
+                : new SideOutputCollector(output);
+    }
+
+    private class KeyCheckedOutputCollector<T> extends TimestampCollector<T> {
+
+        private final TimestampCollector<T> outputCollector;
+
+        private final KeySelector<T, KEY> outputKeySelector;
+
+        private KeyCheckedOutputCollector(
+                TimestampCollector<T> outputCollector, KeySelector<T, KEY> outputKeySelector) {
+            this.outputCollector = outputCollector;
+            this.outputKeySelector = outputKeySelector;
+        }
+
+        @Override
+        public void collect(T outputRecord) {
+            checkOutputKey(outputRecord);
+            this.outputCollector.collect(outputRecord);
+        }
+
+        @Override
+        public void collectAndOverwriteTimestamp(T outputRecord, long timestamp) {
+            checkOutputKey(outputRecord);
+            this.outputCollector.collectAndOverwriteTimestamp(outputRecord, timestamp);
+        }
+
+        @SuppressWarnings("unchecked")
+        private void checkOutputKey(T outputRecord) {
+            try {
+                KEY currentKey = (KEY) getCurrentKey();
+                KEY outputKey = this.outputKeySelector.getKey(outputRecord);
+                if (!outputKey.equals(currentKey)) {
+                    throw new IllegalStateException(
+                            "Output key must equals to input key if you want the produced stream "
+                                    + "is keyed. ");
+                }
+            } catch (Exception e) {
+                // TODO Change Consumer to ThrowingConsumer.

Review Comment:
   I am not sure what the TODO means. 



##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/stream/KeyedPartitionStreamImpl.java:
##########
@@ -0,0 +1,389 @@
+/*
+ * 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.datastream.impl.stream;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.api.stream.BroadcastStream;
+import org.apache.flink.datastream.api.stream.GlobalStream;
+import org.apache.flink.datastream.api.stream.KeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+import org.apache.flink.datastream.impl.operators.KeyedProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputNonBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoOutputProcessOperator;
+import org.apache.flink.datastream.impl.stream.NonKeyedPartitionStreamImpl.TwoNonKeyedPartitionStreamsImpl;
+import org.apache.flink.datastream.impl.utils.StreamUtils;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner;
+import org.apache.flink.util.OutputTag;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link KeyedPartitionStream}. */
+public class KeyedPartitionStreamImpl<K, V> extends AbstractDataStream<V>
+        implements KeyedPartitionStream<K, V> {
+
+    /**
+     * The key selector that can get the key by which the stream if partitioned from the elements.
+     */
+    private final KeySelector<V, K> keySelector;
+
+    /** The type of the key by which the stream is partitioned. */
+    private final TypeInformation<K> keyType;
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream, KeySelector<V, K> keySelector) {
+        this(
+                dataStream,
+                keySelector,
+                TypeExtractor.getKeySelectorTypes(keySelector, dataStream.getType()));
+    }
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        this(
+                dataStream,
+                new PartitionTransformation<>(
+                        dataStream.getTransformation(),
+                        new KeyGroupStreamPartitioner<>(
+                                keySelector,
+                                StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM)),
+                keySelector,
+                keyType);
+    }
+
+    /**
+     * This can construct a keyed stream directly without partitionTransformation to avoid shuffle.
+     */
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            Transformation<V> partitionTransformation,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        super(dataStream.getEnvironment(), partitionTransformation);
+        this.keySelector = keySelector;
+        this.keyType = keyType;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction) {
+        TypeInformation<OUT> outType;
+        outType = StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+
+        KeyedProcessOperator<K, V, OUT> operator = new KeyedProcessOperator<>(processFunction);
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        environment.addOperator(transform);
+        return new NonKeyedPartitionStreamImpl<>(environment, transform);
+    }
+
+    @Override
+    public <OUT> KeyedPartitionStream<K, OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction,
+            KeySelector<OUT, K> newKeySelector) {
+        TypeInformation<OUT> outType =
+                StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+        KeyedProcessOperator<K, V, OUT> operator =
+                new KeyedProcessOperator<>(processFunction, checkNotNull(newKeySelector));
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        NonKeyedPartitionStreamImpl<OUT> outputStream =
+                new NonKeyedPartitionStreamImpl<>(environment, transform);
+        environment.addOperator(transform);
+        // Construct a keyed stream directly without partitionTransformation to avoid shuffle.

Review Comment:
   The only difference with the `process` without `keySelector` is that we construct a keyed stream directly. Maybe we can extract a common method to be reused by the two methods.
   
   Same for the other methods



##########
flink-core/src/main/java/org/apache/flink/api/connector/dsv2/DataStreamV2SourceUtils.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.api.connector.dsv2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to create the DataStream V2 supported {@link Source}. */
+@Experimental
+public final class DataStreamV2SourceUtils {
+    /**
+     * Wrap a FLIP-27 based source to a DataStream V2 supported source.
+     *
+     * @param source The FLIP-27 based source to wrap.
+     * @return The DataStream V2 supported source.
+     */
+    public static <T> Source<T> wrapSource(

Review Comment:
   The method is not used.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1542471491


##########
flink-datastream-api/src/main/java/org/apache/flink/datastream/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.datastream.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getInstance() throws ReflectiveOperationException {

Review Comment:
   By the previous review comments, we have renamed it and I will update the FLIP later.
   
   see: https://github.com/apache/flink/pull/24422#discussion_r1533208773
   
   



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "Sxnan (via GitHub)" <gi...@apache.org>.
Sxnan commented on PR #24422:
URL: https://github.com/apache/flink/pull/24422#issuecomment-2029246823

   @reswqa Thanks for the update. LGTM! 


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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535341354


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentFactory.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.process.api.ExecutionEnvironment;
+
+/** Factory class for execution environments. */
+@FunctionalInterface
+@Experimental

Review Comment:
   Good catch, fixed.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/stream/DataStream.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.process.impl.stream;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.process.impl.ExecutionEnvironmentImpl;
+import org.apache.flink.streaming.api.transformations.SideOutputTransformation;
+import org.apache.flink.util.OutputTag;
+import org.apache.flink.util.Preconditions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Base class for all streams.
+ *
+ * <p>Note: This is only used for internal implementation. It must not leak to user face api.
+ */
+@Internal

Review Comment:
   Fixed.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535339356


##########
pom.xml:
##########
@@ -2366,6 +2366,7 @@ under the License.
 								<exclude>org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#fromData(java.util.Collection)</exclude>
 								<exclude>org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#fromData(java.util.Collection,org.apache.flink.api.common.typeinfo.TypeInformation)</exclude>
 								<exclude>org.apache.flink.api.common.functions.RuntimeContext</exclude>
+								<exclude>org.apache.flink.api.common.functions.Function</exclude>

Review Comment:
   Good suggestion. I have created FLINK-34899 and FLINK-34900 to track this.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1543984976


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.datastream.impl.operators;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.impl.common.OutputCollector;
+import org.apache.flink.datastream.impl.common.TimestampCollector;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.OutputTag;
+
+import javax.annotation.Nullable;
+
+/** */
+public class KeyedTwoOutputProcessOperator<KEY, IN, OUT_MAIN, OUT_SIDE>
+        extends TwoOutputProcessOperator<IN, OUT_MAIN, OUT_SIDE> {
+
+    @Nullable private final KeySelector<OUT_MAIN, KEY> mainOutKeySelector;
+
+    @Nullable private final KeySelector<OUT_SIDE, KEY> sideOutKeySelector;
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag) {
+        this(userFunction, outputTag, null, null);
+    }
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag,
+            @Nullable KeySelector<OUT_MAIN, KEY> mainOutKeySelector,
+            @Nullable KeySelector<OUT_SIDE, KEY> sideOutKeySelector) {
+        super(userFunction, outputTag);
+        this.mainOutKeySelector = mainOutKeySelector;
+        this.sideOutKeySelector = sideOutKeySelector;
+    }
+
+    @Override
+    protected TimestampCollector<OUT_MAIN> getMainCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(new OutputCollector<>(output), mainOutKeySelector)
+                : new OutputCollector<>(output);
+    }
+
+    @Override
+    public TimestampCollector<OUT_SIDE> getSideCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(
+                        new SideOutputCollector(output), sideOutKeySelector)
+                : new SideOutputCollector(output);
+    }
+
+    private class KeyCheckedOutputCollector<T> extends TimestampCollector<T> {
+
+        private final TimestampCollector<T> outputCollector;
+
+        private final KeySelector<T, KEY> outputKeySelector;
+
+        private KeyCheckedOutputCollector(
+                TimestampCollector<T> outputCollector, KeySelector<T, KEY> outputKeySelector) {
+            this.outputCollector = outputCollector;
+            this.outputKeySelector = outputKeySelector;
+        }
+
+        @Override
+        public void collect(T outputRecord) {
+            checkOutputKey(outputRecord);
+            this.outputCollector.collect(outputRecord);
+        }
+
+        @Override
+        public void collectAndOverwriteTimestamp(T outputRecord, long timestamp) {
+            checkOutputKey(outputRecord);
+            this.outputCollector.collectAndOverwriteTimestamp(outputRecord, timestamp);
+        }
+
+        @SuppressWarnings("unchecked")
+        private void checkOutputKey(T outputRecord) {
+            try {
+                KEY currentKey = (KEY) getCurrentKey();
+                KEY outputKey = this.outputKeySelector.getKey(outputRecord);
+                if (!outputKey.equals(currentKey)) {
+                    throw new IllegalStateException(
+                            "Output key must equals to input key if you want the produced stream "
+                                    + "is keyed. ");
+                }
+            } catch (Exception e) {
+                // TODO Change Consumer to ThrowingConsumer.

Review Comment:
   Ai, I changed the implementation here, but forgot to remove TODO. 😓 



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa merged PR #24422:
URL: https://github.com/apache/flink/pull/24422


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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "Sxnan (via GitHub)" <gi...@apache.org>.
Sxnan commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1546006170


##########
flink-datastream-api/src/main/java/org/apache/flink/datastream/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.datastream.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getInstance() throws ReflectiveOperationException {

Review Comment:
   Sound good to me.



##########
flink-datastream-api/src/main/java/org/apache/flink/datastream/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.datastream.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getInstance() throws ReflectiveOperationException {

Review Comment:
   Sounds good to me.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527976069


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/function/ProcessFunction.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.process.api.function;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.functions.Function;
+
+/** Base class for all user defined process functions. */
+@Experimental
+public interface ProcessFunction extends Function {
+    /**
+     * Initialization method for the function. It is called before the actual working methods (like
+     * processRecord) and thus suitable for one time setup work.
+     *
+     * <p>By default, this method does nothing.
+     *
+     * @throws Exception Implementations may forward exceptions, which are caught by the runtime.
+     *     When the runtime catches an exception, it aborts the task and lets the fail-over logic
+     *     decide whether to retry the task execution.
+     */
+    default void open() throws Exception {}

Review Comment:
   Alright, if there is a need to add new parameters to the open method, we can do so when it's actually required, as all the newly added classes are currently at the @Experimental level.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527879616


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.functions.InvalidTypesException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.FromDataSource;
+import org.apache.flink.api.connector.v2.Source;
+import org.apache.flink.api.connector.v2.WrappedSource;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.typeutils.MissingTypeInfo;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.connector.datagen.functions.FromElementsGeneratorFunction;
+import org.apache.flink.connector.datagen.source.DataGeneratorSource;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.SourceTransformation;
+import org.apache.flink.streaming.runtime.translators.ProcessFunctionSinkTransformationTranslator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */
+public class ExecutionEnvironmentImpl implements ExecutionEnvironment {
+    private final List<Transformation<?>> transformations = new ArrayList<>();
+
+    private final ExecutionConfig executionConfig;
+
+    /** Settings that control the checkpointing behavior. */
+    private final CheckpointConfig checkpointCfg;
+
+    private final Configuration configuration;
+
+    private final ClassLoader userClassloader;
+
+    private final PipelineExecutorServiceLoader executorServiceLoader;
+
+    static {
+        try {
+            // All transformation translator must be put to a map in StreamGraphGenerator, but
+            // streaming-java is not depend on process-function module, using reflect to handle
+            // this.
+            ProcessFunctionSinkTransformationTranslator.registerSinkTransformationTranslator();
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Can not register process function transformation translator.");
+        }
+    }
+
+    /**
+     * The environment of the context (local by default, cluster if invoked through command line).
+     */
+    private static ExecutionEnvironmentFactory contextEnvironmentFactory = null;
+
+    public static ExecutionEnvironment newInstance() {
+        if (contextEnvironmentFactory != null) {
+            return contextEnvironmentFactory.createExecutionEnvironment(new Configuration());
+        } else {
+            final Configuration configuration = new Configuration();
+            configuration.set(DeploymentOptions.TARGET, "local");
+            configuration.set(DeploymentOptions.ATTACHED, true);
+            return new ExecutionEnvironmentImpl(
+                    new DefaultExecutorServiceLoader(), configuration, null);
+        }
+    }
+
+    ExecutionEnvironmentImpl(
+            PipelineExecutorServiceLoader executorServiceLoader,
+            Configuration configuration,
+            ClassLoader classLoader) {
+        this.executorServiceLoader = checkNotNull(executorServiceLoader);
+        this.configuration = configuration;
+        this.executionConfig = new ExecutionConfig(this.configuration);
+        this.checkpointCfg = new CheckpointConfig(this.configuration);
+        this.userClassloader = classLoader == null ? getClass().getClassLoader() : classLoader;
+        configure(configuration, userClassloader);
+    }
+
+    @Override
+    public void execute(String jobName) throws Exception {
+        StreamGraph streamGraph = getStreamGraph();
+        if (jobName != null) {
+            streamGraph.setJobName(jobName);
+        }
+
+        execute(streamGraph);
+    }
+
+    @Override
+    public ExecutionEnvironment setExecutionMode(RuntimeExecutionMode runtimeMode) {
+        checkNotNull(runtimeMode);
+        configuration.set(ExecutionOptions.RUNTIME_MODE, runtimeMode);
+        return this;
+    }
+
+    protected static void initializeContextEnvironment(ExecutionEnvironmentFactory ctx) {
+        contextEnvironmentFactory = ctx;
+    }
+
+    protected static void resetContextEnvironment() {
+        contextEnvironmentFactory = null;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> fromSource(Source<OUT> source, String sourceName) {
+        if (source instanceof WrappedSource) {
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> innerSource =
+                    ((WrappedSource<OUT>) source).getWrappedSource();
+            final TypeInformation<OUT> resolvedTypeInfo =
+                    getSourceTypeInfo(innerSource, sourceName);
+
+            SourceTransformation<OUT, ?, ?> sourceTransformation =
+                    new SourceTransformation<>(
+                            sourceName,
+                            innerSource,
+                            WatermarkStrategy.noWatermarks(),
+                            resolvedTypeInfo,
+                            getParallelism(),
+                            false);
+            return new NonKeyedPartitionStreamImpl<>(this, sourceTransformation);
+        } else if (source instanceof FromDataSource) {
+            Collection<OUT> data = ((FromDataSource<OUT>) source).getData();
+            TypeInformation<OUT> outType = extractTypeInfoFromCollection(data);
+
+            FromElementsGeneratorFunction<OUT> generatorFunction =
+                    new FromElementsGeneratorFunction<>(outType, executionConfig, data);
+
+            DataGeneratorSource<OUT> generatorSource =
+                    new DataGeneratorSource<>(generatorFunction, data.size(), outType);
+
+            return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
+        } else {
+            throw new UnsupportedOperationException(
+                    "Unsupported type of sink, you could use SourceUtils to wrap a FLIP-27 based source.");
+        }
+    }
+
+    public Configuration getConfiguration() {
+        return this.configuration;
+    }
+
+    public ExecutionConfig getExecutionConfig() {
+        return executionConfig;
+    }
+
+    public int getParallelism() {
+        return executionConfig.getParallelism();
+    }
+
+    public List<Transformation<?>> getTransformations() {
+        return transformations;
+    }
+
+    public void setParallelism(int parallelism) {
+        executionConfig.setParallelism(parallelism);
+    }
+
+    public CheckpointConfig getCheckpointCfg() {
+        return checkpointCfg;
+    }
+
+    // -----------------------------------------------
+    //              Internal Methods
+    // -----------------------------------------------
+
+    private static <OUT> TypeInformation<OUT> extractTypeInfoFromCollection(Collection<OUT> data) {
+        Preconditions.checkNotNull(data, "Collection must not be null");
+        if (data.isEmpty()) {
+            throw new IllegalArgumentException("Collection must not be empty");
+        }
+
+        OUT first = data.iterator().next();
+        if (first == null) {
+            throw new IllegalArgumentException("Collection must not contain null elements");
+        }
+
+        TypeInformation<OUT> typeInfo;
+        try {
+            typeInfo = TypeExtractor.getForObject(first);
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Could not create TypeInformation for type "
+                            + first.getClass()
+                            + "; please specify the TypeInformation manually via the version of the "
+                            + "method that explicitly accepts it as an argument.",
+                    e);
+        }
+        return typeInfo;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <OUT, T extends TypeInformation<OUT>> T getSourceTypeInfo(
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> source, String sourceName) {
+        TypeInformation<OUT> resolvedTypeInfo = null;
+        if (source instanceof ResultTypeQueryable) {

Review Comment:
   I don't know if I'm missing something, but I feel like this is an unequal replacement...



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527970640


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/utils/StreamUtils.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.process.impl.utils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.Sink;
+import org.apache.flink.api.connector.v2.WrappedSink;
+import org.apache.flink.api.java.Utils;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.process.impl.stream.DataStream;
+import org.apache.flink.process.impl.stream.KeyedPartitionStreamImpl;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.operators.SimpleUdfStreamOperatorFactory;
+import org.apache.flink.streaming.api.operators.StreamOperatorFactory;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.streaming.api.transformations.ProcessFunctionSinkTransformation;
+import org.apache.flink.streaming.api.transformations.TwoInputTransformation;
+
+/** Utils to handle things like extract type information for DataStream. */

Review Comment:
    I think I should explicitly emphasize on the java doc that this class encapsulates common logic for all streams. I have Updated this one.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on PR #24422:
URL: https://github.com/apache/flink/pull/24422#issuecomment-2026552909

   Thanks @Sxnan for the Careful review! I have updated this PR, PTAL.


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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1543978435


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionContextEnvironment.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.datastream.impl;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.datastream.api.ExecutionEnvironment;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Special {@link ExecutionEnvironment} that will be used in cases where the CLI client or testing
+ * utilities create a {@link ExecutionEnvironment} that should be used when {@link
+ * ExecutionEnvironment#getInstance()} ()} is called.
+ */
+public class ExecutionContextEnvironment extends ExecutionEnvironmentImpl {
+    private final boolean suppressSysout;
+
+    private final boolean enforceSingleJobExecution;
+    private final Configuration clusterConfiguration;
+
+    private final boolean programConfigEnabled;
+    private final Collection<String> programConfigWildcards;

Review Comment:
   Yes, we do have a plan to use these fields. But I'm fine to add them later. So I have removed all unused fields.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527863818


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/function/ProcessFunction.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.process.api.function;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.functions.Function;
+
+/** Base class for all user defined process functions. */
+@Experimental
+public interface ProcessFunction extends Function {
+    /**
+     * Initialization method for the function. It is called before the actual working methods (like
+     * processRecord) and thus suitable for one time setup work.
+     *
+     * <p>By default, this method does nothing.
+     *
+     * @throws Exception Implementations may forward exceptions, which are caught by the runtime.
+     *     When the runtime catches an exception, it aborts the task and lets the fail-over logic
+     *     decide whether to retry the task execution.
+     */
+    default void open() throws Exception {}

Review Comment:
   I just didn't realize what we need to do in `OpenContext` at the moment? Since the V2 API is experimental, we can introduce such contexts to it before it becomes public, I think.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527984469


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/BroadcastStream.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+
+/** This interface represents a stream that each parallel task processes the same data. */
+@Experimental
+public interface BroadcastStream<T> {
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * @param other {@link KeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <K, T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            KeyedPartitionStream<K, T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link NonKeyedPartitionStream}.
+     *
+     * @param other {@link NonKeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            NonKeyedPartitionStream<T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * <p>This method is used to avoid shuffle after applying the process function. It is required
+     * that for the record from non-broadcast input, the new {@link KeySelector} must extract the
+     * same key as the original {@link KeySelector}s on the {@link KeyedPartitionStream}. For the
+     * record from broadcast input, the output key from keyed partition itself instead of new key
+     * selector, so it is safe already.

Review Comment:
   1. we need to provide notes for the two connectAndProcess methods to explain the differences between them.
   2. we need to clearly state the purpose and usage limitations of the `newKeySelector`.
   3. we need to clarify what 'safe' means, or simply explain the usage limitations of newKeySelector without introduce the 'safe' concept.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535342882


##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SourceUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to convert a FLIP-27 based source to a DataStream v2 Source. */
+@Experimental
+public final class SourceUtils {
+    public static <T> Source<T> wrapSource(

Review Comment:
   Yes, I somehow forgot it :) Updated.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1523101423


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/BroadcastStream.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+
+/** This interface represents a stream that each parallel task processes the same data. */
+@Experimental
+public interface BroadcastStream<T> {
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * @param other {@link KeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <K, T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            KeyedPartitionStream<K, T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link NonKeyedPartitionStream}.
+     *
+     * @param other {@link NonKeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            NonKeyedPartitionStream<T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * <p>This method is used to avoid shuffle after applying the process function. It is required
+     * that for the record from non-broadcast input, the new {@link KeySelector} must extract the
+     * same key as the original {@link KeySelector}s on the {@link KeyedPartitionStream}. For the
+     * record from broadcast input, the output key from keyed partition itself instead of new key
+     * selector, so it is safe already.

Review Comment:
   For `KeyedPartitionStream` and `BroadcastStream`,  we may need to explain more details on why we need a new key selector, why it avoid shuffle process, and the concept of `safe`.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/utils/StreamUtils.java:
##########
@@ -0,0 +1,285 @@
+/*
+ * 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.process.impl.utils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.Sink;
+import org.apache.flink.api.connector.v2.WrappedSink;
+import org.apache.flink.api.java.Utils;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.process.impl.stream.DataStream;
+import org.apache.flink.process.impl.stream.KeyedPartitionStreamImpl;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.api.operators.SimpleOperatorFactory;
+import org.apache.flink.streaming.api.operators.SimpleUdfStreamOperatorFactory;
+import org.apache.flink.streaming.api.operators.StreamOperatorFactory;
+import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
+import org.apache.flink.streaming.api.transformations.OneInputTransformation;
+import org.apache.flink.streaming.api.transformations.ProcessFunctionSinkTransformation;
+import org.apache.flink.streaming.api.transformations.TwoInputTransformation;
+
+/** Utils to handle things like extract type information for DataStream. */

Review Comment:
   Currently, the StreamUtils utility class is responsible for too many things, including extracting type information, building transformations, creating new DataStreams, adding sink operators, among others. The Java comments for the class state that its purpose is to "handle things like extract type information for DataStream". We might need to specify in the Java comments which types of utility methods this class will provide to improve readability. 



##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/KeyedPartitionStream.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.connector.v2.Sink;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+
+/** This interface represents a stream that each parallel task processes the same data. */

Review Comment:
   The note of class shouldn't be same with `BroadcastStream`.



##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/function/ProcessFunction.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.process.api.function;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.functions.Function;
+
+/** Base class for all user defined process functions. */
+@Experimental
+public interface ProcessFunction extends Function {
+    /**
+     * Initialization method for the function. It is called before the actual working methods (like
+     * processRecord) and thus suitable for one time setup work.
+     *
+     * <p>By default, this method does nothing.
+     *
+     * @throws Exception Implementations may forward exceptions, which are caught by the runtime.
+     *     When the runtime catches an exception, it aborts the task and lets the fail-over logic
+     *     decide whether to retry the task execution.
+     */
+    default void open() throws Exception {}

Review Comment:
   `RichFunction` also has methods like `open(OpenContext openContext)`,` close()`, etc., that can sense the lifecycle of operators. In the open method of ProcessFunction, is it allowed to provide a parameter like `OpenContext`?



##########
flink-core-api/pom.xml:
##########
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.flink</groupId>
+		<artifactId>flink-parent</artifactId>
+		<version>1.20-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>flink-core-api</artifactId>
+	<name>Flink : Core API</name>
+
+	<packaging>jar</packaging>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-annotations</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<!-- publish some test base classes -->

Review Comment:
   Currently there doesn't exist a clear use case for sharing test classes among different modules. I would suggest we remove the test-jar configuration for now. We can always reintroduce it later if the need arises



##########
flink-process-function-parent/flink-process-function/src/test/java/org/apache/flink/process/impl/ExecutionEnvironmentImplTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.connector.v2.SourceUtils;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.StreamTestUtils;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link ExecutionEnvironmentImpl}. */
+class ExecutionEnvironmentImplTest {

Review Comment:
   We need also test `setExecutionMode` and `execute(String jobName)`.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/operators/ProcessOperator.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.process.impl.operators;
+
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.impl.common.OutputCollector;
+import org.apache.flink.process.impl.common.TimestampCollector;
+import org.apache.flink.process.impl.context.DefaultNonPartitionedContext;
+import org.apache.flink.process.impl.context.DefaultRuntimeContext;
+import org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/** Operator for {@link OneInputStreamProcessFunction}. */
+public class ProcessOperator<IN, OUT>
+        extends AbstractUdfStreamOperator<OUT, OneInputStreamProcessFunction<IN, OUT>>
+        implements OneInputStreamOperator<IN, OUT>, BoundedOneInput {
+
+    protected transient DefaultRuntimeContext context;
+
+    protected transient DefaultNonPartitionedContext<OUT> nonPartitionedContext;
+
+    protected transient TimestampCollector<OUT> outputCollector;
+
+    public ProcessOperator(OneInputStreamProcessFunction<IN, OUT> userFunction) {
+        super(userFunction);
+
+        chainingStrategy = ChainingStrategy.ALWAYS;

Review Comment:
   The design of newly introduced `ProcessOperator` is similar with `org.apache.flink.streaming.api.operators.ProcessOperator`, which also set the `chainingStrategy` to `ALWAYS`. 
   
   Currently, the `StreamingJobGraphGenerator` will use `StreamOperatorFactory#getChainingStrategy()` 
   to determine whether to chain the two adjacent operators. 
   
   The operator factory of new`ProcessOperator` is `SimpleUdfStreamOperatorFactory`,  which extends the `AbstractStreamOperatorFactory`. The default implementation of method 
   `getChainingStrategy()` in `AbstractStreamOperatorFactory` will return 
   `ChainingStrategy.DEFAULT_CHAINING_STRATEGY`, which is same with `ALWAYS`. 
   
   Therefore, I think this initialization is unnecessary. WDYT?



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.functions.InvalidTypesException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.FromDataSource;
+import org.apache.flink.api.connector.v2.Source;
+import org.apache.flink.api.connector.v2.WrappedSource;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.typeutils.MissingTypeInfo;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.connector.datagen.functions.FromElementsGeneratorFunction;
+import org.apache.flink.connector.datagen.source.DataGeneratorSource;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.SourceTransformation;
+import org.apache.flink.streaming.runtime.translators.ProcessFunctionSinkTransformationTranslator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */
+public class ExecutionEnvironmentImpl implements ExecutionEnvironment {
+    private final List<Transformation<?>> transformations = new ArrayList<>();
+
+    private final ExecutionConfig executionConfig;
+
+    /** Settings that control the checkpointing behavior. */
+    private final CheckpointConfig checkpointCfg;
+
+    private final Configuration configuration;
+
+    private final ClassLoader userClassloader;
+
+    private final PipelineExecutorServiceLoader executorServiceLoader;
+
+    static {
+        try {
+            // All transformation translator must be put to a map in StreamGraphGenerator, but
+            // streaming-java is not depend on process-function module, using reflect to handle
+            // this.
+            ProcessFunctionSinkTransformationTranslator.registerSinkTransformationTranslator();
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Can not register process function transformation translator.");
+        }
+    }
+
+    /**
+     * The environment of the context (local by default, cluster if invoked through command line).
+     */
+    private static ExecutionEnvironmentFactory contextEnvironmentFactory = null;
+
+    public static ExecutionEnvironment newInstance() {
+        if (contextEnvironmentFactory != null) {
+            return contextEnvironmentFactory.createExecutionEnvironment(new Configuration());
+        } else {
+            final Configuration configuration = new Configuration();
+            configuration.set(DeploymentOptions.TARGET, "local");
+            configuration.set(DeploymentOptions.ATTACHED, true);
+            return new ExecutionEnvironmentImpl(
+                    new DefaultExecutorServiceLoader(), configuration, null);
+        }
+    }
+
+    ExecutionEnvironmentImpl(
+            PipelineExecutorServiceLoader executorServiceLoader,
+            Configuration configuration,
+            ClassLoader classLoader) {
+        this.executorServiceLoader = checkNotNull(executorServiceLoader);
+        this.configuration = configuration;
+        this.executionConfig = new ExecutionConfig(this.configuration);
+        this.checkpointCfg = new CheckpointConfig(this.configuration);
+        this.userClassloader = classLoader == null ? getClass().getClassLoader() : classLoader;
+        configure(configuration, userClassloader);
+    }
+
+    @Override
+    public void execute(String jobName) throws Exception {
+        StreamGraph streamGraph = getStreamGraph();
+        if (jobName != null) {
+            streamGraph.setJobName(jobName);
+        }
+
+        execute(streamGraph);
+    }
+
+    @Override
+    public ExecutionEnvironment setExecutionMode(RuntimeExecutionMode runtimeMode) {
+        checkNotNull(runtimeMode);
+        configuration.set(ExecutionOptions.RUNTIME_MODE, runtimeMode);
+        return this;
+    }
+
+    protected static void initializeContextEnvironment(ExecutionEnvironmentFactory ctx) {
+        contextEnvironmentFactory = ctx;
+    }
+
+    protected static void resetContextEnvironment() {
+        contextEnvironmentFactory = null;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> fromSource(Source<OUT> source, String sourceName) {
+        if (source instanceof WrappedSource) {
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> innerSource =
+                    ((WrappedSource<OUT>) source).getWrappedSource();
+            final TypeInformation<OUT> resolvedTypeInfo =
+                    getSourceTypeInfo(innerSource, sourceName);
+
+            SourceTransformation<OUT, ?, ?> sourceTransformation =
+                    new SourceTransformation<>(
+                            sourceName,
+                            innerSource,
+                            WatermarkStrategy.noWatermarks(),
+                            resolvedTypeInfo,
+                            getParallelism(),
+                            false);
+            return new NonKeyedPartitionStreamImpl<>(this, sourceTransformation);
+        } else if (source instanceof FromDataSource) {
+            Collection<OUT> data = ((FromDataSource<OUT>) source).getData();
+            TypeInformation<OUT> outType = extractTypeInfoFromCollection(data);
+
+            FromElementsGeneratorFunction<OUT> generatorFunction =
+                    new FromElementsGeneratorFunction<>(outType, executionConfig, data);
+
+            DataGeneratorSource<OUT> generatorSource =
+                    new DataGeneratorSource<>(generatorFunction, data.size(), outType);
+
+            return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
+        } else {
+            throw new UnsupportedOperationException(
+                    "Unsupported type of sink, you could use SourceUtils to wrap a FLIP-27 based source.");
+        }
+    }
+
+    public Configuration getConfiguration() {
+        return this.configuration;
+    }
+
+    public ExecutionConfig getExecutionConfig() {
+        return executionConfig;
+    }
+
+    public int getParallelism() {
+        return executionConfig.getParallelism();
+    }
+
+    public List<Transformation<?>> getTransformations() {
+        return transformations;
+    }
+
+    public void setParallelism(int parallelism) {
+        executionConfig.setParallelism(parallelism);
+    }
+
+    public CheckpointConfig getCheckpointCfg() {
+        return checkpointCfg;
+    }
+
+    // -----------------------------------------------
+    //              Internal Methods
+    // -----------------------------------------------
+
+    private static <OUT> TypeInformation<OUT> extractTypeInfoFromCollection(Collection<OUT> data) {
+        Preconditions.checkNotNull(data, "Collection must not be null");
+        if (data.isEmpty()) {
+            throw new IllegalArgumentException("Collection must not be empty");
+        }
+
+        OUT first = data.iterator().next();
+        if (first == null) {
+            throw new IllegalArgumentException("Collection must not contain null elements");
+        }
+
+        TypeInformation<OUT> typeInfo;
+        try {
+            typeInfo = TypeExtractor.getForObject(first);
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Could not create TypeInformation for type "
+                            + first.getClass()
+                            + "; please specify the TypeInformation manually via the version of the "
+                            + "method that explicitly accepts it as an argument.",
+                    e);
+        }
+        return typeInfo;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <OUT, T extends TypeInformation<OUT>> T getSourceTypeInfo(
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> source, String sourceName) {
+        TypeInformation<OUT> resolvedTypeInfo = null;
+        if (source instanceof ResultTypeQueryable) {

Review Comment:
   We could use `org.apache.flink.api.java.typeutils.TypeExtractor#createTypeInfo(java.lang.Object, java.lang.Class<?>, java.lang.Class<?>, int)` to replace this `if-else` check.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.functions.InvalidTypesException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.FromDataSource;
+import org.apache.flink.api.connector.v2.Source;
+import org.apache.flink.api.connector.v2.WrappedSource;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.typeutils.MissingTypeInfo;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.connector.datagen.functions.FromElementsGeneratorFunction;
+import org.apache.flink.connector.datagen.source.DataGeneratorSource;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.SourceTransformation;
+import org.apache.flink.streaming.runtime.translators.ProcessFunctionSinkTransformationTranslator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */
+public class ExecutionEnvironmentImpl implements ExecutionEnvironment {
+    private final List<Transformation<?>> transformations = new ArrayList<>();
+
+    private final ExecutionConfig executionConfig;
+
+    /** Settings that control the checkpointing behavior. */
+    private final CheckpointConfig checkpointCfg;
+
+    private final Configuration configuration;
+
+    private final ClassLoader userClassloader;
+
+    private final PipelineExecutorServiceLoader executorServiceLoader;
+
+    static {
+        try {
+            // All transformation translator must be put to a map in StreamGraphGenerator, but
+            // streaming-java is not depend on process-function module, using reflect to handle
+            // this.
+            ProcessFunctionSinkTransformationTranslator.registerSinkTransformationTranslator();
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Can not register process function transformation translator.");
+        }
+    }
+
+    /**
+     * The environment of the context (local by default, cluster if invoked through command line).
+     */
+    private static ExecutionEnvironmentFactory contextEnvironmentFactory = null;
+
+    public static ExecutionEnvironment newInstance() {
+        if (contextEnvironmentFactory != null) {
+            return contextEnvironmentFactory.createExecutionEnvironment(new Configuration());
+        } else {
+            final Configuration configuration = new Configuration();
+            configuration.set(DeploymentOptions.TARGET, "local");
+            configuration.set(DeploymentOptions.ATTACHED, true);
+            return new ExecutionEnvironmentImpl(
+                    new DefaultExecutorServiceLoader(), configuration, null);
+        }
+    }
+
+    ExecutionEnvironmentImpl(
+            PipelineExecutorServiceLoader executorServiceLoader,
+            Configuration configuration,
+            ClassLoader classLoader) {
+        this.executorServiceLoader = checkNotNull(executorServiceLoader);
+        this.configuration = configuration;
+        this.executionConfig = new ExecutionConfig(this.configuration);
+        this.checkpointCfg = new CheckpointConfig(this.configuration);
+        this.userClassloader = classLoader == null ? getClass().getClassLoader() : classLoader;
+        configure(configuration, userClassloader);
+    }
+
+    @Override
+    public void execute(String jobName) throws Exception {
+        StreamGraph streamGraph = getStreamGraph();
+        if (jobName != null) {
+            streamGraph.setJobName(jobName);
+        }
+
+        execute(streamGraph);
+    }
+
+    @Override
+    public ExecutionEnvironment setExecutionMode(RuntimeExecutionMode runtimeMode) {
+        checkNotNull(runtimeMode);
+        configuration.set(ExecutionOptions.RUNTIME_MODE, runtimeMode);
+        return this;
+    }
+
+    protected static void initializeContextEnvironment(ExecutionEnvironmentFactory ctx) {
+        contextEnvironmentFactory = ctx;
+    }
+
+    protected static void resetContextEnvironment() {
+        contextEnvironmentFactory = null;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> fromSource(Source<OUT> source, String sourceName) {
+        if (source instanceof WrappedSource) {
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> innerSource =
+                    ((WrappedSource<OUT>) source).getWrappedSource();
+            final TypeInformation<OUT> resolvedTypeInfo =
+                    getSourceTypeInfo(innerSource, sourceName);
+
+            SourceTransformation<OUT, ?, ?> sourceTransformation =
+                    new SourceTransformation<>(
+                            sourceName,
+                            innerSource,
+                            WatermarkStrategy.noWatermarks(),
+                            resolvedTypeInfo,
+                            getParallelism(),
+                            false);
+            return new NonKeyedPartitionStreamImpl<>(this, sourceTransformation);
+        } else if (source instanceof FromDataSource) {
+            Collection<OUT> data = ((FromDataSource<OUT>) source).getData();
+            TypeInformation<OUT> outType = extractTypeInfoFromCollection(data);
+
+            FromElementsGeneratorFunction<OUT> generatorFunction =
+                    new FromElementsGeneratorFunction<>(outType, executionConfig, data);
+
+            DataGeneratorSource<OUT> generatorSource =
+                    new DataGeneratorSource<>(generatorFunction, data.size(), outType);
+
+            return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
+        } else {
+            throw new UnsupportedOperationException(
+                    "Unsupported type of sink, you could use SourceUtils to wrap a FLIP-27 based source.");
+        }
+    }
+
+    public Configuration getConfiguration() {
+        return this.configuration;
+    }
+
+    public ExecutionConfig getExecutionConfig() {
+        return executionConfig;
+    }
+
+    public int getParallelism() {
+        return executionConfig.getParallelism();
+    }
+
+    public List<Transformation<?>> getTransformations() {
+        return transformations;
+    }
+
+    public void setParallelism(int parallelism) {

Review Comment:
   This code change is not related to commit `[FLINK-34548][API] Supports sink-v2 Sink`, we could move it to the `[FLINK-34548][API] Introduce ExecutionEnvironment`.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/streaming/api/transformations/ProcessFunctionSinkTransformation.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.transformations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.process.impl.stream.DataStream;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+
+import org.apache.commons.compress.utils.Lists;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * A {@link Transformation} for sink-v2 in process function.
+ *
+ * @param <InputT> The input type of the {@link SinkWriter}
+ * @param <OutputT> The output type of the {@link Sink}
+ */
+@Internal
+public class ProcessFunctionSinkTransformation<InputT, OutputT>

Review Comment:
   Why do we need to introduce a new `ProcessFunctionSinkTransformation` rather than reuse `SinkTransformation` instead?



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527976069


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/function/ProcessFunction.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.process.api.function;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.functions.Function;
+
+/** Base class for all user defined process functions. */
+@Experimental
+public interface ProcessFunction extends Function {
+    /**
+     * Initialization method for the function. It is called before the actual working methods (like
+     * processRecord) and thus suitable for one time setup work.
+     *
+     * <p>By default, this method does nothing.
+     *
+     * @throws Exception Implementations may forward exceptions, which are caught by the runtime.
+     *     When the runtime catches an exception, it aborts the task and lets the fail-over logic
+     *     decide whether to retry the task execution.
+     */
+    default void open() throws Exception {}

Review Comment:
   Alright, if there is a need to add new parameters to the open method, we can do so when it's actually required, as all the newly added classes are currently at the @ Experimental level.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527888923


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/BroadcastStream.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+
+/** This interface represents a stream that each parallel task processes the same data. */
+@Experimental
+public interface BroadcastStream<T> {
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * @param other {@link KeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <K, T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            KeyedPartitionStream<K, T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link NonKeyedPartitionStream}.
+     *
+     * @param other {@link NonKeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            NonKeyedPartitionStream<T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * <p>This method is used to avoid shuffle after applying the process function. It is required
+     * that for the record from non-broadcast input, the new {@link KeySelector} must extract the
+     * same key as the original {@link KeySelector}s on the {@link KeyedPartitionStream}. For the
+     * record from broadcast input, the output key from keyed partition itself instead of new key
+     * selector, so it is safe already.

Review Comment:
   Yes, the clearer the better. But I'm not sure what is not clear, could you give me some proposed changes?



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527867946


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/operators/ProcessOperator.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.process.impl.operators;
+
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.impl.common.OutputCollector;
+import org.apache.flink.process.impl.common.TimestampCollector;
+import org.apache.flink.process.impl.context.DefaultNonPartitionedContext;
+import org.apache.flink.process.impl.context.DefaultRuntimeContext;
+import org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/** Operator for {@link OneInputStreamProcessFunction}. */
+public class ProcessOperator<IN, OUT>
+        extends AbstractUdfStreamOperator<OUT, OneInputStreamProcessFunction<IN, OUT>>
+        implements OneInputStreamOperator<IN, OUT>, BoundedOneInput {
+
+    protected transient DefaultRuntimeContext context;
+
+    protected transient DefaultNonPartitionedContext<OUT> nonPartitionedContext;
+
+    protected transient TimestampCollector<OUT> outputCollector;
+
+    public ProcessOperator(OneInputStreamProcessFunction<IN, OUT> userFunction) {
+        super(userFunction);
+
+        chainingStrategy = ChainingStrategy.ALWAYS;

Review Comment:
   https://github.com/apache/flink/blob/841f23c73e4399df91112dd11ddca74f45ea5b37/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SimpleOperatorFactory.java#L92-L98
   
   IIRC, `AbstractStreamOperator` is always a `SetupableStreamOperator` with the default chainingStrategy `HEAD`. 🤔 



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527940518


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.functions.InvalidTypesException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.FromDataSource;
+import org.apache.flink.api.connector.v2.Source;
+import org.apache.flink.api.connector.v2.WrappedSource;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.typeutils.MissingTypeInfo;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.connector.datagen.functions.FromElementsGeneratorFunction;
+import org.apache.flink.connector.datagen.source.DataGeneratorSource;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.SourceTransformation;
+import org.apache.flink.streaming.runtime.translators.ProcessFunctionSinkTransformationTranslator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */
+public class ExecutionEnvironmentImpl implements ExecutionEnvironment {
+    private final List<Transformation<?>> transformations = new ArrayList<>();
+
+    private final ExecutionConfig executionConfig;
+
+    /** Settings that control the checkpointing behavior. */
+    private final CheckpointConfig checkpointCfg;
+
+    private final Configuration configuration;
+
+    private final ClassLoader userClassloader;
+
+    private final PipelineExecutorServiceLoader executorServiceLoader;
+
+    static {
+        try {
+            // All transformation translator must be put to a map in StreamGraphGenerator, but
+            // streaming-java is not depend on process-function module, using reflect to handle
+            // this.
+            ProcessFunctionSinkTransformationTranslator.registerSinkTransformationTranslator();
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Can not register process function transformation translator.");
+        }
+    }
+
+    /**
+     * The environment of the context (local by default, cluster if invoked through command line).
+     */
+    private static ExecutionEnvironmentFactory contextEnvironmentFactory = null;
+
+    public static ExecutionEnvironment newInstance() {
+        if (contextEnvironmentFactory != null) {
+            return contextEnvironmentFactory.createExecutionEnvironment(new Configuration());
+        } else {
+            final Configuration configuration = new Configuration();
+            configuration.set(DeploymentOptions.TARGET, "local");
+            configuration.set(DeploymentOptions.ATTACHED, true);
+            return new ExecutionEnvironmentImpl(
+                    new DefaultExecutorServiceLoader(), configuration, null);
+        }
+    }
+
+    ExecutionEnvironmentImpl(
+            PipelineExecutorServiceLoader executorServiceLoader,
+            Configuration configuration,
+            ClassLoader classLoader) {
+        this.executorServiceLoader = checkNotNull(executorServiceLoader);
+        this.configuration = configuration;
+        this.executionConfig = new ExecutionConfig(this.configuration);
+        this.checkpointCfg = new CheckpointConfig(this.configuration);
+        this.userClassloader = classLoader == null ? getClass().getClassLoader() : classLoader;
+        configure(configuration, userClassloader);
+    }
+
+    @Override
+    public void execute(String jobName) throws Exception {
+        StreamGraph streamGraph = getStreamGraph();
+        if (jobName != null) {
+            streamGraph.setJobName(jobName);
+        }
+
+        execute(streamGraph);
+    }
+
+    @Override
+    public ExecutionEnvironment setExecutionMode(RuntimeExecutionMode runtimeMode) {
+        checkNotNull(runtimeMode);
+        configuration.set(ExecutionOptions.RUNTIME_MODE, runtimeMode);
+        return this;
+    }
+
+    protected static void initializeContextEnvironment(ExecutionEnvironmentFactory ctx) {
+        contextEnvironmentFactory = ctx;
+    }
+
+    protected static void resetContextEnvironment() {
+        contextEnvironmentFactory = null;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> fromSource(Source<OUT> source, String sourceName) {
+        if (source instanceof WrappedSource) {
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> innerSource =
+                    ((WrappedSource<OUT>) source).getWrappedSource();
+            final TypeInformation<OUT> resolvedTypeInfo =
+                    getSourceTypeInfo(innerSource, sourceName);
+
+            SourceTransformation<OUT, ?, ?> sourceTransformation =
+                    new SourceTransformation<>(
+                            sourceName,
+                            innerSource,
+                            WatermarkStrategy.noWatermarks(),
+                            resolvedTypeInfo,
+                            getParallelism(),
+                            false);
+            return new NonKeyedPartitionStreamImpl<>(this, sourceTransformation);
+        } else if (source instanceof FromDataSource) {
+            Collection<OUT> data = ((FromDataSource<OUT>) source).getData();
+            TypeInformation<OUT> outType = extractTypeInfoFromCollection(data);
+
+            FromElementsGeneratorFunction<OUT> generatorFunction =
+                    new FromElementsGeneratorFunction<>(outType, executionConfig, data);
+
+            DataGeneratorSource<OUT> generatorSource =
+                    new DataGeneratorSource<>(generatorFunction, data.size(), outType);
+
+            return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
+        } else {
+            throw new UnsupportedOperationException(
+                    "Unsupported type of sink, you could use SourceUtils to wrap a FLIP-27 based source.");
+        }
+    }
+
+    public Configuration getConfiguration() {
+        return this.configuration;
+    }
+
+    public ExecutionConfig getExecutionConfig() {
+        return executionConfig;
+    }
+
+    public int getParallelism() {
+        return executionConfig.getParallelism();
+    }
+
+    public List<Transformation<?>> getTransformations() {
+        return transformations;
+    }
+
+    public void setParallelism(int parallelism) {

Review Comment:
   Moved.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1544004626


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/stream/KeyedPartitionStreamImpl.java:
##########
@@ -0,0 +1,389 @@
+/*
+ * 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.datastream.impl.stream;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.api.stream.BroadcastStream;
+import org.apache.flink.datastream.api.stream.GlobalStream;
+import org.apache.flink.datastream.api.stream.KeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+import org.apache.flink.datastream.impl.operators.KeyedProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputNonBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoOutputProcessOperator;
+import org.apache.flink.datastream.impl.stream.NonKeyedPartitionStreamImpl.TwoNonKeyedPartitionStreamsImpl;
+import org.apache.flink.datastream.impl.utils.StreamUtils;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner;
+import org.apache.flink.util.OutputTag;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link KeyedPartitionStream}. */
+public class KeyedPartitionStreamImpl<K, V> extends AbstractDataStream<V>
+        implements KeyedPartitionStream<K, V> {
+
+    /**
+     * The key selector that can get the key by which the stream if partitioned from the elements.
+     */
+    private final KeySelector<V, K> keySelector;
+
+    /** The type of the key by which the stream is partitioned. */
+    private final TypeInformation<K> keyType;
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream, KeySelector<V, K> keySelector) {
+        this(
+                dataStream,
+                keySelector,
+                TypeExtractor.getKeySelectorTypes(keySelector, dataStream.getType()));
+    }
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        this(
+                dataStream,
+                new PartitionTransformation<>(
+                        dataStream.getTransformation(),
+                        new KeyGroupStreamPartitioner<>(
+                                keySelector,
+                                StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM)),
+                keySelector,
+                keyType);
+    }
+
+    /**
+     * This can construct a keyed stream directly without partitionTransformation to avoid shuffle.
+     */
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            Transformation<V> partitionTransformation,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        super(dataStream.getEnvironment(), partitionTransformation);
+        this.keySelector = keySelector;
+        this.keyType = keyType;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction) {
+        TypeInformation<OUT> outType;
+        outType = StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+
+        KeyedProcessOperator<K, V, OUT> operator = new KeyedProcessOperator<>(processFunction);
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        environment.addOperator(transform);
+        return new NonKeyedPartitionStreamImpl<>(environment, transform);
+    }
+
+    @Override
+    public <OUT> KeyedPartitionStream<K, OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction,
+            KeySelector<OUT, K> newKeySelector) {
+        TypeInformation<OUT> outType =
+                StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+        KeyedProcessOperator<K, V, OUT> operator =
+                new KeyedProcessOperator<>(processFunction, checkNotNull(newKeySelector));
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        NonKeyedPartitionStreamImpl<OUT> outputStream =
+                new NonKeyedPartitionStreamImpl<>(environment, transform);
+        environment.addOperator(transform);
+        // Construct a keyed stream directly without partitionTransformation to avoid shuffle.

Review Comment:
   The number of arguments passed to construct the Operator also not same, but we can easily solve this. So the only reason I didn't reuse the code was because some future work would make it different, and I didn't want to extract the common methods first and separate them later.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527984469


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/BroadcastStream.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+
+/** This interface represents a stream that each parallel task processes the same data. */
+@Experimental
+public interface BroadcastStream<T> {
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * @param other {@link KeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <K, T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            KeyedPartitionStream<K, T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link NonKeyedPartitionStream}.
+     *
+     * @param other {@link NonKeyedPartitionStream} to perform operation with two input.
+     * @param processFunction to perform operation.
+     * @return new stream with this operation.
+     */
+    <T_OTHER, OUT> NonKeyedPartitionStream<OUT> connectAndProcess(
+            NonKeyedPartitionStream<T_OTHER> other,
+            TwoInputBroadcastStreamProcessFunction<T_OTHER, T, OUT> processFunction);
+
+    /**
+     * Apply a two input operation to this and other {@link KeyedPartitionStream}.
+     *
+     * <p>This method is used to avoid shuffle after applying the process function. It is required
+     * that for the record from non-broadcast input, the new {@link KeySelector} must extract the
+     * same key as the original {@link KeySelector}s on the {@link KeyedPartitionStream}. For the
+     * record from broadcast input, the output key from keyed partition itself instead of new key
+     * selector, so it is safe already.

Review Comment:
   1. we need to provide comments for the two connectAndProcess methods to explain the differences between them.
   2. we need to clearly state the purpose and usage limitations of the `newKeySelector`.
   3. we need to clarify what 'safe' means, or simply explain the usage limitations of newKeySelector without introduce the 'safe' concept.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527893607


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/stream/KeyedPartitionStream.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * 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.process.api.stream;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.connector.v2.Sink;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.process.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.process.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+
+/** This interface represents a stream that each parallel task processes the same data. */

Review Comment:
   Ai, good catch!.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535343197


##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SourceUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api.connector.v2;

Review Comment:
   Renamed.



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SourceUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to convert a FLIP-27 based source to a DataStream v2 Source. */
+@Experimental
+public final class SourceUtils {

Review Comment:
   Renamed.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on PR #24422:
URL: https://github.com/apache/flink/pull/24422#issuecomment-2014774547

   Thanks @xintongsong for the review! I have addressed all the comments. 
   
   Sorry for the rebase as we have a conflict with master branch.


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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "xintongsong (via GitHub)" <gi...@apache.org>.
xintongsong commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1533200528


##########
flink-process-function-parent/pom.xml:
##########
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<artifactId>flink-parent</artifactId>

Review Comment:
   1. Why do we need this parent module?
   2. I'm not sure about naming / prefixing the modules with `flink-process-function`. The feature is called DataStream API V2. I don't think `flink-process-function` properly reflects what the modules are about.



##########
pom.xml:
##########
@@ -2366,6 +2366,7 @@ under the License.
 								<exclude>org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#fromData(java.util.Collection)</exclude>
 								<exclude>org.apache.flink.streaming.api.environment.StreamExecutionEnvironment#fromData(java.util.Collection,org.apache.flink.api.common.typeinfo.TypeInformation)</exclude>
 								<exclude>org.apache.flink.api.common.functions.RuntimeContext</exclude>
+								<exclude>org.apache.flink.api.common.functions.Function</exclude>

Review Comment:
   I'd suggest to create jira tickets for tracking:
   1. Manually verifying whether there are any breaking changes to the excluded APIs before releasing 1.20.
   2. Remove the exclusion after 1.20.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentFactory.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.process.api.ExecutionEnvironment;
+
+/** Factory class for execution environments. */
+@FunctionalInterface
+@Experimental

Review Comment:
   Why is this `@Experimental`? Is this a public interface at all?



##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.process.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getExecutionEnvironment() throws ReflectiveOperationException {

Review Comment:
   Imagine how this is used. `ExecutionEnvironment.getExecutionEnvironment()` might be a bit redundant. I'd suggest `getInstance()` or `getEnv()`. 



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SourceUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api.connector.v2;

Review Comment:
   The package `*.connector.v2` is confusing. I'd suggest `*.connector.dsv2`.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/stream/DataStream.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.process.impl.stream;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.process.impl.ExecutionEnvironmentImpl;
+import org.apache.flink.streaming.api.transformations.SideOutputTransformation;
+import org.apache.flink.util.OutputTag;
+import org.apache.flink.util.Preconditions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Base class for all streams.
+ *
+ * <p>Note: This is only used for internal implementation. It must not leak to user face api.
+ */
+@Internal

Review Comment:
   Why do we need this annotation? Shouldn't everything in this non-api module be internal by default?



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SourceUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to convert a FLIP-27 based source to a DataStream v2 Source. */
+@Experimental
+public final class SourceUtils {

Review Comment:
   I'd suggest the name `DataStreamV2SourceUtils`.



##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,231 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */

Review Comment:
   It should be documented that the package, class name and signature of `newInstance()` must not be changed, because reflection is used in the api module.



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SourceUtils.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to convert a FLIP-27 based source to a DataStream v2 Source. */
+@Experimental
+public final class SourceUtils {
+    public static <T> Source<T> wrapSource(

Review Comment:
   Need JavaDoc



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SinkUtils.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+
+/** Utils to convert the sink-v2 based sink to a DataStream v2 Source. */
+@Experimental
+public class SinkUtils {
+    public static <T> Sink<T> wrapSink(org.apache.flink.api.connector.sink2.Sink<T> sink) {

Review Comment:
   JavaDoc



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SinkUtils.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+
+/** Utils to convert the sink-v2 based sink to a DataStream v2 Source. */
+@Experimental
+public class SinkUtils {

Review Comment:
   `DataStreamV2SinkUtils`.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1543991166


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/operators/KeyedTwoOutputProcessOperator.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.datastream.impl.operators;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.impl.common.OutputCollector;
+import org.apache.flink.datastream.impl.common.TimestampCollector;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.OutputTag;
+
+import javax.annotation.Nullable;
+
+/** */
+public class KeyedTwoOutputProcessOperator<KEY, IN, OUT_MAIN, OUT_SIDE>
+        extends TwoOutputProcessOperator<IN, OUT_MAIN, OUT_SIDE> {
+
+    @Nullable private final KeySelector<OUT_MAIN, KEY> mainOutKeySelector;
+
+    @Nullable private final KeySelector<OUT_SIDE, KEY> sideOutKeySelector;
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag) {
+        this(userFunction, outputTag, null, null);
+    }
+
+    public KeyedTwoOutputProcessOperator(
+            TwoOutputStreamProcessFunction<IN, OUT_MAIN, OUT_SIDE> userFunction,
+            OutputTag<OUT_SIDE> outputTag,
+            @Nullable KeySelector<OUT_MAIN, KEY> mainOutKeySelector,
+            @Nullable KeySelector<OUT_SIDE, KEY> sideOutKeySelector) {
+        super(userFunction, outputTag);
+        this.mainOutKeySelector = mainOutKeySelector;
+        this.sideOutKeySelector = sideOutKeySelector;
+    }
+
+    @Override
+    protected TimestampCollector<OUT_MAIN> getMainCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(new OutputCollector<>(output), mainOutKeySelector)
+                : new OutputCollector<>(output);
+    }
+
+    @Override
+    public TimestampCollector<OUT_SIDE> getSideCollector() {
+        return mainOutKeySelector != null && sideOutKeySelector != null
+                ? new KeyCheckedOutputCollector<>(
+                        new SideOutputCollector(output), sideOutKeySelector)
+                : new SideOutputCollector(output);
+    }
+
+    private class KeyCheckedOutputCollector<T> extends TimestampCollector<T> {

Review Comment:
   Good suggestion! I somehow forget we have the common implementation when migrate the PoC code to PR.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1542480801


##########
flink-core/src/main/java/org/apache/flink/api/connector/dsv2/DataStreamV2SourceUtils.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.api.connector.dsv2;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collection;
+
+/** Utils to create the DataStream V2 supported {@link Source}. */
+@Experimental
+public final class DataStreamV2SourceUtils {
+    /**
+     * Wrap a FLIP-27 based source to a DataStream V2 supported source.
+     *
+     * @param source The FLIP-27 based source to wrap.
+     * @return The DataStream V2 supported source.
+     */
+    public static <T> Source<T> wrapSource(

Review Comment:
   It is a only user-facing API that is not called by other functions. But yes, I think I should introduce a unit test for this.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527883895


##########
flink-core-api/pom.xml:
##########
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.flink</groupId>
+		<artifactId>flink-parent</artifactId>
+		<version>1.20-SNAPSHOT</version>
+	</parent>
+
+	<artifactId>flink-core-api</artifactId>
+	<name>Flink : Core API</name>
+
+	<packaging>jar</packaging>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-annotations</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<!-- publish some test base classes -->

Review Comment:
   Make sense. I first introduced it and thinking that this PR-moved class from flink-core would have a corresponding test class, but it doesn't. :)



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527994960


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/streaming/api/transformations/ProcessFunctionSinkTransformation.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.transformations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.process.impl.stream.DataStream;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+
+import org.apache.commons.compress.utils.Lists;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * A {@link Transformation} for sink-v2 in process function.
+ *
+ * @param <InputT> The input type of the {@link SinkWriter}
+ * @param <OutputT> The output type of the {@link Sink}
+ */
+@Internal
+public class ProcessFunctionSinkTransformation<InputT, OutputT>

Review Comment:
   After our offline discussion, I believe that introducing `ProcessFunctionSinkTransformation` is reasonable, as the implementation of `SinkTransformation` is coupled with the `DataStream` and `StreamExecutionEnvironment` in DataStream API V1.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527936405


##########
flink-process-function-parent/flink-process-function/src/test/java/org/apache/flink/process/impl/ExecutionEnvironmentImplTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.connector.v2.SourceUtils;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.StreamTestUtils;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link ExecutionEnvironmentImpl}. */
+class ExecutionEnvironmentImplTest {

Review Comment:
   I have added a new test in `ExecutionEnvironmentImplTest`.
   
   As for the testing of `execute`: It's a bit special, or hard to test with a unit test. I will introduce integration tests through other PR, which will be covered in due course.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "WencongLiu (via GitHub)" <gi...@apache.org>.
WencongLiu commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527988624


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.functions.InvalidTypesException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.v2.FromDataSource;
+import org.apache.flink.api.connector.v2.Source;
+import org.apache.flink.api.connector.v2.WrappedSource;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.typeutils.MissingTypeInfo;
+import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.connector.datagen.functions.FromElementsGeneratorFunction;
+import org.apache.flink.connector.datagen.source.DataGeneratorSource;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.NonKeyedPartitionStreamImpl;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.SourceTransformation;
+import org.apache.flink.streaming.runtime.translators.ProcessFunctionSinkTransformationTranslator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */
+public class ExecutionEnvironmentImpl implements ExecutionEnvironment {
+    private final List<Transformation<?>> transformations = new ArrayList<>();
+
+    private final ExecutionConfig executionConfig;
+
+    /** Settings that control the checkpointing behavior. */
+    private final CheckpointConfig checkpointCfg;
+
+    private final Configuration configuration;
+
+    private final ClassLoader userClassloader;
+
+    private final PipelineExecutorServiceLoader executorServiceLoader;
+
+    static {
+        try {
+            // All transformation translator must be put to a map in StreamGraphGenerator, but
+            // streaming-java is not depend on process-function module, using reflect to handle
+            // this.
+            ProcessFunctionSinkTransformationTranslator.registerSinkTransformationTranslator();
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Can not register process function transformation translator.");
+        }
+    }
+
+    /**
+     * The environment of the context (local by default, cluster if invoked through command line).
+     */
+    private static ExecutionEnvironmentFactory contextEnvironmentFactory = null;
+
+    public static ExecutionEnvironment newInstance() {
+        if (contextEnvironmentFactory != null) {
+            return contextEnvironmentFactory.createExecutionEnvironment(new Configuration());
+        } else {
+            final Configuration configuration = new Configuration();
+            configuration.set(DeploymentOptions.TARGET, "local");
+            configuration.set(DeploymentOptions.ATTACHED, true);
+            return new ExecutionEnvironmentImpl(
+                    new DefaultExecutorServiceLoader(), configuration, null);
+        }
+    }
+
+    ExecutionEnvironmentImpl(
+            PipelineExecutorServiceLoader executorServiceLoader,
+            Configuration configuration,
+            ClassLoader classLoader) {
+        this.executorServiceLoader = checkNotNull(executorServiceLoader);
+        this.configuration = configuration;
+        this.executionConfig = new ExecutionConfig(this.configuration);
+        this.checkpointCfg = new CheckpointConfig(this.configuration);
+        this.userClassloader = classLoader == null ? getClass().getClassLoader() : classLoader;
+        configure(configuration, userClassloader);
+    }
+
+    @Override
+    public void execute(String jobName) throws Exception {
+        StreamGraph streamGraph = getStreamGraph();
+        if (jobName != null) {
+            streamGraph.setJobName(jobName);
+        }
+
+        execute(streamGraph);
+    }
+
+    @Override
+    public ExecutionEnvironment setExecutionMode(RuntimeExecutionMode runtimeMode) {
+        checkNotNull(runtimeMode);
+        configuration.set(ExecutionOptions.RUNTIME_MODE, runtimeMode);
+        return this;
+    }
+
+    protected static void initializeContextEnvironment(ExecutionEnvironmentFactory ctx) {
+        contextEnvironmentFactory = ctx;
+    }
+
+    protected static void resetContextEnvironment() {
+        contextEnvironmentFactory = null;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> fromSource(Source<OUT> source, String sourceName) {
+        if (source instanceof WrappedSource) {
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> innerSource =
+                    ((WrappedSource<OUT>) source).getWrappedSource();
+            final TypeInformation<OUT> resolvedTypeInfo =
+                    getSourceTypeInfo(innerSource, sourceName);
+
+            SourceTransformation<OUT, ?, ?> sourceTransformation =
+                    new SourceTransformation<>(
+                            sourceName,
+                            innerSource,
+                            WatermarkStrategy.noWatermarks(),
+                            resolvedTypeInfo,
+                            getParallelism(),
+                            false);
+            return new NonKeyedPartitionStreamImpl<>(this, sourceTransformation);
+        } else if (source instanceof FromDataSource) {
+            Collection<OUT> data = ((FromDataSource<OUT>) source).getData();
+            TypeInformation<OUT> outType = extractTypeInfoFromCollection(data);
+
+            FromElementsGeneratorFunction<OUT> generatorFunction =
+                    new FromElementsGeneratorFunction<>(outType, executionConfig, data);
+
+            DataGeneratorSource<OUT> generatorSource =
+                    new DataGeneratorSource<>(generatorFunction, data.size(), outType);
+
+            return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
+        } else {
+            throw new UnsupportedOperationException(
+                    "Unsupported type of sink, you could use SourceUtils to wrap a FLIP-27 based source.");
+        }
+    }
+
+    public Configuration getConfiguration() {
+        return this.configuration;
+    }
+
+    public ExecutionConfig getExecutionConfig() {
+        return executionConfig;
+    }
+
+    public int getParallelism() {
+        return executionConfig.getParallelism();
+    }
+
+    public List<Transformation<?>> getTransformations() {
+        return transformations;
+    }
+
+    public void setParallelism(int parallelism) {
+        executionConfig.setParallelism(parallelism);
+    }
+
+    public CheckpointConfig getCheckpointCfg() {
+        return checkpointCfg;
+    }
+
+    // -----------------------------------------------
+    //              Internal Methods
+    // -----------------------------------------------
+
+    private static <OUT> TypeInformation<OUT> extractTypeInfoFromCollection(Collection<OUT> data) {
+        Preconditions.checkNotNull(data, "Collection must not be null");
+        if (data.isEmpty()) {
+            throw new IllegalArgumentException("Collection must not be empty");
+        }
+
+        OUT first = data.iterator().next();
+        if (first == null) {
+            throw new IllegalArgumentException("Collection must not contain null elements");
+        }
+
+        TypeInformation<OUT> typeInfo;
+        try {
+            typeInfo = TypeExtractor.getForObject(first);
+        } catch (Exception e) {
+            throw new RuntimeException(
+                    "Could not create TypeInformation for type "
+                            + first.getClass()
+                            + "; please specify the TypeInformation manually via the version of the "
+                            + "method that explicitly accepts it as an argument.",
+                    e);
+        }
+        return typeInfo;
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <OUT, T extends TypeInformation<OUT>> T getSourceTypeInfo(
+            org.apache.flink.api.connector.source.Source<OUT, ?, ?> source, String sourceName) {
+        TypeInformation<OUT> resolvedTypeInfo = null;
+        if (source instanceof ResultTypeQueryable) {

Review Comment:
   This design would allow for a second attempt to retrieve the data type when it cannot be obtained through `ResultTypeQueryable`, which is also acceptable.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535343533


##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SinkUtils.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+
+/** Utils to convert the sink-v2 based sink to a DataStream v2 Source. */
+@Experimental
+public class SinkUtils {

Review Comment:
   Renamed.



##########
flink-core/src/main/java/org/apache/flink/api/connector/v2/SinkUtils.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.api.connector.v2;
+
+import org.apache.flink.annotation.Experimental;
+
+/** Utils to convert the sink-v2 based sink to a DataStream v2 Source. */
+@Experimental
+public class SinkUtils {
+    public static <T> Sink<T> wrapSink(org.apache.flink.api.connector.sink2.Sink<T> sink) {

Review Comment:
   Updated.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535341562


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/stream/DataStream.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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.process.impl.stream;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.process.impl.ExecutionEnvironmentImpl;
+import org.apache.flink.streaming.api.transformations.SideOutputTransformation;
+import org.apache.flink.util.OutputTag;
+import org.apache.flink.util.Preconditions;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Base class for all streams.
+ *
+ * <p>Note: This is only used for internal implementation. It must not leak to user face api.
+ */
+@Internal

Review Comment:
   I have removed this annotation and renamed this class to `AbstractDataStream`.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1543981337


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/common/TimestampCollector.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.datastream.impl.common;
+
+import org.apache.flink.datastream.api.common.Collector;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+
+/** The base {@link Collector} which take care of records timestamp. */
+public abstract class TimestampCollector<OUT> implements Collector<OUT> {
+    protected final StreamRecord<OUT> reuse = new StreamRecord<>(null);
+
+    public void setTimestamp(StreamRecord<?> timestampBase) {
+        if (timestampBase.hasTimestamp()) {
+            setAbsoluteTimestamp(timestampBase.getTimestamp());
+        } else {
+            eraseTimestamp();
+        }
+    }
+
+    public void setAbsoluteTimestamp(long timestamp) {

Review Comment:
   👍 Renamed.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1543978679


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionContextEnvironment.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.datastream.impl;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.datastream.api.ExecutionEnvironment;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Special {@link ExecutionEnvironment} that will be used in cases where the CLI client or testing
+ * utilities create a {@link ExecutionEnvironment} that should be used when {@link
+ * ExecutionEnvironment#getInstance()} ()} is called.
+ */
+public class ExecutionContextEnvironment extends ExecutionEnvironmentImpl {
+    private final boolean suppressSysout;
+
+    private final boolean enforceSingleJobExecution;
+    private final Configuration clusterConfiguration;
+
+    private final boolean programConfigEnabled;
+    private final Collection<String> programConfigWildcards;
+
+    public ExecutionContextEnvironment(

Review Comment:
   Yep, make sense.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1542471491


##########
flink-datastream-api/src/main/java/org/apache/flink/datastream/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.datastream.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getInstance() throws ReflectiveOperationException {

Review Comment:
   By the previous review comments, we renamed it and I will update FLIP.
   
   see: https://github.com/apache/flink/pull/24422#discussion_r1533208773
   
   



##########
flink-datastream-api/src/main/java/org/apache/flink/datastream/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.datastream.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getInstance() throws ReflectiveOperationException {

Review Comment:
   By the previous review comments, we have renamed it and I will update FLIP.
   
   see: https://github.com/apache/flink/pull/24422#discussion_r1533208773
   
   



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1543999261


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/stream/KeyedPartitionStreamImpl.java:
##########
@@ -0,0 +1,389 @@
+/*
+ * 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.datastream.impl.stream;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.api.stream.BroadcastStream;
+import org.apache.flink.datastream.api.stream.GlobalStream;
+import org.apache.flink.datastream.api.stream.KeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+import org.apache.flink.datastream.impl.operators.KeyedProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputNonBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoOutputProcessOperator;
+import org.apache.flink.datastream.impl.stream.NonKeyedPartitionStreamImpl.TwoNonKeyedPartitionStreamsImpl;
+import org.apache.flink.datastream.impl.utils.StreamUtils;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner;
+import org.apache.flink.util.OutputTag;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link KeyedPartitionStream}. */
+public class KeyedPartitionStreamImpl<K, V> extends AbstractDataStream<V>
+        implements KeyedPartitionStream<K, V> {
+
+    /**
+     * The key selector that can get the key by which the stream if partitioned from the elements.
+     */
+    private final KeySelector<V, K> keySelector;
+
+    /** The type of the key by which the stream is partitioned. */
+    private final TypeInformation<K> keyType;
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream, KeySelector<V, K> keySelector) {
+        this(
+                dataStream,
+                keySelector,
+                TypeExtractor.getKeySelectorTypes(keySelector, dataStream.getType()));
+    }
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        this(
+                dataStream,
+                new PartitionTransformation<>(
+                        dataStream.getTransformation(),
+                        new KeyGroupStreamPartitioner<>(
+                                keySelector,
+                                StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM)),
+                keySelector,
+                keyType);
+    }
+
+    /**
+     * This can construct a keyed stream directly without partitionTransformation to avoid shuffle.
+     */
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            Transformation<V> partitionTransformation,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        super(dataStream.getEnvironment(), partitionTransformation);
+        this.keySelector = keySelector;
+        this.keyType = keyType;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction) {
+        TypeInformation<OUT> outType;
+        outType = StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+
+        KeyedProcessOperator<K, V, OUT> operator = new KeyedProcessOperator<>(processFunction);
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        environment.addOperator(transform);
+        return new NonKeyedPartitionStreamImpl<>(environment, transform);
+    }
+
+    @Override
+    public <OUT> KeyedPartitionStream<K, OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction,
+            KeySelector<OUT, K> newKeySelector) {
+        TypeInformation<OUT> outType =
+                StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+        KeyedProcessOperator<K, V, OUT> operator =
+                new KeyedProcessOperator<>(processFunction, checkNotNull(newKeySelector));
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        NonKeyedPartitionStreamImpl<OUT> outputStream =
+                new NonKeyedPartitionStreamImpl<>(environment, transform);
+        environment.addOperator(transform);
+        // Construct a keyed stream directly without partitionTransformation to avoid shuffle.
+        return new KeyedPartitionStreamImpl<>(
+                outputStream,
+                transform,
+                newKeySelector,
+                TypeExtractor.getKeySelectorTypes(newKeySelector, outputStream.getType()));
+    }
+
+    @Override
+    public <OUT1, OUT2> TwoKeyedPartitionStreams<K, OUT1, OUT2> process(
+            TwoOutputStreamProcessFunction<V, OUT1, OUT2> processFunction,
+            KeySelector<OUT1, K> keySelector1,
+            KeySelector<OUT2, K> keySelector2) {
+        Tuple2<TypeInformation<OUT1>, TypeInformation<OUT2>> twoOutputType =
+                StreamUtils.getOutputTypesForTwoOutputProcessFunction(processFunction, getType());
+        TypeInformation<OUT1> firstOutputType = twoOutputType.f0;
+        TypeInformation<OUT2> secondTOutputType = twoOutputType.f1;
+        OutputTag<OUT2> secondOutputTag = new OutputTag<>("Second-Output", secondTOutputType);

Review Comment:
   The `OutputTag` has two constructor indeed, one with just a string(i.e. id) and one with type information. I think It only needs to be an inner class if we don't pass in type information, because type erasure is really annoying.
   
   If the type information is passed explicitly, it should not need to be an anonymous inner class:
   Take the following code from flink code base as example:
   
   https://github.com/apache/flink/blob/bf60c8813598d3119375cec057930240642699d4/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/PatternStream.java#L327-L328
   
   As for the reuse, I'm not sure if this can be done because typeInformation is not always the same. 🤔 



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535341028


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/process/impl/ExecutionEnvironmentImpl.java:
##########
@@ -0,0 +1,231 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.core.execution.PipelineExecutor;
+import org.apache.flink.core.execution.PipelineExecutorFactory;
+import org.apache.flink.core.execution.PipelineExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.apache.flink.streaming.api.graph.StreamGraphGenerator.DEFAULT_TIME_CHARACTERISTIC;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link ExecutionEnvironment}. */

Review Comment:
   Make sense! I have pointed out this both in the java doc of this class and the `newInstance` method.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535339803


##########
flink-process-function-parent/flink-process-function-api/src/main/java/org/apache/flink/process/api/ExecutionEnvironment.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.process.api;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.RuntimeExecutionMode;
+
+/**
+ * This is the context in which a program is executed.
+ *
+ * <p>The environment provides methods to create a DataStream and control the job execution.
+ */
+@Experimental
+public interface ExecutionEnvironment {
+    /**
+     * Get the execution environment instance.
+     *
+     * @return A {@link ExecutionEnvironment} instance.
+     */
+    static ExecutionEnvironment getExecutionEnvironment() throws ReflectiveOperationException {

Review Comment:
   Renamed to `getInstance`.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1535336409


##########
flink-process-function-parent/pom.xml:
##########
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<artifactId>flink-parent</artifactId>

Review Comment:
   By offline discuss, the parent module is useless. I have un-nested the module structure and renamed `flink-process-function` and `flink-process-function-api` to `flink-datastream` and `flink-datastream-api` repectively.



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "Sxnan (via GitHub)" <gi...@apache.org>.
Sxnan commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1546005963


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/stream/KeyedPartitionStreamImpl.java:
##########
@@ -0,0 +1,389 @@
+/*
+ * 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.datastream.impl.stream;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.api.stream.BroadcastStream;
+import org.apache.flink.datastream.api.stream.GlobalStream;
+import org.apache.flink.datastream.api.stream.KeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+import org.apache.flink.datastream.impl.operators.KeyedProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputNonBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoOutputProcessOperator;
+import org.apache.flink.datastream.impl.stream.NonKeyedPartitionStreamImpl.TwoNonKeyedPartitionStreamsImpl;
+import org.apache.flink.datastream.impl.utils.StreamUtils;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner;
+import org.apache.flink.util.OutputTag;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link KeyedPartitionStream}. */
+public class KeyedPartitionStreamImpl<K, V> extends AbstractDataStream<V>
+        implements KeyedPartitionStream<K, V> {
+
+    /**
+     * The key selector that can get the key by which the stream if partitioned from the elements.
+     */
+    private final KeySelector<V, K> keySelector;
+
+    /** The type of the key by which the stream is partitioned. */
+    private final TypeInformation<K> keyType;
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream, KeySelector<V, K> keySelector) {
+        this(
+                dataStream,
+                keySelector,
+                TypeExtractor.getKeySelectorTypes(keySelector, dataStream.getType()));
+    }
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        this(
+                dataStream,
+                new PartitionTransformation<>(
+                        dataStream.getTransformation(),
+                        new KeyGroupStreamPartitioner<>(
+                                keySelector,
+                                StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM)),
+                keySelector,
+                keyType);
+    }
+
+    /**
+     * This can construct a keyed stream directly without partitionTransformation to avoid shuffle.
+     */
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            Transformation<V> partitionTransformation,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        super(dataStream.getEnvironment(), partitionTransformation);
+        this.keySelector = keySelector;
+        this.keyType = keyType;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction) {
+        TypeInformation<OUT> outType;
+        outType = StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+
+        KeyedProcessOperator<K, V, OUT> operator = new KeyedProcessOperator<>(processFunction);
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        environment.addOperator(transform);
+        return new NonKeyedPartitionStreamImpl<>(environment, transform);
+    }
+
+    @Override
+    public <OUT> KeyedPartitionStream<K, OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction,
+            KeySelector<OUT, K> newKeySelector) {
+        TypeInformation<OUT> outType =
+                StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+        KeyedProcessOperator<K, V, OUT> operator =
+                new KeyedProcessOperator<>(processFunction, checkNotNull(newKeySelector));
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        NonKeyedPartitionStreamImpl<OUT> outputStream =
+                new NonKeyedPartitionStreamImpl<>(environment, transform);
+        environment.addOperator(transform);
+        // Construct a keyed stream directly without partitionTransformation to avoid shuffle.
+        return new KeyedPartitionStreamImpl<>(
+                outputStream,
+                transform,
+                newKeySelector,
+                TypeExtractor.getKeySelectorTypes(newKeySelector, outputStream.getType()));
+    }
+
+    @Override
+    public <OUT1, OUT2> TwoKeyedPartitionStreams<K, OUT1, OUT2> process(
+            TwoOutputStreamProcessFunction<V, OUT1, OUT2> processFunction,
+            KeySelector<OUT1, K> keySelector1,
+            KeySelector<OUT2, K> keySelector2) {
+        Tuple2<TypeInformation<OUT1>, TypeInformation<OUT2>> twoOutputType =
+                StreamUtils.getOutputTypesForTwoOutputProcessFunction(processFunction, getType());
+        TypeInformation<OUT1> firstOutputType = twoOutputType.f0;
+        TypeInformation<OUT2> secondTOutputType = twoOutputType.f1;
+        OutputTag<OUT2> secondOutputTag = new OutputTag<>("Second-Output", secondTOutputType);

Review Comment:
   Thanks for the explanation. 



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


Re: [PR] [FLINK-34548][API] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "Sxnan (via GitHub)" <gi...@apache.org>.
Sxnan commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1546005292


##########
flink-datastream/src/main/java/org/apache/flink/datastream/impl/stream/KeyedPartitionStreamImpl.java:
##########
@@ -0,0 +1,389 @@
+/*
+ * 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.datastream.impl.stream;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.typeutils.TypeExtractor;
+import org.apache.flink.datastream.api.function.OneInputStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoInputNonBroadcastStreamProcessFunction;
+import org.apache.flink.datastream.api.function.TwoOutputStreamProcessFunction;
+import org.apache.flink.datastream.api.stream.BroadcastStream;
+import org.apache.flink.datastream.api.stream.GlobalStream;
+import org.apache.flink.datastream.api.stream.KeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.datastream.api.stream.NonKeyedPartitionStream.TwoNonKeyedPartitionStreams;
+import org.apache.flink.datastream.impl.operators.KeyedProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoInputNonBroadcastProcessOperator;
+import org.apache.flink.datastream.impl.operators.KeyedTwoOutputProcessOperator;
+import org.apache.flink.datastream.impl.stream.NonKeyedPartitionStreamImpl.TwoNonKeyedPartitionStreamsImpl;
+import org.apache.flink.datastream.impl.utils.StreamUtils;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.streaming.runtime.partitioner.GlobalPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.KeyGroupStreamPartitioner;
+import org.apache.flink.streaming.runtime.partitioner.ShufflePartitioner;
+import org.apache.flink.util.OutputTag;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** The implementation of {@link KeyedPartitionStream}. */
+public class KeyedPartitionStreamImpl<K, V> extends AbstractDataStream<V>
+        implements KeyedPartitionStream<K, V> {
+
+    /**
+     * The key selector that can get the key by which the stream if partitioned from the elements.
+     */
+    private final KeySelector<V, K> keySelector;
+
+    /** The type of the key by which the stream is partitioned. */
+    private final TypeInformation<K> keyType;
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream, KeySelector<V, K> keySelector) {
+        this(
+                dataStream,
+                keySelector,
+                TypeExtractor.getKeySelectorTypes(keySelector, dataStream.getType()));
+    }
+
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        this(
+                dataStream,
+                new PartitionTransformation<>(
+                        dataStream.getTransformation(),
+                        new KeyGroupStreamPartitioner<>(
+                                keySelector,
+                                StreamGraphGenerator.DEFAULT_LOWER_BOUND_MAX_PARALLELISM)),
+                keySelector,
+                keyType);
+    }
+
+    /**
+     * This can construct a keyed stream directly without partitionTransformation to avoid shuffle.
+     */
+    public KeyedPartitionStreamImpl(
+            AbstractDataStream<V> dataStream,
+            Transformation<V> partitionTransformation,
+            KeySelector<V, K> keySelector,
+            TypeInformation<K> keyType) {
+        super(dataStream.getEnvironment(), partitionTransformation);
+        this.keySelector = keySelector;
+        this.keyType = keyType;
+    }
+
+    @Override
+    public <OUT> NonKeyedPartitionStream<OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction) {
+        TypeInformation<OUT> outType;
+        outType = StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+
+        KeyedProcessOperator<K, V, OUT> operator = new KeyedProcessOperator<>(processFunction);
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        environment.addOperator(transform);
+        return new NonKeyedPartitionStreamImpl<>(environment, transform);
+    }
+
+    @Override
+    public <OUT> KeyedPartitionStream<K, OUT> process(
+            OneInputStreamProcessFunction<V, OUT> processFunction,
+            KeySelector<OUT, K> newKeySelector) {
+        TypeInformation<OUT> outType =
+                StreamUtils.getOutputTypeForOneInputProcessFunction(processFunction, getType());
+        KeyedProcessOperator<K, V, OUT> operator =
+                new KeyedProcessOperator<>(processFunction, checkNotNull(newKeySelector));
+        Transformation<OUT> transform =
+                StreamUtils.getOneInputKeyedTransformation(
+                        "KeyedProcess", this, outType, operator, keySelector, keyType);
+        NonKeyedPartitionStreamImpl<OUT> outputStream =
+                new NonKeyedPartitionStreamImpl<>(environment, transform);
+        environment.addOperator(transform);
+        // Construct a keyed stream directly without partitionTransformation to avoid shuffle.

Review Comment:
   I am fine if we know that there will be future work that would make them different in the foreseeable future.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527870916


##########
flink-process-function-parent/flink-process-function/src/main/java/org/apache/flink/streaming/api/transformations/ProcessFunctionSinkTransformation.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.transformations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.api.dag.Transformation;
+import org.apache.flink.process.impl.stream.DataStream;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+
+import org.apache.commons.compress.utils.Lists;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * A {@link Transformation} for sink-v2 in process function.
+ *
+ * @param <InputT> The input type of the {@link SinkWriter}
+ * @param <OutputT> The output type of the {@link Sink}
+ */
+@Internal
+public class ProcessFunctionSinkTransformation<InputT, OutputT>

Review Comment:
   `SinkTransformation` and `DataStream(v1 version)` are tightly coupled. Unfortunately, V1 and V2 can't be converted to each other.



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


Re: [PR] [FLINK-34548][api] Introduce DataStream, Partitioning and ProcessFunction [flink]

Posted by "reswqa (via GitHub)" <gi...@apache.org>.
reswqa commented on code in PR #24422:
URL: https://github.com/apache/flink/pull/24422#discussion_r1527936405


##########
flink-process-function-parent/flink-process-function/src/test/java/org/apache/flink/process/impl/ExecutionEnvironmentImplTest.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.process.impl;
+
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.connector.v2.SourceUtils;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.execution.DefaultExecutorServiceLoader;
+import org.apache.flink.process.api.ExecutionEnvironment;
+import org.apache.flink.process.api.stream.NonKeyedPartitionStream;
+import org.apache.flink.process.impl.stream.StreamTestUtils;
+import org.apache.flink.streaming.api.graph.StreamGraph;
+import org.apache.flink.streaming.api.graph.StreamNode;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link ExecutionEnvironmentImpl}. */
+class ExecutionEnvironmentImplTest {

Review Comment:
   I have added a new test in `ExecutionEnvironmentImplTest`.
   
   As for the testing of `execute`: It's a bit special, or hard to test with a unit test. I will introduce integration tests through other PR, which will be covered.



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