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

    https://github.com/apache/spark/pull/2576#discussion_r18768525
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/orc/OrcRelation.scala ---
    @@ -0,0 +1,248 @@
    +/*
    + * 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.Properties
    +import java.io.IOException
    +import org.apache.hadoop.hive.ql.stats.StatsSetupConst
    +
    +import scala.collection.mutable
    +
    +import org.apache.hadoop.fs.{FileSystem, Path}
    +import org.apache.hadoop.conf.Configuration
    +import org.apache.hadoop.fs.permission.FsAction
    +import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector
    +import org.apache.hadoop.hive.ql.io.orc._
    +import org.apache.hadoop.hive.ql.io.orc.OrcProto.Type.Kind
    +
    +import org.apache.spark.sql.parquet.FileSystemHelper
    +import org.apache.spark.sql.SQLContext
    +import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, LeafNode}
    +import org.apache.spark.sql.catalyst.analysis.{UnresolvedException, 
MultiInstanceRelation}
    +import org.apache.spark.sql.catalyst.expressions.Attribute
    +import org.apache.spark.sql.catalyst.expressions.AttributeReference
    +import org.apache.spark.sql.catalyst.types._
    +
    +
    +private[sql] case class OrcRelation(
    +    path: String,
    +    @transient conf: Option[Configuration],
    +    @transient sqlContext: SQLContext,
    +    partitioningAttributes: Seq[Attribute] = Nil)
    +  extends LeafNode with MultiInstanceRelation {
    +  self: Product =>
    +
    +  val prop: Properties = new Properties
    +
    +  var rowClass: Class[_] = null
    +
    +  val fieldIdCache: mutable.Map[String, Int] = new mutable.HashMap[String, 
Int]
    +
    +  val fieldNameTypeCache: mutable.Map[String, String] = new 
mutable.HashMap[String, String]
    +
    +  override val output = orcSchema
    +
    +  override lazy val statistics = Statistics(sizeInBytes = 
sqlContext.defaultSizeInBytes)
    +
    +  def orcSchema: Seq[Attribute] = {
    +    val origPath = new Path(path)
    +    val reader = OrcFileOperator.readMetaData(origPath, conf)
    +
    +    if (null != reader) {
    +      val inspector = 
reader.getObjectInspector.asInstanceOf[StructObjectInspector]
    +      val fields = inspector.getAllStructFieldRefs
    +
    +      if (fields.size() == 0) {
    +        return Seq.empty
    +      }
    +
    +      val totalType = reader.getTypes.get(0)
    +      val keys = totalType.getFieldNamesList
    +      val types = totalType.getSubtypesList
    +      log.info("field name is {}", keys)
    +      log.info("types is {}", types)
    +
    +      val colBuff = new StringBuilder
    +      val typeBuff = new StringBuilder
    +      for (i <- 0 until fields.size()) {
    +        val fieldName = fields.get(i).getFieldName
    +        val typeName = fields.get(i).getFieldObjectInspector.getTypeName
    +        colBuff.append(fieldName)
    +        fieldNameTypeCache.put(fieldName, typeName)
    +        fieldIdCache.put(fieldName, i)
    +        colBuff.append(",")
    +        typeBuff.append(typeName)
    +        typeBuff.append(":")
    +      }
    +      colBuff.setLength(colBuff.length - 1)
    +      typeBuff.setLength(typeBuff.length - 1)
    +      prop.setProperty("columns", colBuff.toString())
    +      prop.setProperty("columns.types", typeBuff.toString())
    +      val attributes = convertToAttributes(reader, keys, types)
    +      attributes
    +    } else {
    +      Seq.empty
    +    }
    +  }
    +
    +  def convertToAttributes(
    +      reader: Reader,
    +      keys: java.util.List[String],
    +      types: java.util.List[Integer]): Seq[Attribute] = {
    +    val range = 0.until(keys.size())
    +    range.map {
    +      i => reader.getTypes.get(types.get(i)).getKind match {
    +        case Kind.BOOLEAN =>
    +          new AttributeReference(keys.get(i), BooleanType, false)()
    +        case Kind.STRING =>
    +          new AttributeReference(keys.get(i), StringType, true)()
    +        case Kind.BYTE =>
    +          new AttributeReference(keys.get(i), ByteType, true)()
    +        case Kind.SHORT =>
    +          new AttributeReference(keys.get(i), ShortType, true)()
    +        case Kind.INT =>
    +          new AttributeReference(keys.get(i), IntegerType, true)()
    +        case Kind.LONG =>
    +          new AttributeReference(keys.get(i), LongType, false)()
    +        case Kind.FLOAT =>
    +          new AttributeReference(keys.get(i), FloatType, false)()
    +        case Kind.DOUBLE =>
    +          new AttributeReference(keys.get(i), DoubleType, false)()
    +        case _ => {
    +          log.info("unsupported datatype")
    +          null
    --- End diff --
    
    I think we should support all data types supported by Spark SQL.


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