You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2020/02/27 03:29:29 UTC

[incubator-iotdb] branch master updated: Fix avg merge (#847)

This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 612b288  Fix avg merge (#847)
612b288 is described below

commit 612b2881bb75738ebb7b541f457ed3a8d8c2ff69
Author: Jialin Qiao <qj...@mails.tsinghua.edu.cn>
AuthorDate: Thu Feb 27 11:29:19 2020 +0800

    Fix avg merge (#847)
    
    * fix show child nodes bug
    
    * fix avg count
---
 .../org/apache/iotdb/db/query/aggregation/impl/AvgAggrResult.java   | 6 ++++++
 .../org/apache/iotdb/db/query/aggregation/AggregateResultTest.java  | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/AvgAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/AvgAggrResult.java
index a8e2250..2c4fd7a 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/AvgAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/AvgAggrResult.java
@@ -122,6 +122,7 @@ public class AvgAggrResult extends AggregateResult {
     AvgAggrResult anotherAvg = (AvgAggrResult) another;
     avg = avg * ((double) cnt / (cnt + anotherAvg.cnt)) +
         anotherAvg.avg * ((double) anotherAvg.cnt / (cnt + anotherAvg.cnt));
+    cnt += anotherAvg.cnt;
   }
 
   @Override
@@ -137,4 +138,9 @@ public class AvgAggrResult extends AggregateResult {
     ReadWriteIOUtils.write(avg, outputStream);
     ReadWriteIOUtils.write(cnt, outputStream);
   }
+
+  public long getCnt() {
+    return cnt;
+  }
+
 }
diff --git a/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java b/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java
index 21c1914..fd01468 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/aggregation/AggregateResultTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.query.aggregation.impl.AvgAggrResult;
 import org.apache.iotdb.db.query.factory.AggregateResultFactory;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
@@ -49,6 +50,7 @@ public class AggregateResultTest {
     avgAggrResult2.updateResultFromStatistics(statistics2);
     avgAggrResult1.merge(avgAggrResult2);
     Assert.assertEquals(1.333d, (double)avgAggrResult1.getResult(), 0.01);
+    Assert.assertEquals(3, ((AvgAggrResult) avgAggrResult1).getCnt());
 
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     avgAggrResult1.serializeTo(outputStream);