Created
September 26, 2021 02:30
-
-
Save zinking/7a4d4b74d605759a3a5eee40ac49eb1c to your computer and use it in GitHub Desktop.
reflective call SCALA [object] method
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
import scala.reflect.runtime.universe._; | |
import org.apache.spark.sql.SparkSession; | |
val field = spark.getClass.getDeclaredField("extensions"); | |
field.setAccessible(true); | |
val extensions = field.get(spark).asInstanceOf[org.apache.spark.sql.SparkSessionExtensions]; | |
val tpe = typeOf[org.apache.spark.sql.SparkSession]; | |
val m = scala.reflect.runtime.currentMirror; | |
val im = m.reflect(m.reflectModule(tpe.typeSymbol.asClass.companion.asModule).instance); | |
val method = tpe.companion.decl(TermName("applyExtensions")).asMethod;\n | |
im.reflectMethod(method)("io.delta.sql.DeltaSparkSessionExtension" :: Nil, extensions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment