public void createLogicalView(PartialPath path, ViewExpression viewExpression)
      throws MetadataException {
    String[] nodeNames = path.getNodes();
    if (nodeNames.length <= 2) {
      throw new IllegalPathException(path.getFullPath());
    }
    MetaFormatUtils.checkTimeseries(path);
    PartialPath devicePath =
        new PartialPath(Arrays.copyOf(path.getNodes(), path.getNodeLength() - 1));
    ICachedMNode deviceParent = checkAndAutoCreateInternalPath(devicePath);

    try {
      // synchronize check and add, we need addChild and add Alias become atomic operation
      // only write on mtree will be synchronized
      synchronized (this) {
        ICachedMNode device = checkAndAutoCreateDeviceNode(devicePath.getTailNode(), deviceParent);
        try {
          String leafName = path.getMeasurement();
          if (store.hasChild(device, leafName)) {
            ICachedMNode node = device.getChild(leafName);
            if (node.isMeasurement()) {
              if (node.getAsMeasurementMNode().isPreDeleted()) {
                throw new MeasurementInBlackListException(path);
              } else {
                throw new MeasurementAlreadyExistException(
                    path.getFullPath(), node.getAsMeasurementMNode().getMeasurementPath());
              }
            } else {
              throw new PathAlreadyExistException(path.getFullPath());
            }
          }

          IDeviceMNode<ICachedMNode> entityMNode;
          if (device.isDevice()) {
            entityMNode = device.getAsDeviceMNode();
          } else {
            entityMNode = store.setToEntity(device);
            // this parent has no measurement before. The leafName is his first child who is a
            // logical
            // view.
            entityMNode.setAligned(null);
            device = entityMNode.getAsMNode();
          }

          IMeasurementMNode<ICachedMNode> viewMNode =
              nodeFactory.createLogicalViewMNode(
                  entityMNode, leafName, new LogicalViewSchema(leafName, viewExpression));
          store.addChild(entityMNode.getAsMNode(), leafName, viewMNode.getAsMNode());
          unPinMNode(viewMNode.getAsMNode());
        } finally {
          unPinMNode(device);
        }
      }
    } finally {
      if (deviceParent != null) {
        unPinMNode(deviceParent);
      }
    }
  }
Get node by the path

@return last node in given seriesPath
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java