public static FieldNode mergeFieldNode(FieldNode left, FieldNode right) {
    Preconditions.checkArgument(left.getFieldName() != null && right.getFieldName() != null);
    if (!left.getFieldName().equals(right.getFieldName())) {
      return null;
    }
    if (left.getNodes().isEmpty()) {
      return left;
    } else if (right.getNodes().isEmpty()) {
      return right;
    } else {
      // Both are not empty. Merge two lists.
      FieldNode result = new FieldNode(left.getFieldName());
      result.setNodes(mergeFieldNodes(left.getNodes(), right.getNodes()));
      return result;
    }
  }
Merge the field nodes 'left' and 'right' and return the merged node.
Return null if the two nodes cannot be merged.

There are basically 3 cases here:
1. 'left' and 'right' have the same depth, e.g., 'left' is s[b[c]] and
  'right' is s[b[d]]. In this case, the merged node is s[b[c,d]]
2. 'left' has larger depth than 'right', e.g., 'left' is s[b] while
  'right' is s[b[d]]. In this case, the merged node is s[b]
3. 'left' has smaller depth than 'right', e.g., 'left' is s[b[c]] while
  'right' is s[b]. This is the opposite case of 2), and similarly,
  the merged node is s[b].

A example where the two inputs cannot be merged is, 'left' is s[b] while
  'right' is p[c].
ql/src/java/org/apache/hadoop/hive/ql/optimizer/FieldNode.java