spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mike0sv <...@git.apache.org>
Subject [GitHub] spark pull request #18488: [SPARK-21255][SQL][WIP] Fixed NPE when creating e...
Date Mon, 03 Jul 2017 21:44:51 GMT
Github user mike0sv commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18488#discussion_r125360539
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala
---
    @@ -344,6 +352,28 @@ object JavaTypeInference {
         }
       }
     
    +  /** Returns a mapping from enum value to int for given enum type */
    +  def enumSerializer[T](enum: Class[T]): T => Int = {
    +    assert(enum.isEnum)
    +    enum.getEnumConstants.toList.zipWithIndex.toMap
    +  }
    +
    +  /** Returns value index for given enum type and value */
    +  def serializeEnumName[T](enum: UTF8String, inputObject: T): Int = {
    +    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: Class[T]): Int => T = {
    --- End diff --
    
    Good point. But if we use string values, there is already a hashmap inside enum implementation,
accessible via valueOf.


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


Mime
View raw message