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/10/30 06:57:57 UTC

[GitHub] [flink] WeiZhong94 opened a new pull request #13854: [FLINK-19235][python] Support mixed use with most built-in aggs for Python UDAF.

WeiZhong94 opened a new pull request #13854:
URL: https://github.com/apache/flink/pull/13854


   ## What is the purpose of the change
   
   *This pull request supports mixed use with most built-in aggs (min, max, sum, last_value and so on) for Python UDAF.*
   
   
   ## Brief change log
   
     - *Support mixed use with most built-in aggs (min, max, sum, last_value and so on) for Python UDAF.*
   
   ## Verifying this change
   
   This change is already covered by existing tests.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
     - The serializers: (no)
     - The runtime per-record code paths (performance sensitive): (no)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/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



[GitHub] [flink] flinkbot edited a comment on pull request #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8657",
       "triggerID" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "triggerType" : "PUSH"
     }, {
       "hash" : "61528214ab9174726bc24d8a3bb0e90bd7ff6947",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "61528214ab9174726bc24d8a3bb0e90bd7ff6947",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0ce636d68f60fc7869e90cc00952ca975c6702f4 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8657) 
   * 61528214ab9174726bc24d8a3bb0e90bd7ff6947 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 #13854: [FLINK-19235][python] Support mixed use with most built-in aggs for Python UDAF.

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8657",
       "triggerID" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0ce636d68f60fc7869e90cc00952ca975c6702f4 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8657) 
   
   <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] HuangXingBo commented on a change in pull request #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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



##########
File path: flink-python/pyflink/table/functions.py
##########
@@ -45,6 +82,53 @@ def merge(self, accumulator, accumulators):
             accumulator[0] += acc[0]
 
 
+class CountAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        return accumulator[0]
+
+    def create_accumulator(self):
+        return [0]
+
+    def accumulate(self, accumulator, *args):
+        if args[0] is not None:
+            accumulator[0] += 1
+
+    def retract(self, accumulator, *args):
+        if args[0] is not None:
+            accumulator[0] -= 1
+
+    def merge(self, accumulator, accumulators):
+        for acc in accumulators:
+            accumulator[0] += acc[0]
+
+
+class FirstValueAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        return accumulator[0]
+
+    def create_accumulator(self):
+        # [first_value, first_order]
+        return [None, MAX_LONG_VALUE]
+
+    def accumulate(self, accumulator, *args):
+        if args[0] is not None:
+            if len(args) > 1:
+                if accumulator[1] > args[1]:
+                    accumulator[0] = args[0]
+                    accumulator[1] = args[1]
+            else:
+                if accumulator[0] is None:
+                    accumulator[0] = args[0]

Review comment:
       maybe we need the logic of
   `accumulator[1] = int(round(time.time() * 1000))`

##########
File path: flink-python/pyflink/table/functions.py
##########
@@ -20,12 +20,49 @@
 from abc import abstractmethod
 from decimal import Decimal
 
-from pyflink.table import AggregateFunction, MapView
+from pyflink.table import AggregateFunction, MapView, ListView
 
 MAX_LONG_VALUE = sys.maxsize
 MIN_LONG_VALUE = -MAX_LONG_VALUE - 1
 
 
+class AvgAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        # sum / count
+        if accumulator[0] != 0:
+            return accumulator[1] / accumulator[0]
+        else:
+            return None
+
+    def create_accumulator(self):
+        # [count, sum]
+        return [0, None]

Review comment:
       I think we can set the initial value of sum as `0`

##########
File path: flink-python/pyflink/table/functions.py
##########
@@ -20,12 +20,49 @@
 from abc import abstractmethod
 from decimal import Decimal
 
-from pyflink.table import AggregateFunction, MapView
+from pyflink.table import AggregateFunction, MapView, ListView
 
 MAX_LONG_VALUE = sys.maxsize
 MIN_LONG_VALUE = -MAX_LONG_VALUE - 1
 
 
+class AvgAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        # sum / count
+        if accumulator[0] != 0:
+            return accumulator[1] / accumulator[0]
+        else:
+            return None
+
+    def create_accumulator(self):
+        # [count, sum]
+        return [0, None]
+
+    def accumulate(self, accumulator, *args):
+        if args[0] is not None:
+            accumulator[0] += 1
+            if accumulator[1] is None:

Review comment:
       If we set the initial value of sum as `0`, we can remove the logic of deciding whether accumulator[1] is None.

##########
File path: flink-python/pyflink/table/functions.py
##########
@@ -20,12 +20,49 @@
 from abc import abstractmethod
 from decimal import Decimal
 
