[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
Instead of using `vars` here can this just be?
```scala
val numDynamicPartitions = partSpec.values.filter(_.isEmpty).size
val numStaticPartitions = partSpec.values.filter(_.isDefined).size)
```