Re-apply patch for TEZ-1632.  Accidentally reverted as part of TEZ-1176 commit.

(cherry picked from commit 92b6b6b6722579eb0d29b43c3174a5c913f303a8)