spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yhuai <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-2706][SQL] Enable Spark to support Hive...
Date Sat, 04 Oct 2014 14:34:48 GMT
Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2241#discussion_r18429655
  
    --- Diff: sql/hive/v0.13.1/src/main/scala/org/apache/spark/sql/hive/Shim.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
    +
    +import java.util.Properties
    +import org.apache.hadoop.conf.Configuration
    +import org.apache.hadoop.fs.Path
    +import org.apache.hadoop.hive.common.StatsSetupConst
    +import org.apache.hadoop.hive.common.`type`.{HiveDecimal}
    +import org.apache.hadoop.hive.conf.HiveConf
    +import org.apache.hadoop.hive.ql.Context
    +import org.apache.hadoop.hive.ql.metadata.{Table, Hive, Partition}
    +import org.apache.hadoop.hive.ql.plan.{FileSinkDesc, TableDesc}
    +import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory
    +import org.apache.hadoop.hive.serde2.{ColumnProjectionUtils, Deserializer}
    +import org.apache.hadoop.mapred.InputFormat
    +import org.apache.spark.Logging
    +import org.apache.hadoop.{io => hadoopIo}
    +import scala.collection.JavaConversions._
    +import scala.language.implicitConversions
    +
    +/**
    + * A compatibility layer for interacting with Hive version 0.13.1.
    + */
    +private[hive] object HiveShim {
    +  val version = "0.13.1"
    +  /*
    +   * TODO: hive-0.13 support DECIMAL(precision, scale), DECIMAL in hive-0.12 is actually
DECIMAL(10,0)
    +   * Full support of new decimal feature need to be fixed in seperate PR.
    +   */
    +  val metastoreDecimal = "decimal(10,0)"
    +
    +  def getTableDesc(
    +    serdeClass: Class[_ <: Deserializer],
    +    inputFormatClass: Class[_ <: InputFormat[_, _]],
    +    outputFormatClass: Class[_],
    +    properties: Properties) = {
    +    new TableDesc(inputFormatClass, outputFormatClass, properties)
    +  }
    +
    +  def getStatsSetupConstTotalSize = StatsSetupConst.TOTAL_SIZE
    +
    +  def createDefaultDBIfNeeded(context: HiveContext) ={
    +    context.runSqlHive("CREATE DATABASE default")
    +    context.runSqlHive("USE default")
    +  }
    +
    +  /** The string used to denote an empty comments field in the schema. */
    +  def getEmptyCommentsFieldValue = ""
    +
    +  def getCommandProcessor(cmd: Array[String], conf: HiveConf) =  {
    +    CommandProcessorFactory.get(cmd, conf)
    +  }
    +
    +  def createDecimal(bd: java.math.BigDecimal): HiveDecimal = {
    +    HiveDecimal.create(bd)
    +  }
    +
    +  /*
    +   * This function in hive-0.13 become private, but we have to do this to walkaround
hive bug
    +   */
    +  private def appendReadColumnNames(conf: Configuration, cols: Seq[String]) {
    +    val old: String = conf.get(ColumnProjectionUtils.READ_COLUMN_NAMES_CONF_STR, "")
    +    val result: StringBuilder = new StringBuilder(old)
    +    var first: Boolean = old.isEmpty
    +
    +    for (col <- cols) {
    +      if (first) {
    +        first = false
    +      }
    +      else {
    +        result.append(',')
    +      }
    +      result.append(col)
    +    }
    +    conf.set(ColumnProjectionUtils.READ_COLUMN_NAMES_CONF_STR, result.toString)
    +  }
    +
    +  /*
    +   * Cannot use ColumnProjectionUtils.appendReadColumns directly, if ids is null or empty
    +   */
    +  def appendReadColumns(conf: Configuration, ids: Seq[Integer], names: Seq[String]) {
    +    if (ids != null && ids.size > 0) {
    +      ColumnProjectionUtils.appendReadColumns(conf, ids)
    +    }
    +    appendReadColumnNames(conf, names)
    +  }
    +
    +  def getExternalTmpPath(context: Context, path: Path) = {
    +    context.getExternalTmpPath(path.toUri)
    +  }
    +
    +  def getDataLocationPath(p: Partition) = p.getDataLocation
    +
    +  def getAllPartitionsOf(client: Hive, tbl: Table) =  client.getAllPartitionsOf(tbl)
    +
    +  /*
    +   * Bug introdiced in hive-0.13. FileSinkDesc is serilizable, but its member path is
not.
    +   * Fix it through wrapper.
    --- End diff --
    
    I am pretty confused about it. I think Hive needs to serialize FileSinkDesc when the query
plan needs to be serialized. So, how does Hive handle this issue?
    
    Also, serilizable=>serializable.


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

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


Mime
View raw message