private void traverseAndMerge(SchemaNode thisNode, SchemaNode thisParent, SchemaNode thatNode) {
    SchemaNode thisChild;
    SchemaEntityNode entityNode;
    // merge template device
    if (thatNode.isEntity() && thatNode.getAsEntityNode().getTemplateId() != NON_TEMPLATE) {
      if (thisNode.isEntity()) {
        entityNode = thisNode.getAsEntityNode();
      } else {
        entityNode = new SchemaEntityNode(thisNode.getName());
        thisParent.replaceChild(thisNode.getName(), entityNode);
        thisNode = entityNode;
      }
      entityNode.setTemplateId(thatNode.getAsEntityNode().getTemplateId());
    }
    // merge normal device, internal node and measurement
    for (SchemaNode thatChild : thatNode.getChildren().values()) {
      thisChild = thisNode.getChild(thatChild.getName());
      if (thisChild == null) {
        thisNode.addChild(thatChild.getName(), thatChild);
        if (thatChild.isMeasurement()) {
          SchemaEntityNode thatEntity = thatNode.getAsEntityNode();
          if (thisNode.isEntity()) {
            entityNode = thisNode.getAsEntityNode();
          } else {
            entityNode = new SchemaEntityNode(thisNode.getName());
            thisParent.replaceChild(thisNode.getName(), entityNode);
            thisNode = entityNode;
          }

          if (!entityNode.isAligned()) {
            entityNode.setAligned(thatEntity.isAligned());
          }
          SchemaMeasurementNode measurementNode = thatChild.getAsMeasurementNode();
          if (measurementNode.getAlias() != null) {
            entityNode.addAliasChild(measurementNode.getAlias(), measurementNode);
          }
        }
      } else {
        traverseAndMerge(thisChild, thisNode, thatChild);
      }
    }
  }
Append a template device to the schema tree.

@param devicePath device path
@param isAligned whether the device is aligned
@param templateId template id
@param template template instance, used to search measurement schema, it can be null if
    write-only
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/common/schematree/ClusterSchemaTree.java