This is an automated email from the ASF dual-hosted git repository. jackietien 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 5f139cb8de [IOTDB-5604]Fix NPE when execute Agg + align by device query without assigned DataRegion 5f139cb8de is described below commit 5f139cb8de25d2a3ce15b9c70ded37d90a1e36bf Author: Weihao Li <60659567+wei-hao...@users.noreply.github.com> AuthorDate: Thu Mar 2 08:51:54 2023 +0800 [IOTDB-5604]Fix NPE when execute Agg + align by device query without assigned DataRegion --- .../iotdb/db/it/aggregation/IoTDBAggregationIT.java | 9 +++++++++ .../plan/planner/distribution/NodeGroupContext.java | 18 ++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBAggregationIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBAggregationIT.java index 65aee3dfc2..cd0a1253b1 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBAggregationIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/aggregation/IoTDBAggregationIT.java @@ -46,7 +46,9 @@ 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.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest; import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualWithDescOrderTest; +import static org.apache.iotdb.itbase.constant.TestConstant.DEVICE; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.fail; @@ -971,5 +973,12 @@ public class IoTDBAggregationIT { String[] retArray = new String[] {"0,null,"}; resultSetEqualWithDescOrderTest( "select count(s1), sum(s1) from root.test.noDataRegion", expectedHeader, retArray); + + expectedHeader = new String[] {DEVICE, count("s1"), sum("s1")}; + retArray = new String[] {"root.test.noDataRegion,0,null,"}; + resultSetEqualTest( + "select count(s1), sum(s1) from root.test.noDataRegion align by device", + expectedHeader, + retArray); } } diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/NodeGroupContext.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/NodeGroupContext.java index 6dda89e41f..cd943761ff 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/NodeGroupContext.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/distribution/NodeGroupContext.java @@ -29,7 +29,6 @@ import org.apache.iotdb.db.mpp.plan.planner.plan.node.source.SourceNode; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.stream.Collectors; public class NodeGroupContext { protected final MPPQueryContext queryContext; @@ -49,20 +48,19 @@ public class NodeGroupContext { private TRegionReplicaSet getMostlyUsedDataRegion(PlanNode root) { Map<TRegionReplicaSet, Long> regionCount = new HashMap<>(); countRegionOfSourceNodes(root, regionCount); - return Collections.max( - regionCount.entrySet().stream() - .filter(e -> e.getKey() != DataPartition.NOT_ASSIGNED) - .collect(Collectors.toList()), - Map.Entry.comparingByValue()) - .getKey(); + if (regionCount.isEmpty()) { + return DataPartition.NOT_ASSIGNED; + } + return Collections.max(regionCount.entrySet(), Map.Entry.comparingByValue()).getKey(); } private void countRegionOfSourceNodes(PlanNode root, Map<TRegionReplicaSet, Long> result) { root.getChildren().forEach(child -> countRegionOfSourceNodes(child, result)); if (root instanceof SourceNode) { - result.compute( - ((SourceNode) root).getRegionReplicaSet(), - (region, count) -> (count == null) ? 1 : count + 1); + TRegionReplicaSet regionReplicaSet = ((SourceNode) root).getRegionReplicaSet(); + if (regionReplicaSet != DataPartition.NOT_ASSIGNED) { + result.compute(regionReplicaSet, (region, count) -> (count == null) ? 1 : count + 1); + } } }