You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2021/12/03 01:35:00 UTC

[iotdb] branch master updated: [IOTDB-2088] Fix IndexOutOfBound exception in AggregationPlan.groupAggResultByLevel (#4518)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e78f1b6  [IOTDB-2088] Fix IndexOutOfBound exception in AggregationPlan.groupAggResultByLevel (#4518)
e78f1b6 is described below

commit e78f1b6cb83deab0c85df9d6b354f8dee53e5f0d
Author: BaiJian <er...@hotmail.com>
AuthorDate: Fri Dec 3 09:34:17 2021 +0800

    [IOTDB-2088] Fix IndexOutOfBound exception in AggregationPlan.groupAggResultByLevel (#4518)
---
 .../aggregation/IoTDBAggregationByLevelIT.java     | 66 +++++++++-------------
 .../aggregation/IoTDBAggregationSmallDataIT.java   | 27 ++++++---
 .../iotdb/db/qp/physical/crud/AggregationPlan.java |  2 +-
 3 files changed, 45 insertions(+), 50 deletions(-)

diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java
index 5d35590..1b5b40c 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java
@@ -21,18 +21,16 @@ package org.apache.iotdb.db.integration.aggregation;
 import org.apache.iotdb.db.constant.TestConstant;
 import org.apache.iotdb.db.qp.Planner;
 import org.apache.iotdb.db.qp.logical.crud.AggregationQueryOperator;
-import org.apache.iotdb.db.utils.EnvironmentUtils;
+import org.apache.iotdb.integration.env.EnvFactory;
 import org.apache.iotdb.itbase.category.LocalStandaloneTest;
-import org.apache.iotdb.jdbc.Config;
 
-import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Assert;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;
 
@@ -67,26 +65,26 @@ public class IoTDBAggregationByLevelIT {
 
   private static final double DOUBLE_PRECISION = 0.001d;
 
-  @Before
-  public void setUp() throws Exception {
-    EnvironmentUtils.closeStatMonitor();
-    EnvironmentUtils.envSetUp();
-    Class.forName(Config.JDBC_DRIVER_NAME);
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initBeforeClass();
     prepareData();
   }
 
-  @After
-  public void tearDown() throws Exception {
-    EnvironmentUtils.cleanEnv();
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
   }
 
   @Test
   public void sumFuncGroupByLevelTest() throws Exception {
     double[] retArray = new double[] {243.410d, 380.460d, 623.870d, 91.83d, 151.58d};
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
-      statement.execute("select sum(temperature) from root.sg1.* GROUP BY level=1");
+      // Here we duplicate the column to test the bug
+      // https://issues.apache.org/jira/browse/IOTDB-2088
+      statement.execute(
+          "select sum(temperature), sum(temperature) from root.sg1.* GROUP BY level=1");
 
       int cnt = 0;
       try (ResultSet resultSet = statement.getResultSet()) {
@@ -131,8 +129,7 @@ public class IoTDBAggregationByLevelIT {
   @Test
   public void avgFuncGroupByLevelTest() throws Exception {
     double[] retArray = new double[] {48.682d, 95.115d, 69.319d, 45.915d, 50.527d};
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
       statement.execute("select avg(temperature) from root.sg1.* GROUP BY level=1");
 
@@ -179,8 +176,7 @@ public class IoTDBAggregationByLevelIT {
   @Test
   public void timeFuncGroupByLevelTest() throws Exception {
     String[] retArray = new String[] {"5,3,100,200", "600,700,2,3", "600,700,500"};
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
       statement.execute(
           "select count(status), min_time(temperature) from root.*.* GROUP BY level=2");
@@ -241,8 +237,7 @@ public class IoTDBAggregationByLevelIT {
         new String[] {
           "61.22,125.5", "71.12,62.15,71.12,62.15",
         };
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
       statement.execute(
           "select last_value(temperature), max_value(temperature) from root.*.* GROUP BY level=0");
@@ -282,8 +277,7 @@ public class IoTDBAggregationByLevelIT {
   @Test
   public void countStarGroupByLevelTest() throws Exception {
     String[] retArray = new String[] {"17", "8"};
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
       statement.execute("select count(*) from root.*.* GROUP BY level=0");
 
@@ -311,8 +305,7 @@ public class IoTDBAggregationByLevelIT {
   @Test
   public void GroupByLevelSLimitTest() throws Exception {
     String[] retArray = new String[] {"5,4", "4,6", "3"};
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
       statement.execute(
           "select count(temperature), count(status) from root.*.* GROUP BY level=1 slimit 2");
@@ -371,8 +364,7 @@ public class IoTDBAggregationByLevelIT {
           "null,null,null,null",
           "null,500,null,125.5",
         };
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
 
       statement.execute(
@@ -412,8 +404,7 @@ public class IoTDBAggregationByLevelIT {
         new String[] {
           "null", "88.24", "105.5", "null", "null", "125.5",
         };
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
 
       statement.execute(
@@ -436,8 +427,7 @@ public class IoTDBAggregationByLevelIT {
     String[] retArray2 =
         new String[] {"0,0,0", "100,1,1", "200,1,2", "300,0,1", "400,0,0", "500,1,0"};
 
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
 
       statement.execute(
@@ -480,8 +470,7 @@ public class IoTDBAggregationByLevelIT {
         new String[] {
           "true", "3",
         };
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
       statement.execute("select last_value(status) from root.*.* GROUP BY level=0");
 
@@ -508,8 +497,7 @@ public class IoTDBAggregationByLevelIT {
    */
   @Test
   public void TestGroupByLevelWithoutAggregationFunc() {
-    try (Connection connection =
-            DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
 
       statement.execute("select temperature from root.sg1.* group by level = 2");
@@ -520,10 +508,8 @@ public class IoTDBAggregationByLevelIT {
     }
   }
 
-  private void prepareData() {
-    try (Connection connection =
-            DriverManager.getConnection(
-                Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+  private static void prepareData() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
 
       for (String sql : dataSet) {
diff --git a/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java b/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
index e4be3ea..1c564a3 100644
--- a/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
+++ b/integration/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationSmallDataIT.java
@@ -25,9 +25,9 @@ import org.apache.iotdb.itbase.category.ClusterTest;
 import org.apache.iotdb.itbase.category.LocalStandaloneTest;
 import org.apache.iotdb.jdbc.IoTDBSQLException;
 
-import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Assert;
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
@@ -35,7 +35,16 @@ import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
 
-import static org.apache.iotdb.db.constant.TestConstant.*;
+import static org.apache.iotdb.db.constant.TestConstant.avg;
+import static org.apache.iotdb.db.constant.TestConstant.count;
+import static org.apache.iotdb.db.constant.TestConstant.extreme;
+import static org.apache.iotdb.db.constant.TestConstant.firstValue;
+import static org.apache.iotdb.db.constant.TestConstant.lastValue;
+import static org.apache.iotdb.db.constant.TestConstant.maxTime;
+import static org.apache.iotdb.db.constant.TestConstant.maxValue;
+import static org.apache.iotdb.db.constant.TestConstant.minTime;
+import static org.apache.iotdb.db.constant.TestConstant.minValue;
+import static org.apache.iotdb.db.constant.TestConstant.sum;
 import static org.junit.Assert.fail;
 
 /** Multiple aggregation with filter test. */
@@ -106,15 +115,15 @@ public class IoTDBAggregationSmallDataIT {
         "insert into root.vehicle.d0(timestamp,s4) values(100, true)"
       };
 
-  @Before
-  public void setUp() throws Exception {
-    EnvFactory.getEnv().initBeforeTest();
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initBeforeClass();
     insertSQL();
   }
 
-  @After
-  public void tearDown() throws Exception {
-    EnvFactory.getEnv().cleanAfterTest();
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterClass();
   }
 
   @Test
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/AggregationPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/AggregationPlan.java
index 3943a74..f61e7a6 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/AggregationPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/AggregationPlan.java
@@ -89,7 +89,7 @@ public class AggregationPlan extends RawDataQueryPlan {
     if (!groupPathsResultMap.isEmpty()) {
       groupPathsResultMap.clear();
     }
-    for (int i = 0; i < paths.size(); i++) {
+    for (int i = 0; i < getDeduplicatedPaths().size(); i++) {
       String rawPath =
           String.format(
               "%s(%s)",