diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java index 136d481..b96e2eb 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/ASTNode.java @@ -143,9 +143,11 @@ private ASTNode getRootNodeWithValidASTStr (boolean useMemoizedRoot) { retNode = (ASTNode) retNode.parent; } rootNode=retNode; - rootNode.astStr = new StringBuffer(); - rootNode.toStringTree(rootNode); - rootNode.isValidASTStr = true; + if (!rootNode.isValidASTStr) { + rootNode.astStr = new StringBuffer(); + rootNode.toStringTree(rootNode); + rootNode.isValidASTStr = true; + } return retNode; } @@ -159,9 +161,6 @@ private void resetRootInformation() { rootNode.astStr = null; rootNode.isValidASTStr = false; } - // The root might have changed because of tree modifications. - // Compute the new root for this tree and set the astStr. - getRootNodeWithValidASTStr(false); } private int getMemoizedStringLen() { @@ -225,9 +224,10 @@ public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) { @Override public String toStringTree() { - // The tree modifier functions invalidate the old astStr, rootNode, etc. - // Hence, we can use the memoized root node and string values here. - ASTNode rootNode = (ASTNode)this.getRootNodeWithValidASTStr(true); + + // The root might have changed because of tree modifications. + // Compute the new root for this tree and set the astStr. + getRootNodeWithValidASTStr(true); // If rootNotModified is false, then startIndx and endIndx will be stale. if (startIndx >= 0 && endIndx <= rootNode.getMemoizedStringLen()) {