-from pyflink.table import AggregateFunction, MapView
+from pyflink.table import AggregateFunction, MapView, ListView
 
 MAX_LONG_VALUE = sys.maxsize
 MIN_LONG_VALUE = -MAX_LONG_VALUE - 1
 
 
+class AvgAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        # sum / count
+        if accumulator[0] != 0:
+            return accumulator[1] / accumulator[0]
+        else:
+            return None
+
+    def create_accumulator(self):
+        # [count, sum]
+        return [0, None]
+
+    def accumulate(self, accumulator, *args):
+        if args[0] is not None:
+            accumulator[0] += 1
+            if accumulator[1] is None:
+                accumulator[1] = args[0]
+            else:
+                accumulator[1] += args[0]
+
+    def retract(self, accumulator, *args):
+        if args[0] is not None:
+            if accumulator[1] is not None:
+                accumulator[0] -= 1
+                accumulator[1] -= args[0]
+
+    def merge(self, accumulator, accumulators):
+        for acc in accumulators:
+            if acc[1] is not None:

Review comment:
       ditto

##########
File path: flink-python/pyflink/table/functions.py
##########
@@ -20,12 +20,49 @@
 from abc import abstractmethod
 from decimal import Decimal
 
-from pyflink.table import AggregateFunction, MapView
+from pyflink.table import AggregateFunction, MapView, ListView
 
 MAX_LONG_VALUE = sys.maxsize
 MIN_LONG_VALUE = -MAX_LONG_VALUE - 1
 
 
+class AvgAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        # sum / count
+        if accumulator[0] != 0:
+            return accumulator[1] / accumulator[0]
+        else:
+            return None
+
+    def create_accumulator(self):
+        # [count, sum]
+        return [0, None]
+
+    def accumulate(self, accumulator, *args):
+        if args[0] is not None:
+            accumulator[0] += 1
+            if accumulator[1] is None:
+                accumulator[1] = args[0]
+            else:
+                accumulator[1] += args[0]
+
+    def retract(self, accumulator, *args):
+        if args[0] is not None:
+            if accumulator[1] is not None:

Review comment:
       ditto




----------------------------------------------------------------
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] HuangXingBo commented on a change in pull request #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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



##########
File path: flink-python/pyflink/table/functions.py
##########
@@ -179,3 +740,69 @@ class DecimalSum0AggFunction(Sum0AggFunction):
     def create_accumulator(self):
         # [sum]
         return [Decimal('0')]
+
+
+class SumAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        return accumulator[0]
+
+    def create_accumulator(self):
+        # [sum]
+        return [None]
+
+    def accumulate(self, accumulator, *args):
+        if args[0] is not None:
+            if accumulator[0] is None:
+                accumulator[0] = args[0]
+            else:
+                accumulator[0] += args[0]
+
+    def retract(self, accumulator, *args):
+        raise NotImplementedError("This function does not support retraction.")
+
+    def merge(self, accumulator, accumulators):
+        for acc in accumulators:
+            if acc[0] is not None:
+                if accumulator[0] is None:
+                    accumulator[0] = acc[0]
+                else:
+                    accumulator[0] += acc[0]
+
+
+class SumWithRetractAggFunction(AggregateFunction):
+
+    def get_value(self, accumulator):
+        if accumulator[1] == 0:
+            return None
+        else:
+            return accumulator[0]
+
+    def create_accumulator(self):
+        # [sum, count]
+        return [None, 0]

Review comment:
       I think we can optimize the initial value of `sum` to `0`, so that we can remove the logic of deciding whether `accumulator[0]` is None.




----------------------------------------------------------------
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 #13854: [FLINK-19235][python] Support mixed use with most built-in aggs for Python UDAF.

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


   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 0ce636d68f60fc7869e90cc00952ca975c6702f4 (Fri Oct 30 07:00:25 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 #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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






----------------------------------------------------------------
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 #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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


   


----------------------------------------------------------------
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] WeiZhong94 commented on pull request #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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






----------------------------------------------------------------
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 #13854: [FLINK-19235][python] Support mixed use with most built-in aggs for Python UDAF.

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0ce636d68f60fc7869e90cc00952ca975c6702f4 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 #13854: [FLINK-19235][python] Support more built-in aggs to be mixed use with Python UDAF

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


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8657",
       "triggerID" : "0ce636d68f60fc7869e90cc00952ca975c6702f4",
       "triggerType" : "PUSH"
     }, {
       "hash" : "61528214ab9174726bc24d8a3bb0e90bd7ff6947",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8663",
       "triggerID" : "61528214ab9174726bc24d8a3bb0e90bd7ff6947",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 0ce636d68f60fc7869e90cc00952ca975c6702f4 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8657) 
   * 61528214ab9174726bc24d8a3bb0e90bd7ff6947 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=8663) 
   
   <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