[SPARK-3007][SQL]Add "Dynamic Partition" support to Spark Sql hive

a new PR base on new master.  changes are the same as https://github.com/apache/spark/pull/1919
In general we try and avoid functional programming in the critical path (any piece of code that will be run for every tuple).  If I understand correctly we are going to calculate this for each tuple and thus this could be pretty expensive.  Since I think it might be hard to optimize this, its not critical for this PR, but I'd at least add a TODO here.