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/07/15 01:43:01 UTC

[GitHub] [flink] shuiqiangchen opened a new pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   *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 TableResult#collect in the Python Table API to align with the Java Table API*
   
   
   ## Brief change log
   
     - * Add collect() method for TableResult*
     - *add a new class named ClosableIterator to iterate the result of TableResult*
     - *add a type util to get/transform data between java row object and python object*
   
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - *Add an integration test to test the collect() in test_table_api.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)
   


----------------------------------------------------------------
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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934",
       "triggerID" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0152b67cda06af23879d0b64e94d3c9d33a776e0 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927) 
   * abee885775251aaf6fd43baa002cd50d7d466139 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0152b67cda06af23879d0b64e94d3c9d33a776e0 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934",
       "triggerID" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "triggerType" : "PUSH"
     }, {
       "hash" : "e422451174a439712ff52483da18e90439344811",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7992",
       "triggerID" : "e422451174a439712ff52483da18e90439344811",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * abee885775251aaf6fd43baa002cd50d7d466139 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934) 
   * e422451174a439712ff52483da18e90439344811 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7992) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244) 
   * c6b133f19c45f880d9074f069f2a1a37fe01b00a Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/pyflink/table/tests/test_table_environment_api.py
##########
@@ -445,6 +446,46 @@ def test_to_retract_stream(self):
                     "(True, <Row(2, 'Hello')>)"]
         self.assertEqual(result, expected)
 
+    def test_collect_for_all_data_types(self):
+
+        def collect_from_source(element_data, expected_output):
+            source = self.t_env.from_elements(element_data, ["a"])
+            result = source.execute().collect()
+            collected_result = []
+            for i in result:
+                collected_result.append(i)
+            self.assertEqual(expected_output, collected_result)
+
+        data_in_different_types = [True, 1, "a", u"a", datetime.date(1970, 1, 1),
+                                   datetime.time(0, 0, 0), 1.0, [1], (1,), {"a": 1}, bytearray(1)]
+        expected_results = [Row([True]), Row([1]), Row(['a']), Row(['a']),
+                            Row([datetime.date(1970, 1, 1)]), Row([datetime.time(0, 0)]),
+                            Row([1.0]), Row([[1]]), Row([Row([1])]), Row([{'a': 1}]),
+                            Row([bytearray(b'\x00')])]
+        zipped_datas = zip(data_in_different_types, expected_results)
+        for data, expected_data in zipped_datas:
+            element_data = [Row(data) for _ in range(2)]
+            expected_output = [expected_data for _ in range(2)]
+            collect_from_source(element_data, expected_output)
+
+    def test_collect_with_retract(self):
+        element_data = [(1, 2, 'a'),
+                        (3, 4, 'b'),
+                        (5, 6, 'a'),
+                        (7, 8, 'b')]
+
+        source = self.t_env.from_elements(element_data, ["a", "b", "c"])
+        result = self.t_env.execute_sql("SELECT SUM(a), c FROM %s group by c" % source).collect()
+        collected_result = []
+        for i in result:
+            collected_result.append(i)
+        # The result contains one delete row and an insert row in retract operation for each key.

Review comment:
       Thank you, I'll update the PR after rebasing 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.

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



