Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3470#discussion_r104392040
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/MaxAggFunctionWithRetract.scala
 ---
    @@ -115,12 +112,28 @@ abstract class MaxWithRetractAggFunction[T](implicit 
ord: Ordering[T]) extends A
       }
     
       override def merge(accumulators: JList[Accumulator]): Accumulator = {
    -    val ret = accumulators.get(0)
    +    val ret = 
accumulators.get(0).asInstanceOf[MaxWithRetractAccumulator[T]]
         var i: Int = 1
         while (i < accumulators.size()) {
           val a = 
accumulators.get(i).asInstanceOf[MaxWithRetractAccumulator[T]]
           if (a.f1 != 0) {
    -        accumulate(ret.asInstanceOf[MaxWithRetractAccumulator[T]], a.f0)
    +        val iterator = a.f2.keySet().iterator()
    +        while (iterator.hasNext()) {
    +          val key = iterator.next()
    +          //updating the resulting max value if needed
    +          if (ord.compare(ret.f0, key) < 0) {
    --- End diff --
    
    I think we can simply compare the max values of both accumulators (no need 
to compare all in the hash set) and merge both hash sets:
    ```
    // set max element
    if (ord.compare(ret.f0, key) < 0) {
      ret.f0 = a.f0;
    }
    // merge hash maps
    for (T key: a.f2.keySet()) {
      if (ret.f2.containsKey(key)) {
        ret.f2.put(key, ret.f2.get(key) + count)
      } else {
        ret.f2.put(key, a.f2.get(key))
      }
    }
    ```



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to