[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
Another thing is that, we only need to calculate `dynamicPartPath` once for a single row. Just move this block before the `while`.