You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/01/07 06:53:27 UTC
[GitHub] [iotdb] SilverNarcissus commented on a change in pull request #4727: [IOTDB-2295] Fix Timeseries count group by level Bug
SilverNarcissus commented on a change in pull request #4727:
URL: https://github.com/apache/iotdb/pull/4727#discussion_r780059832
##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mtree/traverser/counter/MeasurementGroupByLevelCounter.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.metadata.mtree.traverser.counter;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.IMNode;
+import org.apache.iotdb.db.metadata.mtree.traverser.Traverser;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MeasurementGroupByLevelCounter extends Traverser {
+
+ // level query option
+ private int groupByLevel;
+
+ private Map<PartialPath, Integer> result = new HashMap<>();
+
+ // path representing current branch and matching the pattern and level
+ private PartialPath path;
+
+ public MeasurementGroupByLevelCounter(IMNode startNode, PartialPath path, int groupByLevel)
+ throws MetadataException {
+ super(startNode, path);
+ this.groupByLevel = groupByLevel;
+ }
+
+ @Override
+ protected boolean processInternalMatchedMNode(IMNode node, int idx, int level)
+ throws MetadataException {
+ if (level == groupByLevel) {
+ path = node.getPartialPath();
+ if (!result.containsKey(path)) {
+ result.put(path, 0);
Review comment:
You can use putIfAbsent method to save look up time
##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mtree/traverser/counter/MeasurementGroupByLevelCounter.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.metadata.mtree.traverser.counter;
+
+import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.IMNode;
+import org.apache.iotdb.db.metadata.mtree.traverser.Traverser;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MeasurementGroupByLevelCounter extends Traverser {
+
+ // level query option
+ private int groupByLevel;
+
+ private Map<PartialPath, Integer> result = new HashMap<>();
+
+ // path representing current branch and matching the pattern and level
+ private PartialPath path;
+
+ public MeasurementGroupByLevelCounter(IMNode startNode, PartialPath path, int groupByLevel)
+ throws MetadataException {
+ super(startNode, path);
+ this.groupByLevel = groupByLevel;
+ }
+
+ @Override
+ protected boolean processInternalMatchedMNode(IMNode node, int idx, int level)
+ throws MetadataException {
+ if (level == groupByLevel) {
+ path = node.getPartialPath();
+ if (!result.containsKey(path)) {
+ result.put(path, 0);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected boolean processFullMatchedMNode(IMNode node, int idx, int level)
+ throws MetadataException {
+ if (level == groupByLevel) {
+ path = node.getPartialPath();
+ if (!result.containsKey(path)) {
+ result.put(path, 0);
Review comment:
You can use putIfAbsent method to save look up time
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org