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/03/31 01:00:13 UTC

[GitHub] [iotdb] MarcosZyk opened a new pull request #5383: Implement SchemaTree Search

MarcosZyk opened a new pull request #5383:
URL: https://github.com/apache/iotdb/pull/5383


   ## Description
   
   Implement the local search interface of SchemaTree via SchemaTreeVisitor. Now it support * and **, slimit and offset.
   
   ## Future work
   Implement SchemaTree serialize and deserialize, and ISchemaFetcher.
   
   


-- 
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



[GitHub] [iotdb] JackieTien97 merged pull request #5383: Implement SchemaTree Search

Posted by GitBox <gi...@apache.org>.
JackieTien97 merged pull request #5383:
URL: https://github.com/apache/iotdb/pull/5383


   


-- 
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



[GitHub] [iotdb] MarcosZyk commented on a change in pull request #5383: Implement SchemaTree Search

Posted by GitBox <gi...@apache.org>.
MarcosZyk commented on a change in pull request #5383:
URL: https://github.com/apache/iotdb/pull/5383#discussion_r839118256



##########
File path: server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaNode.java
##########
@@ -19,7 +19,49 @@
 
 package org.apache.iotdb.db.mpp.common.schematree;
 
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
 public abstract class SchemaNode {
 
-  private String name;
+  protected final String name;
+
+  public SchemaNode(String name) {
+    this.name = name;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public SchemaNode getChild(String name) {
+    return null;
+  }
+
+  public void addChild(String name, SchemaNode child) {}
+
+  public Map<String, SchemaNode> getChildren() {
+    return Collections.emptyMap();
+  }
+
+  public Iterator<SchemaNode> getChildrenIterator() {
+    return Collections.emptyIterator();
+  }
+
+  public boolean isEntity() {
+    return false;
+  }
+
+  public boolean isMeasurement() {
+    return false;
+  }
+
+  public SchemaEntityNode getAsEntityNode() {
+    throw new ClassCastException("This not isn't instance of SchemaEntityNode.");

Review comment:
       Fixed.




-- 
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



[GitHub] [iotdb] SilverNarcissus commented on a change in pull request #5383: Implement SchemaTree Search

Posted by GitBox <gi...@apache.org>.
SilverNarcissus commented on a change in pull request #5383:
URL: https://github.com/apache/iotdb/pull/5383#discussion_r839103610



##########
File path: server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTreeVisitor.java
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.mpp.common.schematree;
+
+import org.apache.iotdb.db.metadata.path.MeasurementPath;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.regex.Pattern;
+
+import static org.apache.iotdb.commons.conf.IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;
+import static org.apache.iotdb.commons.conf.IoTDBConstant.ONE_LEVEL_PATH_WILDCARD;
+
+public class SchemaTreeVisitor implements Iterator<MeasurementPath> {
+
+  private final SchemaNode root;
+  private final String[] nodes;
+  private final boolean isPrefixMatch;
+
+  private final int limit;
+  private final int offset;
+  private final boolean hasLimit;
+
+  private int count = 0;
+  private int curOffset = -1;
+
+  private final Deque<Integer> indexStack = new LinkedList<>();
+  private final Deque<Iterator<SchemaNode>> stack = new LinkedList<>();
+  private final Deque<SchemaNode> context = new LinkedList<>();
+
+  private SchemaMeasurementNode nextMatchedNode;
+
+  public SchemaTreeVisitor(
+      SchemaNode root, PartialPath pathPattern, int slimit, int soffset, boolean isPrefixMatch) {
+    this.root = root;
+    nodes = pathPattern.getNodes();
+    this.isPrefixMatch = isPrefixMatch;
+
+    limit = slimit;
+    offset = soffset;
+    hasLimit = slimit != 0;
+
+    indexStack.push(0);
+    stack.push(Collections.singletonList(root).iterator());
+  }
+
+  @Override
+  public boolean hasNext() {
+    if (nextMatchedNode == null) {
+      getNext();
+    }
+    return nextMatchedNode != null;
+  }
+
+  @Override
+  public MeasurementPath next() {
+    if (!hasNext()) {
+      throw new NoSuchElementException();
+    }
+    MeasurementPath result = generateMeasurementPath();
+    nextMatchedNode = null;
+    return result;
+  }
+
+  public List<MeasurementPath> getAllResult() {
+    List<MeasurementPath> result = new LinkedList<>();

Review comment:
       Why we use a LinkedList rather than ArrayList here?

##########
File path: server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaNode.java
##########
@@ -19,7 +19,49 @@
 
 package org.apache.iotdb.db.mpp.common.schematree;
 
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
 public abstract class SchemaNode {
 
-  private String name;
+  protected final String name;
+
+  public SchemaNode(String name) {
+    this.name = name;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public SchemaNode getChild(String name) {
+    return null;
+  }
+
+  public void addChild(String name, SchemaNode child) {}
+
+  public Map<String, SchemaNode> getChildren() {
+    return Collections.emptyMap();
+  }
+
+  public Iterator<SchemaNode> getChildrenIterator() {
+    return Collections.emptyIterator();
+  }
+
+  public boolean isEntity() {
+    return false;
+  }
+
+  public boolean isMeasurement() {
+    return false;
+  }
+
+  public SchemaEntityNode getAsEntityNode() {
+    throw new ClassCastException("This not isn't instance of SchemaEntityNode.");

Review comment:
       Usually it's should be a UnsupportedOperationException.




-- 
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



[GitHub] [iotdb] MarcosZyk commented on a change in pull request #5383: Implement SchemaTree Search

Posted by GitBox <gi...@apache.org>.
MarcosZyk commented on a change in pull request #5383:
URL: https://github.com/apache/iotdb/pull/5383#discussion_r839118717



##########
File path: server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTreeVisitor.java
##########
@@ -0,0 +1,223 @@
+/*
+ * 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.mpp.common.schematree;
+
+import org.apache.iotdb.db.metadata.path.MeasurementPath;
+import org.apache.iotdb.db.metadata.path.PartialPath;
+
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.regex.Pattern;
+
+import static org.apache.iotdb.commons.conf.IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;
+import static org.apache.iotdb.commons.conf.IoTDBConstant.ONE_LEVEL_PATH_WILDCARD;
+
+public class SchemaTreeVisitor implements Iterator<MeasurementPath> {
+
+  private final SchemaNode root;
+  private final String[] nodes;
+  private final boolean isPrefixMatch;
+
+  private final int limit;
+  private final int offset;
+  private final boolean hasLimit;
+
+  private int count = 0;
+  private int curOffset = -1;
+
+  private final Deque<Integer> indexStack = new LinkedList<>();
+  private final Deque<Iterator<SchemaNode>> stack = new LinkedList<>();
+  private final Deque<SchemaNode> context = new LinkedList<>();
+
+  private SchemaMeasurementNode nextMatchedNode;
+
+  public SchemaTreeVisitor(
+      SchemaNode root, PartialPath pathPattern, int slimit, int soffset, boolean isPrefixMatch) {
+    this.root = root;
+    nodes = pathPattern.getNodes();
+    this.isPrefixMatch = isPrefixMatch;
+
+    limit = slimit;
+    offset = soffset;
+    hasLimit = slimit != 0;
+
+    indexStack.push(0);
+    stack.push(Collections.singletonList(root).iterator());
+  }
+
+  @Override
+  public boolean hasNext() {
+    if (nextMatchedNode == null) {
+      getNext();
+    }
+    return nextMatchedNode != null;
+  }
+
+  @Override
+  public MeasurementPath next() {
+    if (!hasNext()) {
+      throw new NoSuchElementException();
+    }
+    MeasurementPath result = generateMeasurementPath();
+    nextMatchedNode = null;
+    return result;
+  }
+
+  public List<MeasurementPath> getAllResult() {
+    List<MeasurementPath> result = new LinkedList<>();

Review comment:
       Fixed. I thought that since there won't be random access on this list, it will be better to use LinkedList, which will avoid Array copy during add.




-- 
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