Class Traverser

  • Direct Known Subclasses:
    CollectorTraverser, CounterTraverser, MeasurementGroupByLevelCounter

    public abstract class Traverser
    extends java.lang.Object
    This class defines the main traversal framework and declares some methods for result process extension. This class could be extended to implement concrete tasks.
    Currently, the tasks are classified into two type:
    1. counter: to count the node num or measurement num that matches the path pattern
    2. collector: to collect customized results of the matched node or measurement
    • Field Detail

      • startNode

        protected IMNode startNode
      • nodes

        protected java.lang.String[] nodes
      • startIndex

        protected int startIndex
      • startLevel

        protected int startLevel
      • isPrefixStart

        protected boolean isPrefixStart
      • traverseContext

        protected java.util.Deque<IMNode> traverseContext
      • isInTemplate

        protected boolean isInTemplate
      • shouldTraverseTemplate

        protected boolean shouldTraverseTemplate
      • templateMap

        protected java.util.Map<java.lang.Integer,​Template> templateMap
      • isPrefixMatch

        protected boolean isPrefixMatch
    • Constructor Detail

      • Traverser

        public Traverser​(IMNode startNode,
                         org.apache.iotdb.commons.path.PartialPath path,
                         IMTreeStore store)
                  throws org.apache.iotdb.commons.exception.MetadataException
        To traverse subtree under root.sg, e.g., init Traverser(root, "root.sg.**")
        Parameters:
        startNode - denote which tree to traverse by passing its root
        path - use wildcard to specify which part to traverse
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
    • Method Detail

      • traverse

        public void traverse()
                      throws org.apache.iotdb.commons.exception.MetadataException
        The interface to start the traversal. The node process should be defined before traversal by overriding or implement concerned methods.
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
      • traverse

        protected void traverse​(IMNode node,
                                int idx,
                                int level)
                         throws org.apache.iotdb.commons.exception.MetadataException
        The recursive method for MTree traversal. If the node matches nodes[idx], then do some operation and traverse the children with nodes[idx+1].
        Parameters:
        node - current node that match the targetName in given path
        idx - the index of targetName in given path
        level - the level of current node in MTree
        Throws:
        org.apache.iotdb.commons.exception.MetadataException - some result process may throw MetadataException
      • processInternalMatchedMNode

        protected abstract boolean processInternalMatchedMNode​(IMNode node,
                                                               int idx,
                                                               int level)
                                                        throws org.apache.iotdb.commons.exception.MetadataException
        internal match: root.sg internal match root.sg.**(pattern)
        Returns:
        whether this branch of recursive traversal should stop; if true, stop
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
      • processFullMatchedMNode

        protected abstract boolean processFullMatchedMNode​(IMNode node,
                                                           int idx,
                                                           int level)
                                                    throws org.apache.iotdb.commons.exception.MetadataException
        full match: root.sg.d full match root.sg.**(pattern)
        Returns:
        whether this branch of recursive traversal should stop; if true, stop
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
      • processMultiLevelWildcard

        protected void processMultiLevelWildcard​(IMNode node,
                                                 int idx,
                                                 int level)
                                          throws org.apache.iotdb.commons.exception.MetadataException
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
      • processOneLevelWildcard

        protected void processOneLevelWildcard​(IMNode node,
                                               int idx,
                                               int level)
                                        throws org.apache.iotdb.commons.exception.MetadataException
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
      • processNameMatch

        protected void processNameMatch​(IMNode node,
                                        int idx,
                                        int level)
                                 throws org.apache.iotdb.commons.exception.MetadataException
        Throws:
        org.apache.iotdb.commons.exception.MetadataException
      • getUpperTemplate

        protected Template getUpperTemplate​(IMNode node)
      • setTemplateMap

        public void setTemplateMap​(java.util.Map<java.lang.Integer,​Template> templateMap)
      • setPrefixMatch

        public void setPrefixMatch​(boolean isPrefixMatch)
      • getCurrentPartialPath

        protected org.apache.iotdb.commons.path.PartialPath getCurrentPartialPath​(IMNode currentNode)
        Parameters:
        currentNode - the node need to get the full path of
        Returns:
        full path from traverse start node to the current node
      • getCurrentPathNodes

        protected java.lang.String[] getCurrentPathNodes​(IMNode currentNode)
      • getStorageGroupNodeInTraversePath

        protected IMNode getStorageGroupNodeInTraversePath​(IMNode currentNode)
        Returns:
        the storage group node in the traverse path