This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch GroupByBug in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 5d7cf5609d7755e898e9e1b7dd173cb539002008 Author: JackieTien97 <[email protected]> AuthorDate: Thu May 20 19:06:48 2021 +0800 Fix group by bug --- .../dataset/groupby/LocalGroupByExecutor.java | 3 + .../iotdb/db/integration/IoTDBGroupByUnseqIT.java | 130 +++++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java index 3a4200d..b8cec3d 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java +++ b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor.java @@ -331,6 +331,9 @@ public class LocalGroupByExecutor implements GroupByExecutor { // stop calc and cached current batchData if (ascending && batchData.currentTime() >= curEndTime) { preCachedData = batchData; + // reset the last position to current Index + lastReadCurArrayIndex = batchData.getReadCurArrayIndex(); + lastReadCurListIndex = batchData.getReadCurListIndex(); return true; } diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByUnseqIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByUnseqIT.java new file mode 100644 index 0000000..a00c27e --- /dev/null +++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByUnseqIT.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.db.integration; + +import static org.apache.iotdb.db.constant.TestConstant.count; +import static org.junit.Assert.fail; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; +import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.apache.iotdb.db.utils.EnvironmentUtils; +import org.apache.iotdb.jdbc.Config; +import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class IoTDBGroupByUnseqIT { + + private static String[] dataSet1 = new String[]{ + "SET STORAGE GROUP TO root.sg1", + "CREATE TIMESERIES root.sg1.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN", + "INSERT INTO root.sg1.d1(time,s1) values(1, 1)", + "INSERT INTO root.sg1.d1(time,s1) values(2, 2)", + "INSERT INTO root.sg1.d1(time,s1) values(3, 3)", + "INSERT INTO root.sg1.d1(time,s1) values(4, 4)", + "INSERT INTO root.sg1.d1(time,s1) values(8, 8)", + "INSERT INTO root.sg1.d1(time,s1) values(10, 10)", + "INSERT INTO root.sg1.d1(time,s1) values(11, 11)", + "INSERT INTO root.sg1.d1(time,s1) values(12, 12)", + "flush", + "INSERT INTO root.sg1.d1(time,s1) values(7, 7)", + "INSERT INTO root.sg1.d1(time,s1) values(9, 9)", + "flush" + }; + + private static final String TIMESTAMP_STR = "Time"; + + private boolean enableUnseqCompaction; + private int maxNumberOfPointsInPage; + + + @Before + public void setUp() throws Exception { + EnvironmentUtils.closeStatMonitor(); + enableUnseqCompaction = IoTDBDescriptor.getInstance().getConfig().isEnableUnseqCompaction(); + IoTDBDescriptor.getInstance().getConfig().setEnableUnseqCompaction(false); + maxNumberOfPointsInPage = TSFileDescriptor.getInstance().getConfig() + .getMaxNumberOfPointsInPage(); + TSFileDescriptor.getInstance().getConfig().setMaxNumberOfPointsInPage(4); + EnvironmentUtils.envSetUp(); + Class.forName(Config.JDBC_DRIVER_NAME); + prepareData(); + } + + + private void prepareData() { + try (Connection connection = DriverManager + .getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", + "root"); + Statement statement = connection.createStatement();) { + + for (String sql : dataSet1) { + statement.execute(sql); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @After + public void tearDown() throws Exception { + EnvironmentUtils.cleanEnv(); + IoTDBDescriptor.getInstance().getConfig().setEnableUnseqCompaction(enableUnseqCompaction); + TSFileDescriptor.getInstance().getConfig().setMaxNumberOfPointsInPage(maxNumberOfPointsInPage); + } + + @Test + public void test1() { + String[] retArray1 = new String[]{ + "1,3", + "4,1", + "7,3", + "10,3", + }; + + try (Connection connection = DriverManager. + getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root"); + Statement statement = connection.createStatement()) { + boolean hasResultSet = statement.execute( + "select count(s1) from root.sg1.d1 group by ([1, 13), 3ms)"); + + Assert.assertTrue(hasResultSet); + int cnt; + try (ResultSet resultSet = statement.getResultSet()) { + cnt = 0; + while (resultSet.next()) { + String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet + .getString(count("root.sg1.d1.s1")); + Assert.assertEquals(retArray1[cnt], ans); + cnt++; + } + Assert.assertEquals(retArray1.length, cnt); + } + } catch (Exception e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } +}
