public static FieldNode addNodeByPath(
    FieldNode fieldNode,
    String path) {
    if (path == null || path.isEmpty()) {
      return fieldNode;
    }
    boolean found = false;
    int index = 0;
    String[] ps = path.split("\\.");
    FieldNode c = fieldNode;
    if (fieldNode != null) {
      List<FieldNode> currentList = Arrays.asList(c);
      while (index < ps.length) {
        found = false;
        for (FieldNode n : currentList) {
          if (n.getFieldName().equals(ps[index])) {
            found = true;
            // If the matched field is leaf which means all leaves are required, not need to go
            // deeper.
            if (n.getNodes().isEmpty()) {
              return fieldNode;
            }
            c = n;
            currentList = c.getNodes();
            break;
          }
        }
        if (found) {
          index++;
        } else {
          break;
        }
      }
    }

    if (!found) {
      while (index < ps.length) {
        FieldNode n = new FieldNode(ps[index]);
        if (fieldNode == null) {
          // rebuild the tree since original is empty
          fieldNode = n;
        }
        if (c != null) {
          c.addFieldNodes(n);
        }
        c = n;
        index++;
      }
    } else {
      if (index == ps.length) {
        // Consolidation since all leaves are required.
        c.getNodes().clear();
      }
    }
    return fieldNode;
  }
Add a leaf node to the field tree if the specified path is not contained by
current tree specified by the passed parameter field node.

@param fieldNode the root of the column tree
@param path contains the path from root to leaf
@return the root of the newly built tree
ql/src/java/org/apache/hadoop/hive/ql/optimizer/NestedColumnFieldPruningUtils.java