Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

using reflection with Class created in Cell #800

Unanswered
asethia asked this question in Q&A
Discussion options

Hi,

I have a scenario; where I have configured a spark notebook with the dependent jar.

%%configure -f
{ "conf": {"spark.jars.packages": "<custom package>>",
 "spark.jars.repositories":"<<repo URL>>"
 }
}

The included jar has a function to get class Type using scala reflection. For example, the Person case class:

case class Person(name: String)

object Helper {
import scala.reflect.runtime.{universe => ru}
def getTypeFromStringClassName(name: String): ru.Type = {
 val classInstance: Class[_] = Class.forName(name)
 val mirror: ru.Mirror = ru.runtimeMirror(getClass.getClassLoader)
 val classSymbol: ru.ClassSymbol = mirror.classSymbol(classInstance)
 classSymbol.selfType
}
}

When I am trying to invoke this function from a Jupyter cell

Helper.getTypeFromStringClassName("Person")

It throws java.lang.NoClassDefFoundError: Person (wrong name: Person )

Suppose I include the case class (Person) part of the jar file and refer to it using spark.jar.packages, It works fine. The Spark executor cannot resolve the class from the class loader.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /