You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/08/10 03:03:03 UTC

[GitHub] [flink] shuiqiangchen opened a new pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

shuiqiangchen opened a new pull request #13097:
URL: https://github.com/apache/flink/pull/13097


   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Support key_by() operation for Python DataStream API.
   
   ## Brief change log
   
   - Add a new class nemed KeyStream to represent a keyed DataStream.
   - Add key_by() interface for DataStream.
   
   ## Verifying this change
   
   This change has test cases covered in test_key_by() and test_key_by_map() in test_data_stream.py
   
   ## 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/Mesos, ZooKeeper: (no)
     - The S3 file system connector: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (not documented)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] shuiqiangchen commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
shuiqiangchen commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467756206



##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -233,6 +234,56 @@ def flat_map(self, func: Union[Callable, FlatMapFunction], type_info: TypeInform
             j_python_data_stream_scalar_function_operator
         ))
 
+    def key_by(self, key_selector: Union[Callable, KeySelector],
+               key_type_info: TypeInformation = None) -> 'KeyedStream':
+        """
+        Creates a new KeyedStream that uses the provided key for partitioning its operator states.
+
+        :param key_selector: The KeySelector to be used for extracting the key for partitioning.
+        :param key_type_info: The type information describing the key type.
+        :return: The DataStream with partitioned state(i.e. KeyedStream).
+        """
+        if callable(key_selector):
+            key_selector = KeySelectorFunctionWrapper(key_selector)
+        if not isinstance(key_selector, (KeySelector, KeySelectorFunctionWrapper)):
+            raise TypeError("Parameter key_selector should be a type of KeySelector.")
+
+        gateway = get_gateway()
+        PickledKeySelector = gateway.jvm \
+            .org.apache.flink.datastream.runtime.functions.python.PickledKeySelector
+        j_output_type_info = self._j_data_stream.getTransformation().getOutputType()
+        output_type_info = typeinfo._from_java_type(j_output_type_info)
+        is_key_pickled_byte_array = False
+        if key_type_info is None:
+            key_type_info = Types.PICKLED_BYTE_ARRAY()
+            is_key_pickled_byte_array = True
+        generated_key_stream = KeyedStream(self.map(lambda x: (key_selector.get_key(x), x),
+                                                    type_info=Types.ROW([key_type_info,
+                                                                         output_type_info]))
+                                           ._j_data_stream
+                                           .keyBy(PickledKeySelector(is_key_pickled_byte_array)))
+        generated_key_stream._original_data_type_info = output_type_info
+        return generated_key_stream
+
+    def _align_output_type(self) -> 'DataStream':

Review comment:
       ok




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] hequn8128 commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
hequn8128 commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467729266



##########
File path: flink-python/pyflink/datastream/tests/test_data_stream.py
##########
@@ -140,15 +135,68 @@ def flat_map(value):
 
         flat_mapped_stream = ds.flat_map(flat_map, type_info=Types.ROW([Types.STRING(),
                                                                         Types.INT()]))
-        collect_util = DataStreamCollectUtil()
-        collect_util.collect(flat_mapped_stream)
+        self.collect_util.collect(flat_mapped_stream)
         self.env.execute('flat_map_test')
-        results = collect_util.results()
+        results = self.collect_util.results()
         expected = ['a,0', 'bdc,2', 'deeefg,4']
         results.sort()
         expected.sort()
         self.assertEqual(expected, results)
 
+    def test_key_by(self):
+        element_collection = [('a', 0), ('b', 0), ('c', 1), ('d', 1), ('e', 2)]
+        self.env.set_parallelism(1)
+        ds = self.env.from_collection(element_collection,
+                                      type_info=Types.ROW([Types.STRING(), Types.INT()]))
+
+        class AssertKeyMapFunction(MapFunction):
+            def __init__(self):
+                self.pre = None
+
+            def map(self, value):
+                if value[0] == 'b':
+                    assert self.pre == 'a'
+                if value[0] == 'd':
+                    assert self.pre == 'c'
+                self.pre = value[0]
+                return value
+
+        mapped_stream = ds.key_by(MyKeySelector()).map(AssertKeyMapFunction())
+        self.collect_util.collect(mapped_stream)
+        self.env.execute('key_by_test')
+        results = self.collect_util.results()
+        expected = ["<Row('a', 0)>", "<Row('b', 0)>", "<Row('c', 1)>", "<Row('d', 1)>",
+                    "<Row('e', 2)>"]
+        results.sort()
+        expected.sort()
+        self.assertEqual(expected, results)
+
+    def test_key_by_map(self):

Review comment:
       then we can use the second one to cover the first 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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     }, {
       "hash" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352",
       "triggerID" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 70d1588a2ca469ef4dd78f41760a7b1be3a91488 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349) 
   * 03a8bdd5a1f59e18ea58fafefacddd76c50a09be Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] hequn8128 commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
hequn8128 commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467710965



##########
File path: flink-python/src/main/java/org/apache/flink/datastream/runtime/functions/python/PickledKeySelector.java
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.runtime.functions.python;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.types.Row;
+
+import net.razorvine.pickle.Unpickler;
+
+/**
+ * PickledKeySelector is responsible for extracting the first filed of the input row as key.
+ * The input row is generated by python DataStream map function in the format of (key_selector.get_key(value), value)
+ * tuple2.
+ */
+public class PickledKeySelector implements KeySelector<Row, Object> {
+
+	private Unpickler unpickler = null;
+
+	@Override
+	public Object getKey(Row value) throws Exception {
+
+		if (this.unpickler == null) {
+			unpickler = new Unpickler();
+		}
+
+		Object key = value.getField(0);
+		if (key instanceof byte[]) {

Review comment:
       The key can be other types if key_by with type information. For example, `ds.key_by(MyKeySelector(), Types.INT())`

##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -290,3 +339,39 @@ def _get_java_python_function_operator(self, func: Union[Function, FunctionWrapp
             output_type_info.get_java_type_info(),
             j_python_data_stream_function_info)
         return j_python_data_stream_scalar_function_operator, output_type_info
+
+
+class KeyedStream(DataStream):

Review comment:
       I find there are bugs in the methods of python `DataStream`, i.e., we should check DataStream types when perform `set_parallelism`, `name`, `uid`, etc. Please create another jira to fix the problem.

##########
File path: flink-python/pyflink/datastream/tests/test_data_stream.py
##########
@@ -140,15 +135,68 @@ def flat_map(value):
 
         flat_mapped_stream = ds.flat_map(flat_map, type_info=Types.ROW([Types.STRING(),
                                                                         Types.INT()]))
-        collect_util = DataStreamCollectUtil()
-        collect_util.collect(flat_mapped_stream)
+        self.collect_util.collect(flat_mapped_stream)
         self.env.execute('flat_map_test')
-        results = collect_util.results()
+        results = self.collect_util.results()
         expected = ['a,0', 'bdc,2', 'deeefg,4']
         results.sort()
         expected.sort()
         self.assertEqual(expected, results)
 
+    def test_key_by(self):
+        element_collection = [('a', 0), ('b', 0), ('c', 1), ('d', 1), ('e', 2)]
+        self.env.set_parallelism(1)
+        ds = self.env.from_collection(element_collection,
+                                      type_info=Types.ROW([Types.STRING(), Types.INT()]))
+
+        class AssertKeyMapFunction(MapFunction):
+            def __init__(self):
+                self.pre = None
+
+            def map(self, value):
+                if value[0] == 'b':
+                    assert self.pre == 'a'
+                if value[0] == 'd':
+                    assert self.pre == 'c'
+                self.pre = value[0]
+                return value
+
+        mapped_stream = ds.key_by(MyKeySelector()).map(AssertKeyMapFunction())
+        self.collect_util.collect(mapped_stream)
+        self.env.execute('key_by_test')
+        results = self.collect_util.results()
+        expected = ["<Row('a', 0)>", "<Row('b', 0)>", "<Row('c', 1)>", "<Row('d', 1)>",
+                    "<Row('e', 2)>"]
+        results.sort()
+        expected.sort()
+        self.assertEqual(expected, results)
+
+    def test_key_by_map(self):

Review comment:
       The two tests are duplicated?

##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -233,6 +234,54 @@ def flat_map(self, func: Union[Callable, FlatMapFunction], type_info: TypeInform
             j_python_data_stream_scalar_function_operator
         ))
 
+    def key_by(self, key_selector: Union[Callable, KeySelector],
+               key_type_info: TypeInformation = None) -> 'KeyedStream':
+        """
+        Creates a new KeyedStream that uses the provided key for partitioning its operator states.
+
+        :param key_selector: The KeySelector to be used for extracting the key for partitioning.
+        :param key_type_info: The type information describing the key type.
+        :return: The DataStream with partitioned state(i.e. KeyedStream).
+        """
+        if callable(key_selector):
+            key_selector = KeySelectorFunctionWrapper(key_selector)
+        if not isinstance(key_selector, (KeySelector, KeySelectorFunctionWrapper)):
+            raise TypeError("Parameter key_selector should be a type of KeySelector.")
+
+        gateway = get_gateway()
+        PickledKeySelector = gateway.jvm \
+            .org.apache.flink.datastream.runtime.functions.python.PickledKeySelector
+        j_output_type_info = self._j_data_stream.getTransformation().getOutputType()
+        output_type_info = typeinfo._from_java_type(j_output_type_info)
+        if key_type_info is None:
+            key_type_info = Types.PICKLED_BYTE_ARRAY()
+        generated_key_stream = KeyedStream(self.map(lambda x: (key_selector.get_key(x), x),
+                                                    type_info=Types.ROW([key_type_info,
+                                                                         output_type_info]))
+                                           ._j_data_stream
+                                           .keyBy(PickledKeySelector()))
+        generated_key_stream._original_data_type_info = output_type_info
+        return generated_key_stream
+
+    def _align_output_type(self) -> 'DataStream':

Review comment:
       The method has never been used.

##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -233,6 +234,54 @@ def flat_map(self, func: Union[Callable, FlatMapFunction], type_info: TypeInform
             j_python_data_stream_scalar_function_operator
         ))
 
+    def key_by(self, key_selector: Union[Callable, KeySelector],
+               key_type_info: TypeInformation = None) -> 'KeyedStream':
+        """
+        Creates a new KeyedStream that uses the provided key for partitioning its operator states.
+
+        :param key_selector: The KeySelector to be used for extracting the key for partitioning.
+        :param key_type_info: The type information describing the key type.
+        :return: The DataStream with partitioned state(i.e. KeyedStream).
+        """
+        if callable(key_selector):
+            key_selector = KeySelectorFunctionWrapper(key_selector)
+        if not isinstance(key_selector, (KeySelector, KeySelectorFunctionWrapper)):
+            raise TypeError("Parameter key_selector should be a type of KeySelector.")
+
+        gateway = get_gateway()
+        PickledKeySelector = gateway.jvm \
+            .org.apache.flink.datastream.runtime.functions.python.PickledKeySelector
+        j_output_type_info = self._j_data_stream.getTransformation().getOutputType()
+        output_type_info = typeinfo._from_java_type(j_output_type_info)
+        if key_type_info is None:
+            key_type_info = Types.PICKLED_BYTE_ARRAY()
+        generated_key_stream = KeyedStream(self.map(lambda x: (key_selector.get_key(x), x),
+                                                    type_info=Types.ROW([key_type_info,
+                                                                         output_type_info]))
+                                           ._j_data_stream
+                                           .keyBy(PickledKeySelector()))

Review comment:
       .keyBy(PickledKeySelector(), key_type_info)

