Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4014#discussion_r23426344
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/ScriptTransformation.scala
 ---
    @@ -53,28 +82,176 @@ case class ScriptTransformation(
           val inputStream = proc.getInputStream
           val outputStream = proc.getOutputStream
           val reader = new BufferedReader(new InputStreamReader(inputStream))
    + 
    +      val outputSerde: AbstractSerDe = if (outputSerdeClass != "") {
    +        val trimed_class = outputSerdeClass.split("'")(1) 
    +        Utils.classForName(trimed_class)
    +          .newInstance.asInstanceOf[AbstractSerDe]
    +      } else {
    +        null
    +      }
    + 
    +      if (outputSerde != null) {
    +        val columns = output.map { case aref: AttributeReference => 
aref.name }
    +          .mkString(",")
    +        val columnTypes = output.map { case aref: AttributeReference =>
    +          aref.dataType.toTypeInfo.getTypeName()
    +        }.mkString(",")
    +
    +        var propsMap = outputSerdeProps.map(kv => {
    +          (kv._1.split("'")(1), kv._2.split("'")(1))
    +        }).toMap + (serdeConstants.LIST_COLUMNS -> columns)
    +        propsMap = propsMap + (serdeConstants.LIST_COLUMN_TYPES -> 
columnTypes)
    +
    +        val properties = new Properties()
    +        properties.putAll(propsMap)
    + 
    +        outputSerde.initialize(null, properties)
    +      }
    +
    +      val outputSoi = if (outputSerde != null) {
    +        
outputSerde.getObjectInspector().asInstanceOf[StructObjectInspector]
    +      } else {
    +        null
    +      }
    +
    +      val iterator: Iterator[Row] = new Iterator[Row] with HiveInspectors {
    +        var cacheRow: Row = null
    +        var curLine: String = null
    +        var eof: Boolean = false
    +
    +        override def hasNext: Boolean = {
    +          if (outputSerde == null) {
    +            if (curLine == null) {
    +              curLine = reader.readLine()
    +              curLine != null
    +            } else {
    +              true
    +            }
    +          } else {
    +            !eof
    +          }
    +        }
     
    -      // TODO: This should be exposed as an iterator instead of reading in 
all the data at once.
    -      val outputLines = collection.mutable.ArrayBuffer[Row]()
    -      val readerThread = new Thread("Transform OutputReader") {
    --- End diff --
    
    I can understand why removing the reader thread, but it would be helpful in 
the future if we support the `streaming style output`, which will save lots of 
memory, do you might leave it unchanged? or at least keep the `TODO`


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