I'm new to Scala and I have difficulties writing a spark-sql application to dynamically load user classes and map rdds to it.
rdd.map(line => {
val cls = Class.forName("UserClass")
val constructor = cls.getConstructor(classOf[String], classOf[String])
Tuple1(constructor.newInstence(line._1, line._2)).asInstanceOf[cls.type]
}).toDF()
The problem is converting the object to its declared class, as cls.type returns java.lang.class[_], which is not expected. At runtime the following exception would be threw:
java.lang.UnsupportedOperationException: Schema for type java.lang.class[_] is not supported
BTW, I'm using Scala 2.10 and spark 1.6.1.
Any suggestions and comments would be appreciated! Thanks!