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

    https://github.com/apache/spark/pull/18488#discussion_r134478386
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala
 ---
    @@ -345,6 +356,30 @@ object JavaTypeInference {
         }
       }
     
    +  /** Returns a mapping from enum value to int for given enum type */
    +  def enumSerializer[T <: Enum[T]](enum: Class[T]): T => UTF8String = {
    +    assert(enum.isEnum)
    +    inputObject: T =>
    +      UTF8String.fromString(inputObject.name())
    +  }
    +
    +  /** Returns value index for given enum type and value */
    +  def serializeEnumName[T <: Enum[T]](enum: UTF8String, inputObject: T): 
UTF8String = {
    +    
enumSerializer(Utils.classForName(enum.toString).asInstanceOf[Class[T]])(inputObject)
    +  }
    +
    +  /** Returns a mapping from int to enum value for given enum type */
    +  def enumDeserializer[T <: Enum[T]](enum: Class[T]): InternalRow => T = {
    +    assert(enum.isEnum)
    +    value: InternalRow =>
    +      Enum.valueOf(enum, value.getUTF8String(0).toString)
    --- End diff --
    
    Enum.valueOf uses cached string->value map


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

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

Reply via email to