##########
File path: flink-python/src/main/java/org/apache/flink/datastream/runtime/functions/python/PickledKeySelector.java
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.runtime.functions.python;
+
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.types.Row;
+
+import net.razorvine.pickle.Unpickler;
+
+/**
+ * PickledKeySelector is responsible for extracting the first filed of the input row as key.

Review comment:
       Use java annotation to describe Java class(e.g., PickledKeySelector, DataStream).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671143340


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 52e8670eef5651d09ad0defeb1a8729aa7c589ba (Mon Aug 10 03:05:45 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
    * **This pull request references an unassigned [Jira ticket](https://issues.apache.org/jira/browse/FLINK-18864).** According to the [code contribution guide](https://flink.apache.org/contributing/contribute-code.html), tickets need to be assigned before starting with the implementation work.
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     }, {
       "hash" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352",
       "triggerID" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "triggerType" : "PUSH"
     }, {
       "hash" : "eb8c81fd06223acfd43bf5b3f4778ba32e8b4ade",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5361",
       "triggerID" : "eb8c81fd06223acfd43bf5b3f4778ba32e8b4ade",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 03a8bdd5a1f59e18ea58fafefacddd76c50a09be Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352) 
   * eb8c81fd06223acfd43bf5b3f4778ba32e8b4ade Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5361) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] hequn8128 commented on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
hequn8128 commented on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671179922


   Tests failed.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 52e8670eef5651d09ad0defeb1a8729aa7c589ba Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     }, {
       "hash" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352",
       "triggerID" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 03a8bdd5a1f59e18ea58fafefacddd76c50a09be Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] shuiqiangchen commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
shuiqiangchen commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467721304



##########
File path: flink-python/pyflink/datastream/tests/test_data_stream.py
##########
@@ -140,15 +135,68 @@ def flat_map(value):
 
         flat_mapped_stream = ds.flat_map(flat_map, type_info=Types.ROW([Types.STRING(),
                                                                         Types.INT()]))
-        collect_util = DataStreamCollectUtil()
-        collect_util.collect(flat_mapped_stream)
+        self.collect_util.collect(flat_mapped_stream)
         self.env.execute('flat_map_test')
-        results = collect_util.results()
+        results = self.collect_util.results()
         expected = ['a,0', 'bdc,2', 'deeefg,4']
         results.sort()
         expected.sort()
         self.assertEqual(expected, results)
 
+    def test_key_by(self):
+        element_collection = [('a', 0), ('b', 0), ('c', 1), ('d', 1), ('e', 2)]
+        self.env.set_parallelism(1)
+        ds = self.env.from_collection(element_collection,
+                                      type_info=Types.ROW([Types.STRING(), Types.INT()]))
+
+        class AssertKeyMapFunction(MapFunction):
+            def __init__(self):
+                self.pre = None
+
+            def map(self, value):
+                if value[0] == 'b':
+                    assert self.pre == 'a'
+                if value[0] == 'd':
+                    assert self.pre == 'c'
+                self.pre = value[0]
+                return value
+
+        mapped_stream = ds.key_by(MyKeySelector()).map(AssertKeyMapFunction())
+        self.collect_util.collect(mapped_stream)
+        self.env.execute('key_by_test')
+        results = self.collect_util.results()
+        expected = ["<Row('a', 0)>", "<Row('b', 0)>", "<Row('c', 1)>", "<Row('d', 1)>",
+                    "<Row('e', 2)>"]
+        results.sort()
+        expected.sort()
+        self.assertEqual(expected, results)
+
+    def test_key_by_map(self):

Review comment:
       They are almost the same, but the second test is to make sure we have not changed the original DataStream after key_by() operation with two way map operation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] hequn8128 commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
hequn8128 commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467754837



##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -290,3 +341,39 @@ def _get_java_python_function_operator(self, func: Union[Function, FunctionWrapp
             output_type_info.get_java_type_info(),
             j_python_data_stream_function_info)
         return j_python_data_stream_scalar_function_operator, output_type_info
+
+
+class KeyedStream(DataStream):

Review comment:
       Throw exception when perform `set_parallelism`, `name`, `uid`, etc.

##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -233,6 +234,56 @@ def flat_map(self, func: Union[Callable, FlatMapFunction], type_info: TypeInform
             j_python_data_stream_scalar_function_operator
         ))
 
+    def key_by(self, key_selector: Union[Callable, KeySelector],
+               key_type_info: TypeInformation = None) -> 'KeyedStream':
+        """
+        Creates a new KeyedStream that uses the provided key for partitioning its operator states.
+
+        :param key_selector: The KeySelector to be used for extracting the key for partitioning.
+        :param key_type_info: The type information describing the key type.
+        :return: The DataStream with partitioned state(i.e. KeyedStream).
+        """
+        if callable(key_selector):
+            key_selector = KeySelectorFunctionWrapper(key_selector)
+        if not isinstance(key_selector, (KeySelector, KeySelectorFunctionWrapper)):
+            raise TypeError("Parameter key_selector should be a type of KeySelector.")
+
+        gateway = get_gateway()
+        PickledKeySelector = gateway.jvm \
+            .org.apache.flink.datastream.runtime.functions.python.PickledKeySelector
+        j_output_type_info = self._j_data_stream.getTransformation().getOutputType()
+        output_type_info = typeinfo._from_java_type(j_output_type_info)
+        is_key_pickled_byte_array = False
+        if key_type_info is None:
+            key_type_info = Types.PICKLED_BYTE_ARRAY()
+            is_key_pickled_byte_array = True
+        generated_key_stream = KeyedStream(self.map(lambda x: (key_selector.get_key(x), x),
+                                                    type_info=Types.ROW([key_type_info,
+                                                                         output_type_info]))
+                                           ._j_data_stream
+                                           .keyBy(PickledKeySelector(is_key_pickled_byte_array)))
+        generated_key_stream._original_data_type_info = output_type_info
+        return generated_key_stream
+
+    def _align_output_type(self) -> 'DataStream':

Review comment:
       Remove this method in this PR.

##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -233,6 +234,56 @@ def flat_map(self, func: Union[Callable, FlatMapFunction], type_info: TypeInform
             j_python_data_stream_scalar_function_operator
         ))
 
+    def key_by(self, key_selector: Union[Callable, KeySelector],
+               key_type_info: TypeInformation = None) -> 'KeyedStream':
+        """
+        Creates a new KeyedStream that uses the provided key for partitioning its operator states.
+
+        :param key_selector: The KeySelector to be used for extracting the key for partitioning.
+        :param key_type_info: The type information describing the key type.
+        :return: The DataStream with partitioned state(i.e. KeyedStream).
+        """
+        if callable(key_selector):
+            key_selector = KeySelectorFunctionWrapper(key_selector)
+        if not isinstance(key_selector, (KeySelector, KeySelectorFunctionWrapper)):
+            raise TypeError("Parameter key_selector should be a type of KeySelector.")
+
+        gateway = get_gateway()
+        PickledKeySelector = gateway.jvm \
+            .org.apache.flink.datastream.runtime.functions.python.PickledKeySelector
+        j_output_type_info = self._j_data_stream.getTransformation().getOutputType()
+        output_type_info = typeinfo._from_java_type(j_output_type_info)
+        is_key_pickled_byte_array = False
+        if key_type_info is None:
+            key_type_info = Types.PICKLED_BYTE_ARRAY()
+            is_key_pickled_byte_array = True
+        generated_key_stream = KeyedStream(self.map(lambda x: (key_selector.get_key(x), x),
+                                                    type_info=Types.ROW([key_type_info,
+                                                                         output_type_info]))
+                                           ._j_data_stream
+                                           .keyBy(PickledKeySelector(is_key_pickled_byte_array)))

Review comment:
       .keyBy(PickledKeySelector(), key_type_info)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] hequn8128 merged pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
hequn8128 merged pull request #13097:
URL: https://github.com/apache/flink/pull/13097


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     }, {
       "hash" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352",
       "triggerID" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "triggerType" : "PUSH"
     }, {
       "hash" : "eb8c81fd06223acfd43bf5b3f4778ba32e8b4ade",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "eb8c81fd06223acfd43bf5b3f4778ba32e8b4ade",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 03a8bdd5a1f59e18ea58fafefacddd76c50a09be Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5352) 
   * eb8c81fd06223acfd43bf5b3f4778ba32e8b4ade UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 52e8670eef5651d09ad0defeb1a8729aa7c589ba Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 70d1588a2ca469ef4dd78f41760a7b1be3a91488 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341) 
   * 70d1588a2ca469ef4dd78f41760a7b1be3a91488 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     }, {
       "hash" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "03a8bdd5a1f59e18ea58fafefacddd76c50a09be",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 70d1588a2ca469ef4dd78f41760a7b1be3a91488 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5349) 
   * 03a8bdd5a1f59e18ea58fafefacddd76c50a09be UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] hequn8128 commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
hequn8128 commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467717445



##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -290,3 +339,39 @@ def _get_java_python_function_operator(self, func: Union[Function, FunctionWrapp
             output_type_info.get_java_type_info(),
             j_python_data_stream_function_info)
         return j_python_data_stream_scalar_function_operator, output_type_info
+
+
+class KeyedStream(DataStream):

Review comment:
       Throw exception when perform `set_parallelism`, `name`, `uid`, etc.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] shuiqiangchen commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
shuiqiangchen commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467756005



##########
File path: flink-python/pyflink/datastream/data_stream.py
##########
@@ -233,6 +234,54 @@ def flat_map(self, func: Union[Callable, FlatMapFunction], type_info: TypeInform
             j_python_data_stream_scalar_function_operator
         ))
 
+    def key_by(self, key_selector: Union[Callable, KeySelector],
+               key_type_info: TypeInformation = None) -> 'KeyedStream':
+        """
+        Creates a new KeyedStream that uses the provided key for partitioning its operator states.
+
+        :param key_selector: The KeySelector to be used for extracting the key for partitioning.
+        :param key_type_info: The type information describing the key type.
+        :return: The DataStream with partitioned state(i.e. KeyedStream).
+        """
+        if callable(key_selector):
+            key_selector = KeySelectorFunctionWrapper(key_selector)
+        if not isinstance(key_selector, (KeySelector, KeySelectorFunctionWrapper)):
+            raise TypeError("Parameter key_selector should be a type of KeySelector.")
+
+        gateway = get_gateway()
+        PickledKeySelector = gateway.jvm \
+            .org.apache.flink.datastream.runtime.functions.python.PickledKeySelector
+        j_output_type_info = self._j_data_stream.getTransformation().getOutputType()
+        output_type_info = typeinfo._from_java_type(j_output_type_info)
+        if key_type_info is None:
+            key_type_info = Types.PICKLED_BYTE_ARRAY()
+        generated_key_stream = KeyedStream(self.map(lambda x: (key_selector.get_key(x), x),
+                                                    type_info=Types.ROW([key_type_info,
+                                                                         output_type_info]))
+                                           ._j_data_stream
+                                           .keyBy(PickledKeySelector()))
+        generated_key_stream._original_data_type_info = output_type_info
+        return generated_key_stream
+
+    def _align_output_type(self) -> 'DataStream':

Review comment:
       Ok, I will remove it in this 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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 52e8670eef5651d09ad0defeb1a8729aa7c589ba Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324) 
   * 3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 52e8670eef5651d09ad0defeb1a8729aa7c589ba UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 52e8670eef5651d09ad0defeb1a8729aa7c589ba Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324) 
   * 3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] shuiqiangchen commented on a change in pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
shuiqiangchen commented on a change in pull request #13097:
URL: https://github.com/apache/flink/pull/13097#discussion_r467756102



##########
File path: flink-python/pyflink/datastream/tests/test_data_stream.py
##########
@@ -140,15 +135,68 @@ def flat_map(value):
 
         flat_mapped_stream = ds.flat_map(flat_map, type_info=Types.ROW([Types.STRING(),
                                                                         Types.INT()]))
-        collect_util = DataStreamCollectUtil()
-        collect_util.collect(flat_mapped_stream)
+        self.collect_util.collect(flat_mapped_stream)
         self.env.execute('flat_map_test')
-        results = collect_util.results()
+        results = self.collect_util.results()
         expected = ['a,0', 'bdc,2', 'deeefg,4']
         results.sort()
         expected.sort()
         self.assertEqual(expected, results)
 
+    def test_key_by(self):
+        element_collection = [('a', 0), ('b', 0), ('c', 1), ('d', 1), ('e', 2)]
+        self.env.set_parallelism(1)
+        ds = self.env.from_collection(element_collection,
+                                      type_info=Types.ROW([Types.STRING(), Types.INT()]))
+
+        class AssertKeyMapFunction(MapFunction):
+            def __init__(self):
+                self.pre = None
+
+            def map(self, value):
+                if value[0] == 'b':
+                    assert self.pre == 'a'
+                if value[0] == 'd':
+                    assert self.pre == 'c'
+                self.pre = value[0]
+                return value
+
+        mapped_stream = ds.key_by(MyKeySelector()).map(AssertKeyMapFunction())
+        self.collect_util.collect(mapped_stream)
+        self.env.execute('key_by_test')
+        results = self.collect_util.results()
+        expected = ["<Row('a', 0)>", "<Row('b', 0)>", "<Row('c', 1)>", "<Row('d', 1)>",
+                    "<Row('e', 2)>"]
+        results.sort()
+        expected.sort()
+        self.assertEqual(expected, results)
+
+    def test_key_by_map(self):

Review comment:
       Ok




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13097: [FLINK-18864][python] Support key_by() operation for Python DataStrea…

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13097:
URL: https://github.com/apache/flink/pull/13097#issuecomment-671146880


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324",
       "triggerID" : "52e8670eef5651d09ad0defeb1a8729aa7c589ba",
       "triggerType" : "PUSH"
     }, {
       "hash" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341",
       "triggerID" : "3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "70d1588a2ca469ef4dd78f41760a7b1be3a91488",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 52e8670eef5651d09ad0defeb1a8729aa7c589ba Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5324) 
   * 3a4fc8cbc9cab1b8395b92c33b960fe4913c6d4a Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5341) 
   * 70d1588a2ca469ef4dd78f41760a7b1be3a91488 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org