flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request #3470: [FLINK-5956] [table] Add retract method for aggreg...
Date Mon, 06 Mar 2017 11:43:13 GMT
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message