Created
November 22, 2017 07:34
-
-
Save Kornel/f90e92e5b53b5f7bf3e3dbcc9f2b3dd5 to your computer and use it in GitHub Desktop.
enum spark UDT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.spark.sql.types | |
import xxx.Condition | |
import xxx.Department | |
class ConditionUDT extends UserDefinedType[Condition.Value] { | |
override def sqlType: DataType = IntegerType | |
override def serialize(obj: Condition.Value): Int = obj.id | |
override def deserialize(datum: Any): Condition.Value = Condition(datum.asInstanceOf[Int]) | |
override def userClass: Class[Condition.Value] = classOf[Condition.Value] | |
} | |
object EnumUDTRegister { | |
def register(): Unit = { | |
val clazz = this.getClass.getClassLoader.loadClass("org.apache.spark.sql.types.UDTRegistration") | |
val m = clazz.getMethods.filter(_.getName == "register").head | |
m.setAccessible(true) | |
m.invoke(clazz, classOf[Condition.Value].getCanonicalName, "org.apache.spark.sql.types.ConditionUDT") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment