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

    https://github.com/apache/spark/pull/7301#discussion_r34230186
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/pythonUDFs.scala ---
    @@ -220,6 +214,89 @@ object EvaluatePython {
         // TODO(davies): we could improve this by try to cast the object to 
expected type
         case (c, _) => null
       }
    +
    +
    +  private val module = "pyspark.sql.types"
    +
    +  /**
    +   * Pickler for StructType
    +   */
    +  private class StructTypePickler extends IObjectPickler {
    +
    +    private val cls = classOf[StructType]
    +
    +    def register(): Unit = {
    +      Pickler.registerCustomPickler(cls, this)
    +    }
    +
    +    def pickle(obj: Object, out: OutputStream, pickler: Pickler): Unit = {
    +      out.write(Opcodes.GLOBAL)
    +      out.write((module + "\n" + "_parse_datatype_json_string" + 
"\n").getBytes)
    +      val schema = obj.asInstanceOf[StructType]
    +      pickler.save(schema.json)
    +      out.write(Opcodes.TUPLE1)
    +      out.write(Opcodes.REDUCE)
    +    }
    +  }
    +
    +  /**
    +   * Pickler for InternalRow
    +   */
    +  private class RowPickler extends IObjectPickler {
    +
    +    private val cls = classOf[GenericInternalRowWithSchema]
    +
    +    // register this to Pickler and Unpickler
    +    def register(): Unit = {
    +      Pickler.registerCustomPickler(this.getClass, this)
    +      Pickler.registerCustomPickler(cls, this)
    +    }
    +
    +    def pickle(obj: Object, out: OutputStream, pickler: Pickler): Unit = {
    +      if (obj == this) {
    +        out.write(Opcodes.GLOBAL)
    +        out.write((module + "\n" + "_create_row_inbound_converter" + 
"\n").getBytes)
    +      } else {
    +        // it will be memorized by Pickler
    +        pickler.save(this)
    +        val row = obj.asInstanceOf[GenericInternalRowWithSchema]
    +        // schema should always be same object for memorization
    +        pickler.save(row.schema)
    +        out.write(Opcodes.TUPLE1)
    +        out.write(Opcodes.REDUCE)
    +
    +        out.write(Opcodes.MARK)
    +        row.values.foreach(pickler.save)
    +        out.write(Opcodes.TUPLE)
    +        out.write(Opcodes.REDUCE)
    +      }
    +    }
    +  }
    +
    +  private[this] var registered = false
    +  // This should be called before trying to serialize any above classes
    +  // In cluster mode, this should be put in the closure
    +  def registerPicklers(): Unit = {
    +    SerDeUtil.initialize()
    --- End diff --
    
    Could be.


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