Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/2226#discussion_r17277261
--- Diff:
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveTable.scala
---
@@ -101,62 +103,135 @@ case class InsertIntoHiveTable(
}
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()
+ } else {
+ writerMap = new scala.collection.mutable.HashMap[String,
SparkHiveHadoopWriter]
+ }
- val writer = new SparkHiveHadoopWriter(conf, fileSinkConf)
- writer.preSetup()
-
- def writeToFile(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
-
+ def writeToFile(context: TaskContext, iter: Iterator[(Writable,
String)]) {
+ // 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
+ // writer for No Dynamic Partition
+ if (dynamicPartNum == 0) {
writer.setup(context.stageId, context.partitionId, attemptNumber)
writer.open()
+ }
- var count = 0
- while(iter.hasNext) {
- val record = iter.next()
- count += 1
- writer.write(record)
+ var count = 0
--- End diff --
I don't think this variable is used.
---
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]