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

    https://github.com/apache/spark/pull/5688#discussion_r30835359
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/ScriptTransformation.scala
 ---
    @@ -178,95 +169,156 @@ case class ScriptTransformation(
      */
     private[hive]
     case class HiveScriptIOSchema (
    -    inputRowFormat: Seq[(String, String)],
    -    outputRowFormat: Seq[(String, String)],
    +    inputRowFormat: Seq[(String, String, String)],
    +    outputRowFormat: Seq[(String, String, String)],
         inputSerdeClass: String,
         outputSerdeClass: String,
         inputSerdeProps: Seq[(String, String)],
         outputSerdeProps: Seq[(String, String)],
    +    recordReader: String,
    +    recordWriter: String,
         schemaLess: Boolean) extends ScriptInputOutputSchema with 
HiveInspectors {
     
    -  val defaultFormat = Map(("TOK_TABLEROWFORMATFIELD", "\t"),
    -                          ("TOK_TABLEROWFORMATLINES", "\n"))
    +  @transient val hConf = new HiveConf()
    +  val defaultSerdeName: String = 
hConf.getVar(HiveConf.ConfVars.HIVESCRIPTSERDE)
    +  val defaultSerdeClass: Class[_ <: Deserializer] = 
Utils.classForName(defaultSerdeName)
    +    .asInstanceOf[Class[_ <: Deserializer]]
     
    -  val inputRowFormatMap = inputRowFormat.toMap.withDefault((k) => 
defaultFormat(k))
    -  val outputRowFormatMap = outputRowFormat.toMap.withDefault((k) => 
defaultFormat(k))
    +  val fieldSeparator: Int =
    +    if (HiveConf.getBoolVar(hConf, HiveConf.ConfVars.HIVESCRIPTESCAPE)) {
    +      Utilities.ctrlaCode
    +    } else {
    +      Utilities.tabCode
    +    }
     
    -  
    -  def initInputSerDe(input: Seq[Expression]): (AbstractSerDe, 
ObjectInspector) = {
    +  def initInputSerDe(input: Seq[Expression]): TableDesc = {
         val (columns, columnTypes) = parseAttrs(input)
    -    val serde = initSerDe(inputSerdeClass, columns, columnTypes, 
inputSerdeProps)
    -    (serde, initInputSoi(serde, columns, columnTypes))
    +    val columnTypesNames = 
columnTypes.map(_.toTypeInfo.getTypeName()).mkString(",")
    +    val inInfo: TableDesc =
    +      if (inputSerdeClass != "") {
    +        getTableDescFromSerDe(inputSerdeClass, columns, columnTypes, 
inputSerdeProps,
    +          inputRowFormat)
    +      } else {
    +        PlanUtils.getTableDesc(defaultSerdeClass, fieldSeparator.toString, 
columns.mkString(","),
    +          columnTypesNames, false, true)
    +      }
    +    inInfo
       }
     
    -  def initOutputSerDe(output: Seq[Attribute]): (AbstractSerDe, 
StructObjectInspector) = {
    +  def initOutputSerDe(output: Seq[Attribute]): TableDesc = {
         val (columns, columnTypes) = parseAttrs(output)
    -    val serde = initSerDe(outputSerdeClass, columns, columnTypes, 
outputSerdeProps)
    -    (serde, initOutputputSoi(serde))
    +    val columnTypesNames = 
columnTypes.map(_.toTypeInfo.getTypeName()).mkString(",")
    +    val outInfo: TableDesc =
    +      if (outputSerdeClass != "") {
    +        getTableDescFromSerDe(outputSerdeClass, columns, columnTypes, 
outputSerdeProps,
    +          outputRowFormat)
    +      } else {
    +        PlanUtils.getTableDesc(defaultSerdeClass, fieldSeparator.toString, 
columns.mkString(","),
    +          columnTypesNames, false)
    +      }
    +    outInfo
       }
     
       def parseAttrs(attrs: Seq[Expression]): (Seq[String], Seq[DataType]) = {
    -                                                
    -    val columns = attrs.map {
    -      case aref: AttributeReference => aref.name
    -      case e: NamedExpression => e.name
    -      case _ => null
    +    val columns = attrs.zipWithIndex.map {
    +      case (aref: AttributeReference, _) => aref.name
    +      case (e: NamedExpression, _) => e.name
    +      case (o, index) => "c_$index"
         }
      
    -    val columnTypes = attrs.map {
    -      case aref: AttributeReference => aref.dataType
    -      case e: NamedExpression => e.dataType
    -      case _ =>  null
    -    }
    +    val columnTypes = attrs.map(_.dataType)
     
         (columns, columnTypes)
       }
    - 
    -  def initSerDe(serdeClassName: String, columns: Seq[String],
    -    columnTypes: Seq[DataType], serdeProps: Seq[(String, String)]): 
AbstractSerDe = {
     
    -    val serde: AbstractSerDe = if (serdeClassName != "") {
    -      val trimed_class = serdeClassName.split("'")(1)
    -      Utils.classForName(trimed_class)
    -        .newInstance.asInstanceOf[AbstractSerDe]
    -    } else {
    -      null
    -    }
    -
    -    if (serde != null) {
    -      val columnTypesNames = 
columnTypes.map(_.toTypeInfo.getTypeName()).mkString(",")
    +  def getTableDescFromSerDe(
    +      serdeClassName: String,
    +      columns: Seq[String],
    +      columnTypes: Seq[DataType],
    +      serdeProps: Seq[(String, String)],
    +      rowFormat: Seq[(String, String, String)]): TableDesc = {
    +    val columnTypesNames = 
columnTypes.map(_.toTypeInfo.getTypeName()).mkString(",")
    +    if (serdeClassName != "") {
    +      val className = serdeClassName
    +      val serdeClass: Class[_ <: Deserializer] = 
Utils.classForName(className)
    +        .asInstanceOf[Class[_ <: Deserializer]]
     
    +      val tblDesc: TableDesc = PlanUtils.getTableDesc(serdeClass, 
Utilities.tabCode.toString,
    +        columns.mkString(","), columnTypesNames, false)
    + 
           var propsMap = serdeProps.map(kv => {
    -        (kv._1.split("'")(1), kv._2.split("'")(1))
    +        (kv._1, kv._2)
           }).toMap + (serdeConstants.LIST_COLUMNS -> columns.mkString(","))
           propsMap = propsMap + (serdeConstants.LIST_COLUMN_TYPES -> 
columnTypesNames)
    -    
    -      val properties = new Properties()
    -      properties.putAll(propsMap)
    -      serde.initialize(null, properties)
    -    }
    +      propsMap.map(kv => tblDesc.getProperties().setProperty(kv._1, kv._2))
     
    -    serde
    +      return tblDesc
    +    } else if (rowFormat != Nil) {
    +      val tblDesc: TableDesc = 
PlanUtils.getDefaultTableDesc(Utilities.ctrlaCode.toString,
    +        columns.mkString(","), columnTypesNames, false)
    +      rowFormat.foreach { (tuple) =>
    --- End diff --
    
    I think we should avoid holding on to ASTs and instead do all translation 
in the parser.


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