You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by gatorsmile <gi...@git.apache.org> on 2017/01/28 04:53:35 UTC

[GitHub] spark pull request #16636: [SPARK-19279] [SQL] Infer Schema for Hive Serde T...

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

    https://github.com/apache/spark/pull/16636#discussion_r98324289
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveUtils.scala ---
    @@ -455,4 +462,133 @@ private[spark] object HiveUtils extends Logging {
         case (decimal, DecimalType()) => decimal.toString
         case (other, tpe) if primitiveTypes contains tpe => other.toString
       }
    +
    +  /** Converts the native StructField to Hive's FieldSchema. */
    +  private def toHiveColumn(c: StructField): FieldSchema = {
    +    val typeString = if (c.metadata.contains(HiveUtils.hiveTypeString)) {
    +      c.metadata.getString(HiveUtils.hiveTypeString)
    +    } else {
    +      c.dataType.catalogString
    +    }
    +    new FieldSchema(c.name, typeString, c.getComment.orNull)
    +  }
    +
    +  /** Builds the native StructField from Hive's FieldSchema. */
    +  private def fromHiveColumn(hc: FieldSchema): StructField = {
    +    val columnType = try {
    +      CatalystSqlParser.parseDataType(hc.getType)
    +    } catch {
    +      case e: ParseException =>
    +        throw new SparkException("Cannot recognize hive type string: " + hc.getType, e)
    +    }
    +
    +    val metadata = new MetadataBuilder().putString(HiveUtils.hiveTypeString, hc.getType).build()
    +    val field = StructField(
    +      name = hc.getName,
    +      dataType = columnType,
    +      nullable = true,
    +      metadata = metadata)
    +    Option(hc.getComment).map(field.withComment).getOrElse(field)
    +  }
    +
    +  // TODO: merge this with HiveClientImpl#toHiveTable
    --- End diff --
    
    So far, it is a little bit tricky when merging them, because our execution is using 1.2.1, but Hive metadata APIs support the versions from 0.12 to 1.2. Thus, it does not make sense to do it. 
    
    So far, the schema inference is not using metadata Hive client. I checked the code. The changes between 0.12 and 1.2 look fine to me. Schema inference should work correctly. I think I need to add a test case to VersionSuite.scala.


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