Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/2226#discussion_r17625525
--- Diff:
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala
---
@@ -178,6 +256,40 @@ case class InsertIntoHiveTable(
val tableLocation = table.hiveQlTable.getDataLocation
val tmpLocation = hiveContext.getExternalTmpFileURI(tableLocation)
val fileSinkConf = new FileSinkDesc(tmpLocation.toString, tableDesc,
false)
+
+ val numDynamicPartitions = partition.values.filter(_.isEmpty).size
+ val numStaticPartitions = partition.values.filter(_.isDefined).size
+ val partitionSpec = partition.map {
+ case (key, Some(value)) =>
+ key -> value
+ case (key, None) =>
+ key -> ""
+ }
+
+ val jobConf = new JobConf(sc.hiveconf)
+ val jobConfSer = new SerializableWritable(jobConf)
+ // check if the partition spec is valid
+ if (numDynamicPartitions > 0) {
+ if (!sc.hiveconf.getBoolVar(HiveConf.ConfVars.DYNAMICPARTITIONING)) {
+ throw new
SparkException(ErrorMsg.DYNAMIC_PARTITION_DISABLED.getMsg())
+ }
+ if (numStaticPartitions == 0 &&
+
sc.hiveconf.getVar(HiveConf.ConfVars.DYNAMICPARTITIONINGMODE).equalsIgnoreCase("strict"))
{
+ throw new
SparkException(ErrorMsg.DYNAMIC_PARTITION_STRICT_MODE.getMsg())
+ }
+ // check if static partition appear after dynamic partitions
+ var tmpNumStaticPartitions = numStaticPartitions
+ for ((k,v) <- partitionSpec) {
+ if (partitionSpec(k) == "") {
+ if (tmpNumStaticPartitions > 0) { // found a DP, but there
exists ST as subpartition
+ throw new
SparkException(ErrorMsg.PARTITION_DYN_STA_ORDER.getMsg())
+ }
+ } else {
+ tmpNumStaticPartitions -= 1
+ }
+ }
--- End diff --
This for-loop check is incorrect and dangerous, `partitionSpec` is a `Map`,
which is not an ordered sequence. Instead, we can have something like this:
```scala
// Report error if any static partition appears after a dynamic partition
val isDynamic = partitionColumnNames.map(partitionSpec(_).isEmpty)
isDynamic.init.zip(isDynamic.tail).find(_ == (true, false)).foreach { _ =>
throw new SparkException(ErrorMsg.PARTITION_DYN_STA_ORDER.getMsg)
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]