我想打电话
com.databricks.dbutils_v1.DBUtilsHolder.dbutils.secrets.get(scope = "myScope", key = "myKey")
使用镜像。
到目前为止,我实现了这一点:
val className = "com.databricks.dbutils_v1.DBUtilsHolder"
import scala.reflect.runtime.{universe => ru}
val mirror = ru.runtimeMirror(getClass.getClassLoader)
val moduleSymbol = mirror.staticModule(className)
val moduleMirror = mirror.reflectModule(moduleSymbol)
val instanceMirror = mirror.reflect(moduleMirror.instance)
这提供了一个有效的 dbutils 参考:
instanceMirror.instance
> Any = com.databricks.dbutils_v1.DBUtilsHolder$@25d7f14b
作为比较:
com.databricks.dbutils_v1.DBUtilsHolder
> com.databricks.dbutils_v1.DBUtilsHolder.type = com.databricks.dbutils_v1.DBUtilsHolder$@25d7f14b
要列出可用字段:
val fields = moduleSymbol.typeSignature.decls.filter(_.asTerm.isVal)
for (f <- fields) {
println(f)
val fieldMirror = instanceMirror.reflectField(f.asTerm)
}
> value dbutils0
> value dbutils
问题是如何扩展fieldMirror以访问 dbutils.secrets.get(s, k)