[GitHub] [flink] flinkbot commented on pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b 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] shuiqiangchen commented on a change in pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {
+		List<byte[]> pickledRowBytes = new ArrayList<>(row.getArity());
+		Pickler pickler = new Pickler();
+		for (int i = 0; i < row.getArity(); i++) {
+			Object fieldData = row.getField(i);
+			if (fieldData == null) {
+				pickledRowBytes.add(new byte[0]);
+			} else {
+				if (dataTypes[i] instanceof DateType) {
+					long time = ((Date) fieldData).toLocalDate().toEpochDay();
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof TimeType) {
+					long time = ((Time) fieldData).toLocalTime().toNanoOfDay();
+					time = time / 1000;
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof RowType) {
+					Row tmpRow = (Row) fieldData;
+					LogicalType[] tmpRowFieldTypes = new LogicalType[tmpRow.getArity()];
+					((RowType) dataTypes[i]).getChildren().toArray(tmpRowFieldTypes);
+					List<byte[]> rowFieldBytes = getPickledBytesFromRow(tmpRow, tmpRowFieldTypes);
+					pickledRowBytes.add(pickler.dumps(rowFieldBytes));
+				} else {
+					pickledRowBytes.add(pickler.dumps(row.getField(i)));

Review comment:
       These types are supported and could be directly serialized by pickled without any special processing, unlike Row/SQL_TIME/SQL_DATE,etc. types 




----------------------------------------------------------------
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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c6b133f19c45f880d9074f069f2a1a37fe01b00a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   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 802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b (Wed Jul 15 01:44:55 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c6b133f19c45f880d9074f069f2a1a37fe01b00a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650) 
   * 0152b67cda06af23879d0b64e94d3c9d33a776e0 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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0152b67cda06af23879d0b64e94d3c9d33a776e0 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927) 
   * abee885775251aaf6fd43baa002cd50d7d466139 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] shuiqiangchen commented on a change in pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {
+		List<byte[]> pickledRowBytes = new ArrayList<>(row.getArity());
+		Pickler pickler = new Pickler();
+		for (int i = 0; i < row.getArity(); i++) {
+			Object fieldData = row.getField(i);
+			if (fieldData == null) {
+				pickledRowBytes.add(new byte[0]);
+			} else {
+				if (dataTypes[i] instanceof DateType) {
+					long time = ((Date) fieldData).toLocalDate().toEpochDay();
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof TimeType) {
+					long time = ((Time) fieldData).toLocalTime().toNanoOfDay();
+					time = time / 1000;
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof RowType) {
+					Row tmpRow = (Row) fieldData;
+					LogicalType[] tmpRowFieldTypes = new LogicalType[tmpRow.getArity()];
+					((RowType) dataTypes[i]).getChildren().toArray(tmpRowFieldTypes);
+					List<byte[]> rowFieldBytes = getPickledBytesFromRow(tmpRow, tmpRowFieldTypes);
+					pickledRowBytes.add(pickler.dumps(rowFieldBytes));
+				} else {

Review comment:
       Types that can not be directly serialized by pickle will be process as code blocks above, and others will be serialized by pickle. So all data types are supported here. 




----------------------------------------------------------------
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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518) 
   * 8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68 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] dianfu closed pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

Posted by GitBox <gi...@apache.org>.
dianfu closed pull request #12902:
URL: https://github.com/apache/flink/pull/12902


   


----------------------------------------------------------------
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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518) 
   * 8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244) 
   
   <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] dianfu commented on a change in pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/pyflink/table/utils.py
##########
@@ -76,3 +79,61 @@ def to_expression_jarray(exprs):
     """
     gateway = get_gateway()
     return to_jarray(gateway.jvm.Expression, [expr._j_expr for expr in exprs])
+
+
+class CloseableIterator(object):

Review comment:
       Move this class to table_result?
   

##########
File path: flink-python/pyflink/table/utils.py
##########
@@ -76,3 +79,61 @@ def to_expression_jarray(exprs):
     """
     gateway = get_gateway()
     return to_jarray(gateway.jvm.Expression, [expr._j_expr for expr in exprs])
+
+
+class CloseableIterator(object):
+    """

Review comment:
       This current implementation of this class is actually not closable. Could you update it a bit as following:
   - Add a close() method
   - Add __enter__ and __exit__ methods
   - Add documentation in TableResult.collect describing that close should be called at the end. You could refer to the Java classes for more details
   - Add an example in TableResult.collect on how to use the returned result using the `with` statement
   

##########
File path: flink-python/pyflink/table/utils.py
##########
@@ -76,3 +79,61 @@ def to_expression_jarray(exprs):
     """
     gateway = get_gateway()
     return to_jarray(gateway.jvm.Expression, [expr._j_expr for expr in exprs])
+
+
+class CloseableIterator(object):
+    """
+    Representing an Iterator that is also auto closeable.
+    """
+    def __init__(self, j_closeable_iterator, field_data_types):
+        self._j_closeable_iterator = j_closeable_iterator
+        self._j_field_data_types = field_data_types
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        if not self._j_closeable_iterator.hasNext():
+            raise StopIteration("No more data.")
+        gateway = get_gateway()
+        pickle_bytes = gateway.jvm.PythonBridgeUtils. \
+            getPickledBytesFromRow(self._j_closeable_iterator.next(),
+                                   self._j_field_data_types)
+        pickle_bytes = list(pickle_bytes)
+        data_types = [_from_java_type(j_field_data_type)

Review comment:
       data_types could be generated in the constructor. There is no need to generate it for each element.

##########
File path: flink-python/pyflink/table/tests/test_table_environment_api.py
##########
@@ -445,6 +446,46 @@ def test_to_retract_stream(self):
                     "(True, <Row(2, 'Hello')>)"]
         self.assertEqual(result, expected)
 
+    def test_collect_for_all_data_types(self):

Review comment:
       could you make the tests runs both in blink planner and the legacy planner?

##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {
+		List<byte[]> pickledRowBytes = new ArrayList<>(row.getArity());
+		Pickler pickler = new Pickler();
+		for (int i = 0; i < row.getArity(); i++) {
+			Object fieldData = row.getField(i);
+			if (fieldData == null) {
+				pickledRowBytes.add(new byte[0]);
+			} else {
+				if (dataTypes[i] instanceof DateType) {
+					long time = ((Date) fieldData).toLocalDate().toEpochDay();
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof TimeType) {
+					long time = ((Time) fieldData).toLocalTime().toNanoOfDay();
+					time = time / 1000;
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof RowType) {
+					Row tmpRow = (Row) fieldData;
+					LogicalType[] tmpRowFieldTypes = new LogicalType[tmpRow.getArity()];
+					((RowType) dataTypes[i]).getChildren().toArray(tmpRowFieldTypes);

Review comment:
       What about change it as following:
   tmpRowFieldTypes = ((RowType) dataTypes[i]).getChildren().toArray(new LogicalType[0])

##########
File path: flink-python/pyflink/table/tests/test_table_environment_api.py
##########
@@ -445,6 +446,46 @@ def test_to_retract_stream(self):
                     "(True, <Row(2, 'Hello')>)"]
         self.assertEqual(result, expected)
 
+    def test_collect_for_all_data_types(self):
+
+        def collect_from_source(element_data, expected_output):
+            source = self.t_env.from_elements(element_data, ["a"])
+            result = source.execute().collect()
+            collected_result = []
+            for i in result:
+                collected_result.append(i)
+            self.assertEqual(expected_output, collected_result)
+
+        data_in_different_types = [True, 1, "a", u"a", datetime.date(1970, 1, 1),
+                                   datetime.time(0, 0, 0), 1.0, [1], (1,), {"a": 1}, bytearray(1)]
+        expected_results = [Row([True]), Row([1]), Row(['a']), Row(['a']),
+                            Row([datetime.date(1970, 1, 1)]), Row([datetime.time(0, 0)]),
+                            Row([1.0]), Row([[1]]), Row([Row([1])]), Row([{'a': 1}]),
+                            Row([bytearray(b'\x00')])]
+        zipped_datas = zip(data_in_different_types, expected_results)
+        for data, expected_data in zipped_datas:
+            element_data = [Row(data) for _ in range(2)]
+            expected_output = [expected_data for _ in range(2)]
+            collect_from_source(element_data, expected_output)
+
+    def test_collect_with_retract(self):
+        element_data = [(1, 2, 'a'),
+                        (3, 4, 'b'),
+                        (5, 6, 'a'),
+                        (7, 8, 'b')]
+
+        source = self.t_env.from_elements(element_data, ["a", "b", "c"])
+        result = self.t_env.execute_sql("SELECT SUM(a), c FROM %s group by c" % source).collect()
+        collected_result = []
+        for i in result:
+            collected_result.append(i)
+        # The result contains one delete row and an insert row in retract operation for each key.

Review comment:
       It seems that we should consider the retraction flag also, that's the rowKind field?

##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {

Review comment:
       Should we call the initialize() method?

##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {
+		List<byte[]> pickledRowBytes = new ArrayList<>(row.getArity());
+		Pickler pickler = new Pickler();
+		for (int i = 0; i < row.getArity(); i++) {
+			Object fieldData = row.getField(i);
+			if (fieldData == null) {

Review comment:
       Could you add test case for this? That's None field.

##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {
+		List<byte[]> pickledRowBytes = new ArrayList<>(row.getArity());
+		Pickler pickler = new Pickler();
+		for (int i = 0; i < row.getArity(); i++) {
+			Object fieldData = row.getField(i);
+			if (fieldData == null) {
+				pickledRowBytes.add(new byte[0]);
+			} else {
+				if (dataTypes[i] instanceof DateType) {
+					long time = ((Date) fieldData).toLocalDate().toEpochDay();
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof TimeType) {
+					long time = ((Time) fieldData).toLocalTime().toNanoOfDay();
+					time = time / 1000;
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof RowType) {
+					Row tmpRow = (Row) fieldData;
+					LogicalType[] tmpRowFieldTypes = new LogicalType[tmpRow.getArity()];
+					((RowType) dataTypes[i]).getChildren().toArray(tmpRowFieldTypes);
+					List<byte[]> rowFieldBytes = getPickledBytesFromRow(tmpRow, tmpRowFieldTypes);
+					pickledRowBytes.add(pickler.dumps(rowFieldBytes));
+				} else {
+					pickledRowBytes.add(pickler.dumps(row.getField(i)));

Review comment:
       It seems that the implementation doesn't consider the composite types such as ArrayType, MapType, etc, e.g. the element of an array is Row.

##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -162,7 +171,42 @@
 		return objs;
 	}
 
+	private static List<byte[]> getPickledBytesFromRow(Row row, LogicalType[] dataTypes) throws IOException {
+		List<byte[]> pickledRowBytes = new ArrayList<>(row.getArity());
+		Pickler pickler = new Pickler();
+		for (int i = 0; i < row.getArity(); i++) {
+			Object fieldData = row.getField(i);
+			if (fieldData == null) {
+				pickledRowBytes.add(new byte[0]);
+			} else {
+				if (dataTypes[i] instanceof DateType) {
+					long time = ((Date) fieldData).toLocalDate().toEpochDay();
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof TimeType) {
+					long time = ((Time) fieldData).toLocalTime().toNanoOfDay();
+					time = time / 1000;
+					pickledRowBytes.add(pickler.dumps(time));
+				} else if (dataTypes[i] instanceof RowType) {
+					Row tmpRow = (Row) fieldData;
+					LogicalType[] tmpRowFieldTypes = new LogicalType[tmpRow.getArity()];
+					((RowType) dataTypes[i]).getChildren().toArray(tmpRowFieldTypes);
+					List<byte[]> rowFieldBytes = getPickledBytesFromRow(tmpRow, tmpRowFieldTypes);
+					pickledRowBytes.add(pickler.dumps(rowFieldBytes));
+				} else {

Review comment:
       Doesn't all types are supported? Otherwise, it would be great to throw meaningful exceptions if there are unsupported types.




----------------------------------------------------------------
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] dianfu commented on a change in pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/pyflink/table/table_result.py
##########
@@ -130,6 +132,18 @@ def get_result_kind(self):
         """
         return ResultKind._from_j_result_kind(self._j_table_result.getResultKind())
 
+    def collect(self):
+        """
+        Get the result contents as a closeable row iterator.
+
+        :return: A CloseableIterator.
+        """
+        data_types = self._j_table_result.getTableSchema().getFieldDataTypes()
+
+        j_iter = self._j_table_result.collect()
+

Review comment:
       Add the version information:
   ```
   .. versionadded:: 1.12.0
   ``` 

##########
File path: flink-python/pyflink/table/tests/test_table_api.py
##########
@@ -31,6 +32,20 @@ def test_execute(self):
         source.execute()
         # TODO check result
 
+    def test_collect(self):
+        self.t_env.get_config().get_configuration().set_string(
+            "taskmanager.memory.task.off-heap.size", "80mb")
+        element_data = [({"a": [1, 2]}, [1, 2], Row("a")(1)), ({"a": [3, 4]}, [3, 4], Row("a")(1))]

Review comment:
       could you improve the tests to cover all the data types supported?

##########
File path: flink-python/pyflink/table/utils.py
##########
@@ -67,3 +71,60 @@ def tz_convert_to_internal(s, t: DataType, local_tz):
         elif is_datetime64tz_dtype(s.dtype):
             return s.dt.tz_convert(local_tz).dt.tz_localize(None)
     return s
+
+
+class CloseableIterator(object):
+    """
+    Representing an Iterator that is also auto closeable.
+    """
+    def __init__(self, j_closeable_iterator, result_types):
+        self._j_closeable_iterator = j_closeable_iterator
+        self._j_result_types = result_types

Review comment:
       result_types -> field_data_types

##########
File path: flink-python/pyflink/table/tests/test_table_api.py
##########
@@ -31,6 +32,20 @@ def test_execute(self):
         source.execute()
         # TODO check result
 
+    def test_collect(self):
+        self.t_env.get_config().get_configuration().set_string(
+            "taskmanager.memory.task.off-heap.size", "80mb")
+        element_data = [({"a": [1, 2]}, [1, 2], Row("a")(1)), ({"a": [3, 4]}, [3, 4], Row("a")(1))]
+        source = self.t_env.from_elements(element_data, ["a", "b", "c"])
+        result_table = self.t_env.execute_sql("SELECT * FROM %s" % source)

Review comment:
       What happens for a Table with retraction rows? Could you add a test for it?

##########
File path: flink-python/pyflink/table/tests/test_table_api.py
##########
@@ -31,6 +32,20 @@ def test_execute(self):
         source.execute()
         # TODO check result
 
+    def test_collect(self):
+        self.t_env.get_config().get_configuration().set_string(
+            "taskmanager.memory.task.off-heap.size", "80mb")
+        element_data = [({"a": [1, 2]}, [1, 2], Row("a")(1)), ({"a": [3, 4]}, [3, 4], Row("a")(1))]
+        source = self.t_env.from_elements(element_data, ["a", "b", "c"])
+        result_table = self.t_env.execute_sql("SELECT * FROM %s" % source)

Review comment:
       this line could be removed as source is already a Table

##########
File path: flink-python/pyflink/table/types.py
##########
@@ -2405,6 +2405,10 @@ def to_arrow_type(data_type):
         raise ValueError("field_type %s is not supported." % data_type)
 
 
+def get_data_type_from_java_type(j_java_types):

Review comment:
       What about remove this method?

##########
File path: flink-python/src/main/java/org/apache/flink/api/common/python/PythonBridgeUtils.java
##########
@@ -175,4 +221,20 @@ private static void initialize() {
 			}
 		}
 	}
+
+	private static int getOffsetFromLocalMillis(long millisLocal) {

Review comment:
       where it's used?

##########
File path: flink-python/pyflink/table/table_result.py
##########
@@ -130,6 +132,18 @@ def get_result_kind(self):
         """
         return ResultKind._from_j_result_kind(self._j_table_result.getResultKind())
 
+    def collect(self):
+        """
+        Get the result contents as a closeable row iterator.
+
+        :return: A CloseableIterator.
+        """
+        data_types = self._j_table_result.getTableSchema().getFieldDataTypes()

Review comment:
       data_types -> field_data_types?

##########
File path: flink-python/pyflink/table/tests/test_table_api.py
##########
@@ -31,6 +32,20 @@ def test_execute(self):
         source.execute()
         # TODO check result
 
+    def test_collect(self):
+        self.t_env.get_config().get_configuration().set_string(

Review comment:
       Could be removed




----------------------------------------------------------------
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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934",
       "triggerID" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "triggerType" : "PUSH"
     }, {
       "hash" : "e422451174a439712ff52483da18e90439344811",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "e422451174a439712ff52483da18e90439344811",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * abee885775251aaf6fd43baa002cd50d7d466139 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934) 
   * e422451174a439712ff52483da18e90439344811 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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934",
       "triggerID" : "abee885775251aaf6fd43baa002cd50d7d466139",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * abee885775251aaf6fd43baa002cd50d7d466139 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7934) 
   
   <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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244) 
   * c6b133f19c45f880d9074f069f2a1a37fe01b00a 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] dianfu commented on a change in pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/pyflink/table/tests/test_table_environment_api.py
##########
@@ -445,6 +446,46 @@ def test_to_retract_stream(self):
                     "(True, <Row(2, 'Hello')>)"]
         self.assertEqual(result, expected)
 
+    def test_collect_for_all_data_types(self):
+
+        def collect_from_source(element_data, expected_output):
+            source = self.t_env.from_elements(element_data, ["a"])
+            result = source.execute().collect()
+            collected_result = []
+            for i in result:
+                collected_result.append(i)
+            self.assertEqual(expected_output, collected_result)
+
+        data_in_different_types = [True, 1, "a", u"a", datetime.date(1970, 1, 1),
+                                   datetime.time(0, 0, 0), 1.0, [1], (1,), {"a": 1}, bytearray(1)]
+        expected_results = [Row([True]), Row([1]), Row(['a']), Row(['a']),
+                            Row([datetime.date(1970, 1, 1)]), Row([datetime.time(0, 0)]),
+                            Row([1.0]), Row([[1]]), Row([Row([1])]), Row([{'a': 1}]),
+                            Row([bytearray(b'\x00')])]
+        zipped_datas = zip(data_in_different_types, expected_results)
+        for data, expected_data in zipped_datas:
+            element_data = [Row(data) for _ in range(2)]
+            expected_output = [expected_data for _ in range(2)]
+            collect_from_source(element_data, expected_output)
+
+    def test_collect_with_retract(self):
+        element_data = [(1, 2, 'a'),
+                        (3, 4, 'b'),
+                        (5, 6, 'a'),
+                        (7, 8, 'b')]
+
+        source = self.t_env.from_elements(element_data, ["a", "b", "c"])
+        result = self.t_env.execute_sql("SELECT SUM(a), c FROM %s group by c" % source).collect()
+        collected_result = []
+        for i in result:
+            collected_result.append(i)
+        # The result contains one delete row and an insert row in retract operation for each key.

Review comment:
       PR #13371 has been merged and so could you also rebase the PR after addressing the above comments.




----------------------------------------------------------------
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] dianfu commented on a change in pull request #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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



##########
File path: flink-python/pyflink/table/table_result.py
##########
@@ -151,6 +156,45 @@ def get_result_kind(self):
         """
         return ResultKind._from_j_result_kind(self._j_table_result.getResultKind())
 
+    def collect(self):
+        """
+        Get the result contents as a closeable row iterator.
+
+        Note:
+
+        For SELECT operation, the job will not be finished unless all result data has been
+        collected. So we should actively close the job to avoid resource leak through
+        CloseableIterator#close method. Calling CloseableIterator#close method will cancel the job
+        and release related resources.
+
+        For DML operation, Flink dose not support getting the real affected row count now. So the

Review comment:
       ```suggestion
           For DML operation, Flink does not support getting the real affected row count now. So the
   ```

##########
File path: flink-python/pyflink/table/tests/test_table_environment_api.py
##########
@@ -454,6 +458,145 @@ def test_to_retract_stream(self):
                     "(True, <Row(2, 'Hello')>)"]
         self.assertEqual(result, expected)
 
+    def test_collect_for_all_data_types(self):
+
+        def collect_from_source(t_env, expected_result):
+            source = t_env.from_elements([(1, None, 1, True, 32767, -2147483648, 1.23, 1.98932,
+                                           bytearray(b'pyflink'), 'pyflink',
+                                           datetime.date(2014, 9, 13),
+                                           datetime.time(hour=12, minute=0, second=0,
+                                                         microsecond=123000),
+                                           datetime.datetime(2018, 3, 11, 3, 0, 0, 123000),
+                                           [Row(['pyflink']), Row(['pyflink']), Row(['pyflink'])],
+                                           {1: Row(['flink']), 2: Row(['pyflink'])},
+                                           decimal.Decimal('1000000000000000000.05'),
+                                           decimal.Decimal('1000000000000000000.0599999999999999989'
+                                                           '9999999999'))],
+                                         DataTypes.ROW([DataTypes.FIELD("a", DataTypes.BIGINT()),
+                                                        DataTypes.FIELD("b", DataTypes.BIGINT()),
+                                                        DataTypes.FIELD("c", DataTypes.TINYINT()),
+                                                        DataTypes.FIELD("d", DataTypes.BOOLEAN()),
+                                                        DataTypes.FIELD("e", DataTypes.SMALLINT()),
+                                                        DataTypes.FIELD("f", DataTypes.INT()),
+                                                        DataTypes.FIELD("g", DataTypes.FLOAT()),
+                                                        DataTypes.FIELD("h", DataTypes.DOUBLE()),
+                                                        DataTypes.FIELD("i", DataTypes.BYTES()),
+                                                        DataTypes.FIELD("j", DataTypes.STRING()),
+                                                        DataTypes.FIELD("k", DataTypes.DATE()),
+                                                        DataTypes.FIELD("l", DataTypes.TIME()),
+                                                        DataTypes.FIELD("m",
+                                                                        DataTypes.TIMESTAMP(3)),
+                                                        DataTypes.FIELD("n", DataTypes.ARRAY(
+                                                            DataTypes.ROW([DataTypes.FIELD('ss2',
+                                                                           DataTypes.STRING())]))),
+                                                        DataTypes.FIELD("o", DataTypes.MAP(
+                                                            DataTypes.BIGINT(), DataTypes.ROW(
+                                                                [DataTypes.FIELD('ss',
+                                                                 DataTypes.STRING())]))),
+                                                        DataTypes.FIELD("p",
+                                                                        DataTypes.DECIMAL(38, 18)),
+                                                        DataTypes.FIELD("q",
+                                                        DataTypes.DECIMAL(38, 18))]))
+            table_result = source.execute()
+            with table_result.collect() as result:
+                collected_result = []
+                for i in result:
+                    collected_result.append(i)
+                self.assertEqual(expected_result, collected_result)
+
+        legacy_planer_t_env = self.t_env
+        expected_result_legacy_planner = [Row([1, None, 1, True, 32767, -2147483648, 1.23,
+                                          1.98932, bytearray(b'pyflink'), 'pyflink',
+                                          datetime.date(2014, 9, 13), datetime.time(12, 0),
+                                          datetime.datetime(2018, 3, 11, 3, 0, 0, 123000),
+                                          [Row(['[pyflink]']), Row(['[pyflink]']),
+                                           Row(['[pyflink]'])],
+                                          {1: Row(['[flink]']), 2: Row(['[pyflink]'])},
+                                          decimal.Decimal('1000000000000000000.05'),
+                                          decimal.Decimal('1000000000000000000.05999999999999999899'
+                                                          '999999999')])]
+        collect_from_source(legacy_planer_t_env, expected_result_legacy_planner)
+
+        blink_planer_t_env = StreamTableEnvironment.create(
+            StreamExecutionEnvironment.get_execution_environment(),
+            environment_settings=EnvironmentSettings.new_instance()
+            .in_streaming_mode().use_blink_planner().build())
+        blink_planer_t_env.get_config().get_configuration().set_string(
+            "taskmanager.memory.task.off-heap.size", "80mb")
+        expected_result_blink_planner = [Row([1, None, 1, True, 32767, -2147483648, 1.23,
+                                         1.98932, bytearray(b'pyflink'), 'pyflink',
+                                         datetime.date(2014, 9, 13),
+                                              datetime.time(12, 0, 0, 123000),
+                                         datetime.datetime(2018, 3, 11, 3, 0, 0, 123000),
+                                         [Row(['[pyflink]']), Row(['[pyflink]']),
+                                          Row(['[pyflink]'])],
+                                         {1: Row(['[flink]']), 2: Row(['[pyflink]'])},
+                                         decimal.Decimal('1000000000000000000.050000000000000000'),
+                                         decimal.Decimal('1000000000000000000.059999999999999999')])
+                                         ]
+        collect_from_source(blink_planer_t_env, expected_result_blink_planner)
+
+    def test_collect_with_retract(self):
+
+        def collect_retract_result_with(t_env, expected_row_kinds):
+            element_data = [(1, 2, 'a'),
+                            (3, 4, 'b'),
+                            (5, 6, 'a'),
+                            (7, 8, 'b')]
+            field_names = ['a', 'b', 'c']
+            source = t_env.from_elements(element_data, field_names)
+            table_result = t_env.execute_sql(
+                "SELECT SUM(a), c FROM %s group by c" % source)
+            with table_result.collect() as result:
+                collected_result = []
+                for i in result:
+                    collected_result.append(i)
+
+                collected_result = [str(result) + ',' + str(result.get_row_kind())
+                                    for result in collected_result]
+                expected_result = [Row([1, 'a']), Row([1, 'a']), Row([6, 'a']), Row([3, 'b']),
+                                   Row([3, 'b']), Row([10, 'b'])]
+                for i in range(len(expected_result)):
+                    expected_result[i] = str(expected_result[i]) + ',' + str(expected_row_kinds[i])
+                expected_result.sort()
+                collected_result.sort()
+                self.assertEqual(expected_result, collected_result)
+
+        expected_row_kinds_legacy = [RowKind.INSERT, RowKind.DELETE, RowKind.INSERT, RowKind.INSERT,
+                                     RowKind.DELETE, RowKind.INSERT]
+
+        # Test legacy planner
+        collect_retract_result_with(self.t_env, expected_row_kinds_legacy)
+
+        # Test blink planner

Review comment:
       split the tests for legacy planner and blink planner into two test cases?

##########
File path: flink-python/pyflink/table/table_result.py
##########
@@ -151,6 +156,45 @@ def get_result_kind(self):
         """
         return ResultKind._from_j_result_kind(self._j_table_result.getResultKind())
 
+    def collect(self):

Review comment:
       ```suggestion
       def collect(self) -> "CloseableIterator":
   ```

##########
File path: flink-python/pyflink/table/table_result.py
##########
@@ -173,3 +217,49 @@ def print(self):
         .. versionadded:: 1.11.0
         """
         self._j_table_result.print()
+
+
+class CloseableIterator(object):
+    """
+    Representing an Iterator that is also auto closeable.
+    """
+    def __init__(self, j_closeable_iterator, field_data_types):
+        self._j_closeable_iterator = j_closeable_iterator
+        self._j_field_data_types = field_data_types
+        self._data_types = [_from_java_type(j_field_data_type)
+                            for j_field_data_type in self._j_field_data_types]
+
+    def __iter__(self):
+        return self
+
+    def __next__(self):
+        if not self._j_closeable_iterator.hasNext():
+            raise StopIteration("No more data.")
+        gateway = get_gateway()
+        pickle_bytes = gateway.jvm.PythonBridgeUtils. \
+            getPickledBytesFromRow(self._j_closeable_iterator.next(),
+                                   self._j_field_data_types)
+        row_kind = RowKind(int.from_bytes(pickle_bytes[0], byteorder='big', signed=False))
+        pickle_bytes = list(pickle_bytes[1:])
+        field_data = zip(pickle_bytes, self._data_types)
+        fields = []
+        for data, field_type in field_data:
+            if len(data) == 0:
+                fields.append(None)
+            else:
+                fields.append(java_to_python_converter(data, field_type))
+        result_row = Row(fields)
+        result_row.set_row_kind(row_kind)
+        return result_row
+
+    def next(self):
+        return self.__next__()
+
+    def close(self):
+        self._j_closeable_iterator.close()
+
+    def __enter__(self):
+        return self

Review comment:
       ```suggestion
           pass
   ```




----------------------------------------------------------------
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 #12902: [FLINK-18415][python] Support TableResult#collect in the Python Table…

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=4518",
       "triggerID" : "802dfd4a0a2fb3e1b6e9a31fbc850c18f00c5c2b",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=6244",
       "triggerID" : "8fd60abc0cb82fc158b7a68a6dfd3c7fdf1cff68",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650",
       "triggerID" : "c6b133f19c45f880d9074f069f2a1a37fe01b00a",
       "triggerType" : "PUSH"
     }, {
       "hash" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927",
       "triggerID" : "0152b67cda06af23879d0b64e94d3c9d33a776e0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c6b133f19c45f880d9074f069f2a1a37fe01b00a Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7650) 
   * 0152b67cda06af23879d0b64e94d3c9d33a776e0 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=7927) 
   
   <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