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/04/17 02:26:40 UTC

[GitHub] [flink] HuangXingBo opened a new pull request #11784: [FLINK-17120][python] Add Cython support for operations

HuangXingBo opened a new pull request #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784
 
 
   ## What is the purpose of the change
   
   *This pull request will add cython support for operations*
   
   ## Brief change log
   
     - *Add cython implementation of operations in fast_operations.pyx and corresponding pxd*
    
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - *It will be tested in previous IT case in test_udf.py and test_udtf.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 applicable)
   

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


With regards,
Apache Git Services

[GitHub] [flink] flinkbot commented on issue #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#issuecomment-615011156
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1ee639f83adcf607b722609782be88207de5fe49 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


With regards,
Apache Git Services

[GitHub] [flink] dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#discussion_r409994309
 
 

 ##########
 File path: flink-python/pyflink/fn_execution/fast_operations.pxd
 ##########
 @@ -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.
+#
+# cython: language_level=3
+
+cimport libc.stdint
+
+from apache_beam.utils.windowed_value cimport WindowedValue
 
 Review comment:
   used import

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


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#issuecomment-615011156
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=7622",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/160666122",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1ee639f83adcf607b722609782be88207de5fe49 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/160666122) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=7622) 
   
   <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


With regards,
Apache Git Services

[GitHub] [flink] dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#discussion_r409991523
 
 

 ##########
 File path: flink-python/pyflink/fn_execution/coders.py
 ##########
 @@ -177,6 +187,9 @@ def __init__(self, elem_coder):
     def _create_impl(self):
         return coder_impl.ArrayCoderImpl(self._elem_coder.get_impl())
 
+    def get_impl(self):
 
 Review comment:
   If get_impl is already defined in the base class, it is not necessary to define it in child class again.

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


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#issuecomment-615011156
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=7622",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/160666122",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1ee639f83adcf607b722609782be88207de5fe49 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/160666122) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=7622) 
   
   <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


With regards,
Apache Git Services

[GitHub] [flink] dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#discussion_r409994413
 
 

 ##########
 File path: flink-python/pyflink/fn_execution/fast_operations.pxd
 ##########
 @@ -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.
+#
+# cython: language_level=3
+
+cimport libc.stdint
+
+from apache_beam.utils.windowed_value cimport WindowedValue
+from apache_beam.runners.worker.operations cimport Operation
+from apache_beam.coders.coder_impl cimport StreamCoderImpl, CoderImpl, OutputStream, InputStream
+from pyflink.fn_execution.fast_coder_impl cimport InputStreamAndFunctionWrapper
 
 Review comment:
   unused import

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


With regards,
Apache Git Services

[GitHub] [flink] flinkbot commented on issue #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#issuecomment-615003250
 
 
   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 1ee639f83adcf607b722609782be88207de5fe49 (Fri Apr 17 02:28:43 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-17120).** 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


With regards,
Apache Git Services

[GitHub] [flink] dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
dianfu commented on a change in pull request #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#discussion_r409992838
 
 

 ##########
 File path: flink-python/pyflink/fn_execution/fast_operations.pyx
 ##########
 @@ -0,0 +1,242 @@
+#
+# 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.
+#
+# cython: language_level = 3
+# cython: infer_types = True
+# cython: profile=True
+# cython: boundscheck=False, wraparound=False, initializedcheck=False, cdivision=True
+
+import datetime
+
+import cloudpickle
+from apache_beam.runners.worker import bundle_processor
+from apache_beam.runners.worker import operation_specs
+
+from pyflink.fn_execution import flink_fn_execution_pb2
+from pyflink.metrics.metricbase import GenericMetricGroup
+from pyflink.serializers import PickleSerializer
+from pyflink.table import FunctionContext
+from pyflink.table.udf import DelegatingScalarFunction, DelegationTableFunction
+
+SCALAR_FUNCTION_URN = "flink:transform:scalar_function:v1"
+TABLE_FUNCTION_URN = "flink:transform:table_function:v1"
+
+cdef class StatelessFunctionOperation(Operation):
+    """
+    Base class of stateless function operation that will execute ScalarFunction or TableFunction for
+    each input element.
+    """
+
+    def __init__(self, name, spec, counter_factory, sampler, consumers):
+        super(StatelessFunctionOperation, self).__init__(name, spec, counter_factory, sampler)
+        self.consumer = consumers['output'][0]
+        self._value_coder_impl = self.consumer.windowed_coder.wrapped_value_coder.get_impl()
+        value_coder = self._value_coder_impl._value_coder
+        from pyflink.fn_execution.coder_impl import ArrowCoderImpl
+        if isinstance(value_coder, ArrowCoderImpl):
+            self._is_python_coder = True
+        else:
+            self._is_python_coder = False
+
+        self.variable_dict = {}
+        self.user_defined_funcs = []
+        self._func_num = 0
+        self._constant_num = 0
+        self.func = self.generate_func(self.spec.serialized_fn.udfs)
+        self._metric_enabled = self.spec.serialized_fn.metric_enabled
+        self.base_metric_group = None
+        if self._metric_enabled:
+            self.base_metric_group = GenericMetricGroup(None, None)
+        for user_defined_func in self.user_defined_funcs:
+            user_defined_func.open(FunctionContext(self.base_metric_group))
+
+    cpdef start(self):
+        with self.scoped_start_state:
+            super(StatelessFunctionOperation, self).start()
+
+    cpdef finish(self):
+        with self.scoped_finish_state:
+            super(StatelessFunctionOperation, self).finish()
+            self._update_gauge(self.base_metric_group)
+
+    cpdef teardown(self):
+        with self.scoped_finish_state:
+            for user_defined_func in self.user_defined_funcs:
+                user_defined_func.close()
+
+    cpdef process(self, WindowedValue o):
+        cdef InputStreamAndFunctionWrapper wrapper
+        with self.scoped_process_state:
+            output_stream = self.consumer.output_stream
+            if self._is_python_coder:
+                self._value_coder_impl.encode_to_stream(self.func(o.value), output_stream, True)
+            else:
+                wrapper = InputStreamAndFunctionWrapper(self.func, o.value)
+                self._value_coder_impl.encode_to_stream(wrapper, output_stream, True)
+            output_stream.maybe_flush()
+
+    cpdef monitoring_infos(self, transform_id):
 
 Review comment:
   progress_metrics method is missing

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


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11784: [FLINK-17120][python] Add Cython support for operations

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11784: [FLINK-17120][python] Add Cython support for operations
URL: https://github.com/apache/flink/pull/11784#issuecomment-615011156
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=7622",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1ee639f83adcf607b722609782be88207de5fe49",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/160666122",
       "triggerID" : "1ee639f83adcf607b722609782be88207de5fe49",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 1ee639f83adcf607b722609782be88207de5fe49 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/160666122) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=7622) 
   
   <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


With regards,
Apache Git Services