Github user liancheng commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2226#discussion_r17625214
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala
 ---
    @@ -100,63 +102,139 @@ case class InsertIntoHiveTable(
           obj
       }
     
    +  /**
    +   * since we should get directory of dynamic partition from upstream RDD
    +   * reference the code "serializer.serialize(outputData, standardOI) -> 
dynamicPartPath"
    +   * So The type of the elment in RDD is (Writable, String)
    +   */
       def saveAsHiveFile(
    -      rdd: RDD[Writable],
    +      rdd: RDD[(Writable, String)],
           valueClass: Class[_],
           fileSinkConf: FileSinkDesc,
    -      conf: JobConf,
    -      isCompressed: Boolean) {
    +      conf: SerializableWritable[JobConf],
    +      isCompressed: Boolean,
    +      dynamicPartNum: Int) {
         if (valueClass == null) {
           throw new SparkException("Output value class not set")
         }
    -    conf.setOutputValueClass(valueClass)
    +    conf.value.setOutputValueClass(valueClass)
         if (fileSinkConf.getTableInfo.getOutputFileFormatClassName == null) {
           throw new SparkException("Output format class not set")
         }
         // Doesn't work in Scala 2.9 due to what may be a generics bug
         // TODO: Should we uncomment this for Scala 2.10?
         // conf.setOutputFormat(outputFormatClass)
    -    conf.set("mapred.output.format.class", 
fileSinkConf.getTableInfo.getOutputFileFormatClassName)
    +    conf.value.set("mapred.output.format.class",
    +      fileSinkConf.getTableInfo.getOutputFileFormatClassName)
         if (isCompressed) {
           // Please note that isCompressed, "mapred.output.compress", 
"mapred.output.compression.codec",
           // and "mapred.output.compression.type" have no impact on ORC 
because it uses table properties
           // to store compression information.
    -      conf.set("mapred.output.compress", "true")
    +      conf.value.set("mapred.output.compress", "true")
           fileSinkConf.setCompressed(true)
    -      
fileSinkConf.setCompressCodec(conf.get("mapred.output.compression.codec"))
    -      
fileSinkConf.setCompressType(conf.get("mapred.output.compression.type"))
    +      
fileSinkConf.setCompressCodec(conf.value.get("mapred.output.compression.codec"))
    +      
fileSinkConf.setCompressType(conf.value.get("mapred.output.compression.type"))
         }
    -    conf.setOutputCommitter(classOf[FileOutputCommitter])
    -    FileOutputFormat.setOutputPath(
    -      conf,
    -      SparkHiveHadoopWriter.createPathFromString(fileSinkConf.getDirName, 
conf))
    +    conf.value.setOutputCommitter(classOf[FileOutputCommitter])
     
    +    FileOutputFormat.setOutputPath(
    +      conf.value,
    +      SparkHiveHadoopWriter.createPathFromString(fileSinkConf.getDirName, 
conf.value))
         log.debug("Saving as hadoop file of type " + valueClass.getSimpleName)
    +    var writer: SparkHiveHadoopWriter = null
    +    // Map restore writesr for Dynamic Partition
    +    var writerMap: scala.collection.mutable.HashMap[String, 
SparkHiveHadoopWriter] = null
    +    if (dynamicPartNum == 0) {
    +      writer = new SparkHiveHadoopWriter(conf.value, fileSinkConf)
    +      writer.preSetup()
    +      sc.sparkContext.runJob(rdd, writeToFile _)
    +      writer.commitJob()
    +    } else {
    +      writerMap =  new scala.collection.mutable.HashMap[String, 
SparkHiveHadoopWriter]
    +      sc.sparkContext.runJob(rdd, writeToFile _)
    +      for ((k,v) <- writerMap) {
    +        v.commitJob()
    +      }
    --- End diff --
    
    Actual writers are created on the fly by `writeToFile` on driver side, but 
the `writerMap` object is on driver side, so it's always empty, and 
`commitJob()` never gets called.
    
    Had an offline discussion with @yhuai, and came to the conclusion that, 
instead of creating a bunch of `SparkHiveHadoopWriter`s on executor side, we 
can create multiple `FileSinkOperator.RecordWriter`s on executor side within a 
single driver side `SparkHiveHadoopWriter`, so that we can call `commitJob` 
properly. This behavior somewhat mimics Hive 
`DynamicPartitionFileRecordWriterContainer`.


---
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]

Reply via email to