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

    https://github.com/apache/spark/pull/6135#discussion_r30427832
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/orc/OrcRelation.scala ---
    @@ -0,0 +1,158 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.hive.orc
    +
    +import java.util.Objects
    +
    +import org.apache.hadoop.fs.Path
    +import org.apache.hadoop.hive.ql.io.orc.{OrcSerde, OrcOutputFormat}
    +import org.apache.hadoop.hive.serde2.objectinspector.{ObjectInspector, 
StructObjectInspector}
    +import org.apache.hadoop.hive.serde2.typeinfo.{TypeInfoUtils, TypeInfo}
    +import org.apache.hadoop.io.{Writable, NullWritable}
    +import org.apache.hadoop.mapred.{RecordWriter, Reporter, JobConf}
    +import org.apache.hadoop.mapreduce.{TaskID, TaskAttemptContext}
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.annotation.DeveloperApi
    +import org.apache.spark.mapred.SparkHadoopMapRedUtil
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.sql.hive.HiveMetastoreTypes
    +import org.apache.spark.sql.types.StructType
    +import org.apache.spark.sql.{Row, SQLContext}
    +import org.apache.spark.sql.sources._
    +
    +/* Implicit conversions */
    +import scala.collection.JavaConversions._
    +
    +
    +private[sql] class DefaultSource extends FSBasedRelationProvider {
    +  def createRelation(
    +      sqlContext: SQLContext,
    +      paths: Array[String],
    +      schema: Option[StructType],
    +      partitionColumns: Option[StructType],
    +      parameters: Map[String, String]): FSBasedRelation ={
    +    val partitionSpec = partitionColumns.map(PartitionSpec(_, 
Seq.empty[Partition]))
    +    OrcRelation(paths, parameters,
    +      schema, partitionSpec)(sqlContext)
    +  }
    +}
    +
    +
    +private[sql] class OrcOutputWriter extends OutputWriter with 
SparkHadoopMapRedUtil {
    +
    +  var taskAttemptContext: TaskAttemptContext = _
    +  var serializer: OrcSerde = _
    +  var wrappers: Array[Any => Any] = _
    +  var created = false
    +  var path: String = _
    +  var dataSchema: StructType = _
    +  var fieldOIs: Array[ObjectInspector] = _
    +  var structOI: StructObjectInspector = _
    +  var outputData: Array[Any] = _
    +  lazy val recordWriter: RecordWriter[NullWritable, Writable] = {
    +    created = true
    +    val conf = taskAttemptContext.getConfiguration
    +    val taskId: TaskID = taskAttemptContext.getTaskAttemptID.getTaskID
    +    val partition: Int = taskId.getId
    +    val filename = 
f"part-r-$partition%05d-${System.currentTimeMillis}%015d.orc"
    +    val file = new Path(path, filename)
    +    val fs = file.getFileSystem(conf)
    +    val outputFormat = new OrcOutputFormat()
    +    outputFormat.getRecordWriter(fs,
    +      conf.asInstanceOf[JobConf],
    +      file.toUri.getPath, Reporter.NULL)
    +      .asInstanceOf[org.apache.hadoop.mapred.RecordWriter[NullWritable, 
Writable]]
    +  }
    +
    +  override def init(path: String,
    +      dataSchema: StructType,
    +      context: TaskAttemptContext): Unit = {
    +    this.path = path
    +    taskAttemptContext = context
    +    val orcSchema = HiveMetastoreTypes.toMetastoreType(dataSchema)
    +    serializer = new OrcSerde
    --- End diff --
    
    Just saw your new code.My misunderstanding.  ObjectInspector is also 
specified in serialize, but doing initialization does look more elegant.


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