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

    https://github.com/apache/spark/pull/1919#discussion_r16343411
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala
 ---
    @@ -201,17 +270,79 @@ case class InsertIntoHiveTable(
           }
         }
     
    -    // ORC stores compression information in table properties. While, 
there are other formats
    -    // (e.g. RCFile) that rely on hadoop configurations to store 
compression information.
    -    val jobConf = new JobConf(sc.hiveconf)
    -    saveAsHiveFile(
    -      rdd,
    -      outputClass,
    -      fileSinkConf,
    -      jobConf,
    -      sc.hiveconf.getBoolean("hive.exec.compress.output", false))
    -
    -    // TODO: Handle dynamic partitioning.
    +    if (dynamicPartNum > 0) {
    +      if (outputClass == null) {
    +        throw new SparkException("Output value class not set")
    +      }
    +      jobConfSer.value.setOutputValueClass(outputClass)
    +      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)
    +      jobConfSer.value.set("mapred.output.format.class", 
fileSinkConf.getTableInfo.getOutputFileFormatClassName)
    +      if (sc.hiveconf.getBoolean("hive.exec.compress.output", false)) {
    +        // 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.
    +        jobConfSer.value.set("mapred.output.compress", "true")
    +        fileSinkConf.setCompressed(true)
    +        
fileSinkConf.setCompressCodec(jobConfSer.value.get("mapred.output.compression.codec"))
    +        
fileSinkConf.setCompressType(jobConfSer.value.get("mapred.output.compression.type"))
    +      }
    +      jobConfSer.value.setOutputCommitter(classOf[FileOutputCommitter])
    +
    +      FileOutputFormat.setOutputPath(
    +        jobConfSer.value,
    +        
SparkHiveHadoopWriter.createPathFromString(fileSinkConf.getDirName, 
jobConfSer.value))
    +
    +      var writerMap =  new scala.collection.mutable.HashMap[String, 
SparkHiveHadoopWriter]
    +      def writeToFile2(context: TaskContext, iter: Iterator[Writable]) {
    +        // Hadoop wants a 32-bit task attempt ID, so if ours is bigger 
than Int.MaxValue, roll it
    +        // around by taking a mod. We expect that no task will be 
attempted 2 billion times.
    +        val attemptNumber = (context.attemptId % Int.MaxValue).toInt
    +        val serializer = newSerializer(fileSinkConf.getTableInfo)
    +        var count = 0
    +        var writer2:SparkHiveHadoopWriter = null
    +        while(iter.hasNext) {
    +          val record = iter.next();
    +          val location = fileSinkConf.getDirName
    +          val partLocation = location + dynamicPartPath
    +          writer2=writerMap.get(dynamicPartPath) match {
    +            case Some(writer)=> writer
    +            case None => {
    +              val tempWriter = new SparkHiveHadoopWriter(jobConfSer.value, 
new FileSinkDesc(partLocation, fileSinkConf.getTableInfo, false))
    +              tempWriter.setup(context.stageId, context.partitionId, 
attemptNumber)
    +              tempWriter.open(dynamicPartPath);
    +              writerMap += (dynamicPartPath -> tempWriter)
    +              tempWriter
    +            }
    +          }
    +          count += 1
    +          writer2.write(record)
    +        }
    +        for((k,v) <- writerMap) {
    +          v.close()
    +          v.commit()
    +        }
    +      }
    +
    +      sc.sparkContext.runJob(rdd, writeToFile2 _)
    +
    +      for((k,v) <- writerMap) {
    --- End diff --
    
    Space before `(`


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to