This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch IOTDB-4159 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit bc974a5c01f0742ba65c67c95925cd8f5b6308fc Author: JackieTien97 <[email protected]> AuthorDate: Wed Aug 17 14:41:20 2022 +0800 [IOTDB-4159] Fix bug in group by while using left open and right close syntax --- .../iotdb/db/it/groupby/IoTDBLeftORightCIT.java | 70 ++++++++++++++++++++++ .../iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java | 12 +++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/groupby/IoTDBLeftORightCIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/groupby/IoTDBLeftORightCIT.java new file mode 100644 index 0000000000..befa114755 --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/groupby/IoTDBLeftORightCIT.java @@ -0,0 +1,70 @@ +/* + * 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.it.groupby; + +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.ClusterIT; +import org.apache.iotdb.itbase.category.LocalStandaloneIT; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import static org.apache.iotdb.db.constant.TestConstant.count; +import static org.apache.iotdb.db.it.utils.TestUtils.prepareData; +import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualWithDescOrderTest; +import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR; + +@RunWith(IoTDBTestRunner.class) +@Category({LocalStandaloneIT.class, ClusterIT.class}) +public class IoTDBLeftORightCIT { + + private static final String[] sqls = + new String[] { + "insert into root.sg1.d1(time, s1) values(9, 9)", + }; + + @BeforeClass + public static void setUp() throws Exception { + EnvFactory.getEnv().initBeforeClass(); + prepareData(sqls); + } + + @AfterClass + public static void tearDown() throws Exception { + EnvFactory.getEnv().cleanAfterClass(); + } + + @Test + public void testLeftORightCGroupBy() { + String[] expectedHeader = + new String[] { + TIMESTAMP_STR, count("root.sg1.d1.s1"), + }; + String[] retArray = + new String[] { + "2,0,", "4,0,", "6,0,", "8,0,", "9,1,", + }; + resultSetEqualWithDescOrderTest( + "select count(s1) from root.sg1.d1 group by((0, 9], 2ms)", expectedHeader, retArray); + } +} diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java index 4927629622..3145724708 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/AnalyzeVisitor.java @@ -1690,11 +1690,19 @@ public class AnalyzeVisitor extends StatementVisitor<Analysis, MPPQueryContext> groupByTimeComponent.isIntervalByMonth(), TimeZone.getTimeZone("+00:00")); } else { + long startTime = + groupByTimeComponent.isLeftCRightO() + ? groupByTimeComponent.getStartTime() + : groupByTimeComponent.getStartTime() + 1; + long endTime = + groupByTimeComponent.isLeftCRightO() + ? groupByTimeComponent.getEndTime() + : groupByTimeComponent.getEndTime() + 1; return new GroupByFilter( groupByTimeComponent.getInterval(), groupByTimeComponent.getSlidingStep(), - groupByTimeComponent.getStartTime(), - groupByTimeComponent.getEndTime()); + startTime, + endTime); } }
