[SPARK-3198] [SQL] Generate the expression id when necessary