Commit 8a6b685
[SPARK-54853][SQL] Always check
### What changes were proposed in this pull request?
This PR makes `hive.exec.max.dynamic.partitions` check always happens on the spark side on performing dynamic partition overwrite to Hive SerDe tables, and skips the hive side check by setting `hive.exec.max.dynamic.partitions` to `Int.MaxValue` for shared `Hive`'s conf, also assigns the error condition `_LEGACY_ERROR_TEMP_2277` with a proper name `DYNAMIC_PARTITION_WRITE_PARTITION_NUM_LIMIT_EXCEEDED`
### Why are the changes needed?
SPARK-37217 partially handles `hive.exec.max.dynamic.partitions` on the spark side, but only for `INSERT OVERWRITE` case on performing dynamic partition overwrite to an external Hive SerDe table, which reduces the data loss risks but still has risks, e.g. when the user updates(especially increases) the session conf `hive.exec.max.dynamic.partitions`, it only takes effect on the spark side, the shared `Hive` still uses a static hadoop conf from `sc.newHadoopConf`, thus if the user hits the error and increases the value by following the error message's suggestion, it can pass the spark side check but fail on the hive side later, then data loss issue mentioned in SPARK-37217 will happens again.
Currently, the following three frequently used configs related to dynamic partition overwrite for Hive SerDe tables have inconsistent behaviors
```
-- this works
SET hive.exec.dynamic.partition=true;
-- this also works
SET hive.exec.dynamic.partition.mode=nonstrict;
-- this does not work, but the error message suggests the user to do that
SET hive.exec.max.dynamic.partitions=1001;
```
```
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Number of dynamic partitions created is 3, which is more than 2. To solve this try to set hive.exec.max.dynamic.partitions to at least 3.
at org.apache.hadoop.hive.ql.metadata.Hive.getValidPartitionsInPath(Hive.java:1862)
at org.apache.hadoop.hive.ql.metadata.Hive.loadDynamicPartitions(Hive.java:1902)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.apache.spark.sql.hive.client.Shim_v2_1.loadDynamicPartitions(HiveShim.scala:1110)
at org.apache.spark.sql.hive.client.HiveClientImpl.$anonfun$loadDynamicPartitions$1(HiveClientImpl.scala:1013)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at org.apache.spark.sql.hive.client.HiveClientImpl.$anonfun$withHiveState$1(HiveClientImpl.scala:294)
at org.apache.spark.sql.hive.client.HiveClientImpl.liftedTree1$1(HiveClientImpl.scala:237)
at org.apache.spark.sql.hive.client.HiveClientImpl.retryLocked(HiveClientImpl.scala:236)
at org.apache.spark.sql.hive.client.HiveClientImpl.withHiveState(HiveClientImpl.scala:274)
at org.apache.spark.sql.hive.client.HiveClientImpl.loadDynamicPartitions(HiveClientImpl.scala:1004)
at org.apache.spark.sql.hive.HiveExternalCatalog.$anonfun$loadDynamicPartitions$1(HiveExternalCatalog.scala:1051)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at org.apache.spark.sql.hive.HiveExternalCatalog.withClient(HiveExternalCatalog.scala:105)
at org.apache.spark.sql.hive.HiveExternalCatalog.loadDynamicPartitions(HiveExternalCatalog.scala:1031)
...
```
### Does this PR introduce _any_ user-facing change?
Yes, with this change, users are allowed to set `hive.exec.max.dynamic.partitions` in session conf, e.g., by executing `SET hive.exec.max.dynamic.partitions=1001`, and users will see more consistent behavior on `hive.exec.max.dynamic.partitions` checks, it always perform checks before calling external catalog `loadDynamicPartitions`, for both managed and external table, and both `INSERT INTO` and `INSERT OVERWRITE` dynamic partition write operation for Hive SerDe tables.
### How was this patch tested?
New UT is added.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #53624 from pan3793/SPARK-54853.
Lead-authored-by: Cheng Pan <[email protected]>
Co-authored-by: Cheng Pan <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>hive.exec.max.dynamic.partitions on the spark side1 parent eec092c commit 8a6b685
File tree
5 files changed
+58
-18
lines changed- common/utils/src/main/resources/error
- sql
- catalyst/src/main/scala/org/apache/spark/sql/errors
- hive/src
- main/scala/org/apache/spark/sql/hive
- client
- execution
- test/scala/org/apache/spark/sql/hive
5 files changed
+58
-18
lines changedLines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1575 | 1575 | | |
1576 | 1576 | | |
1577 | 1577 | | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
1578 | 1584 | | |
1579 | 1585 | | |
1580 | 1586 | | |
| |||
9409 | 9415 | | |
9410 | 9416 | | |
9411 | 9417 | | |
9412 | | - | |
9413 | | - | |
9414 | | - | |
9415 | | - | |
9416 | | - | |
9417 | 9418 | | |
9418 | 9419 | | |
9419 | 9420 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2484 | 2484 | | |
2485 | 2485 | | |
2486 | 2486 | | |
2487 | | - | |
| 2487 | + | |
2488 | 2488 | | |
2489 | | - | |
| 2489 | + | |
2490 | 2490 | | |
2491 | | - | |
2492 | | - | |
| 2491 | + | |
2493 | 2492 | | |
2494 | 2493 | | |
2495 | 2494 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1399 | 1399 | | |
1400 | 1400 | | |
1401 | 1401 | | |
| 1402 | + | |
| 1403 | + | |
1402 | 1404 | | |
1403 | 1405 | | |
1404 | 1406 | | |
| |||
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
51 | 89 | | |
0 commit comments