[SPARK-4274] [SQL] Fix NPE in printing the details of the query plan

Author: Cheng Hao <hao.cheng@intel.com>

Closes #3139 from chenghao-intel/comparison_test and squashes the following commits:

f5d7146 [Cheng Hao] avoid exception in printing the codegen enabled

(cherry picked from commit c764d0ac1c6410ca2dd2558cb6bcbe8ad5f02481)
Signed-off-by: Michael Armbrust <michael@databricks.com>