public void appendTemplateDevice(
      PartialPath devicePath, boolean isAligned, int templateId, Template template) {
    String[] nodes = devicePath.getNodes();
    SchemaNode cur = root;
    SchemaNode child;
    for (int i = 1; i < nodes.length - 1; i++) {
      child = cur.getChild(nodes[i]);
      if (child == null) {
        child = new SchemaInternalNode(nodes[i]);
        cur.addChild(nodes[i], child);
      }
      cur = child;
    }
    String deviceName = nodes[nodes.length - 1];
    child = cur.getChild(deviceName);
    if (child == null) {
      SchemaEntityNode entityNode = new SchemaEntityNode(deviceName);
      entityNode.setAligned(isAligned);
      entityNode.setTemplateId(templateId);
      cur.addChild(deviceName, entityNode);
    } else if (child.isEntity()) {
      child.getAsEntityNode().setTemplateId(templateId);
      child.getAsEntityNode().setAligned(isAligned);
    } else {
      SchemaEntityNode entityNode = new SchemaEntityNode(deviceName);
      entityNode.setAligned(isAligned);
      entityNode.setTemplateId(templateId);
      cur.replaceChild(deviceName, entityNode);
    }
    if (template != null) {
      templateMap.putIfAbsent(templateId, template);
    }
  }
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