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