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

the detail please refer the comment of https://issues.apache.org/jira/browse/SPARK-3007
Remove this newline.

It seems that we duplicated `saveAsHiveFile` here and added a new version of `writeToFile` together with some other minor modifications to enable dynamic partitioning. I think we can move `writeToFile2` (also, please rename it to something like `wirteWithDynamicPartitions`) into `saveAsHiveFile` without hurting performance as long as we keep the critical path of writing without dynamic partitioning clean.