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 2018/11/21 13:05:19 UTC

[GitHub] twalthr closed pull request #7076: [FLINK-10674] [table] Fix DistinctAccumulator.remove lead to NPE.

twalthr closed pull request #7076: [FLINK-10674] [table] Fix DistinctAccumulator.remove lead to NPE.
URL: https://github.com/apache/flink/pull/7076
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/DistinctAccumulator.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/DistinctAccumulator.scala
index 3427c9c96f7..91c2f923b72 100644
--- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/DistinctAccumulator.scala
+++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/DistinctAccumulator.scala
@@ -101,13 +101,18 @@ class DistinctAccumulator[ACC](
     * @return true if no instances of the parameters remain in the map, false otherwise.
     */
   def remove(params: Row): Boolean = {
-    val currentCnt = distinctValueMap.get(params)
-    if (currentCnt == 1) {
-      distinctValueMap.remove(params)
+    if (!distinctValueMap.contains(params)) {
       true
     } else {
-      distinctValueMap.put(params, currentCnt - 1L)
-      false
+      val currentCnt = distinctValueMap.get(params)
+
+      if (currentCnt == null || currentCnt <= 1) {
+        distinctValueMap.remove(params)
+        true
+      } else {
+        distinctValueMap.put(params, currentCnt - 1L)
+        false
+      }
     }
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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