目前正在将以下代码转换为“JAR”以在 Databricks 集群中注册永久 UDF。面临 NoClassDefFoundError 之类的问题,但我在使用 SBT 构建 Jar 时添加了所需的库依赖项。源代码:https ://databricks.com/notebooks/enforcing-column-level-encryption.html
下面在 build.sbt 中使用
scalaVersion := "2.13.4"
libraryDependencies += "org.apache.hive" % "hive-exec" % "0.13.1"
libraryDependencies += "com.macasaet.fernet" % "fernet-java8" % "1.5.0"
如果上面有任何问题,请指导我使用正确的库。
请帮助我,
import com.macasaet.fernet.{Key, StringValidator, Token}
import org.apache.hadoop.hive.ql.exec.UDF;
class Validator extends StringValidator {
override def getTimeToLive() : java.time.temporal.TemporalAmount = {
Duration.ofSeconds(Instant.MAX.getEpochSecond());
}
}
class udfDecrypt extends UDF {
def evaluate(inputVal: String, sparkKey : String): String = {
if( inputVal != null && inputVal!="" ) {
val keys: Key = new Key(sparkKey)
val token = Token.fromString(inputVal)
val validator = new Validator() {}
val payload = token.validateAndDecrypt(keys, validator)
payload
} else return inputVal
}
}