LantaoJin commented on a change in pull request #25840: [SPARK-29166][SQL] Add
parameters to limit the number of dynamic partitions for data source table
URL: https://github.com/apache/spark/pull/25840#discussion_r327027878
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/SQLHadoopMapReduceCommitProtocol.scala
##########
@@ -63,7 +70,29 @@ class SQLHadoopMapReduceCommitProtocol(
committer = ctor.newInstance()
}
}
+ totalPartitions = new AtomicInteger(0)
logInfo(s"Using output committer class
${committer.getClass.getCanonicalName}")
committer
}
+
+ override def newTaskTempFile(
+ taskContext: TaskAttemptContext, dir: Option[String], ext: String):
String = {
+ val path = super.newTaskTempFile(taskContext, dir, ext)
+ totalPartitions.incrementAndGet()
+ if (dynamicPartitionOverwrite) {
+ if (totalPartitions.get > maxDynamicPartitions) {
Review comment:
Here is a simple testing for Hive table:
```sql
bin/spark-sql --master local --hiveconf
hive.exec.dynamic.partition.mode=nonstrict --hiveconf
hive.exec.dynamic.partition=true --hiveconf hive.exec.max.dynamic.partitions=3
spark-sql>create temporary view t4 (key, value) as select 2,
explode(array(1, 2, 3, 4));
spark-sql>select * from t4;
2 1
2 2
2 3
2 4
>insert into table p partition(key) select key, value from t4;
Error in query: org.apache.hadoop.hive.ql.metadata.HiveException: Number of
dynamic partitions created is 4, which is more than 3. To solve this try to set
hive.exec.max.dynamic.partitions to at least 4.;
spark-sql>create temporary view t3 (key, value) as select 2,
explode(array(1, 2, 3));
spark-sql>select * from t3;
2 1
2 2
2 3
spark-sql>insert into table p partition(key) select key, value from t3;
spark-sql>insert into table p partition(key) select key, value from t3;
spark-sql>select * from p;
2 1
2 1
2 2
2 2
2 3
2 3
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]