Spark 无法与 pureconfig 一起使用
Spark not working with pureconfig
我正在尝试将 pureConfig 和 configFactory 用于我的 spark 应用程序配置。
这是我的代码:
import pureconfig.{loadConfigOrThrow}
object Source{
def apply(keyName: String, configArguments: Config): Source = {
keyName.toLowerCase match {
case "mysql" =>
val properties = loadConfigOrThrow[DBConnectionProperties](configArguments)
new MysqlSource(None, properties)
case "files" =>
val properties = loadConfigOrThrow[FilesSourceProperties](configArguments)
new Files(properties)
case _ => throw new NoSuchElementException(s"Unknown Source ${keyName.toLowerCase}")
}
}
}
import Source
val config = ConfigFactory.parseString(result.mkString("\n"))
val source = Source("mysql",config.getConfig("source.mysql"))
当我 运行 它来自 IDE (intelliJ) 或直接来自 java
(即 java jar...)它工作正常。
但是当我使用 spark-submit 运行 它失败并出现以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: shapeless.Witness$.mkWitness(Ljava/lang/Object;)Lshapeless/Witness;
通过快速搜索,我找到了与此类似的内容 。
这表明这是因为 spark 和 pureConfig 都依赖于 Shapeless 但版本不同,
我尝试shade it按照答案中的建议
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("shapeless.**" -> "shadeshapless.@1")
.inLibrary("com.github.pureconfig" %% "pureconfig" % "0.7.0").inProject
)
但效果不佳
会不会是其他原因?
知道什么可行吗?
谢谢
除了 pureconfig 之外,您还必须在其自己的 JAR 中隐藏 shapeless:
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("shapeless.**" -> "shadeshapless.@1")
.inLibrary("com.chuusai" % "shapeless_2.11" % "2.3.2")
.inLibrary("com.github.pureconfig" %% "pureconfig" % "0.7.0")
.inProject
)
确保添加正确的无形版本。
我正在尝试将 pureConfig 和 configFactory 用于我的 spark 应用程序配置。 这是我的代码:
import pureconfig.{loadConfigOrThrow}
object Source{
def apply(keyName: String, configArguments: Config): Source = {
keyName.toLowerCase match {
case "mysql" =>
val properties = loadConfigOrThrow[DBConnectionProperties](configArguments)
new MysqlSource(None, properties)
case "files" =>
val properties = loadConfigOrThrow[FilesSourceProperties](configArguments)
new Files(properties)
case _ => throw new NoSuchElementException(s"Unknown Source ${keyName.toLowerCase}")
}
}
}
import Source
val config = ConfigFactory.parseString(result.mkString("\n"))
val source = Source("mysql",config.getConfig("source.mysql"))
当我 运行 它来自 IDE (intelliJ) 或直接来自 java (即 java jar...)它工作正常。
但是当我使用 spark-submit 运行 它失败并出现以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: shapeless.Witness$.mkWitness(Ljava/lang/Object;)Lshapeless/Witness;
通过快速搜索,我找到了与此类似的内容
我尝试shade it按照答案中的建议
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("shapeless.**" -> "shadeshapless.@1")
.inLibrary("com.github.pureconfig" %% "pureconfig" % "0.7.0").inProject
)
但效果不佳 会不会是其他原因? 知道什么可行吗?
谢谢
除了 pureconfig 之外,您还必须在其自己的 JAR 中隐藏 shapeless:
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("shapeless.**" -> "shadeshapless.@1")
.inLibrary("com.chuusai" % "shapeless_2.11" % "2.3.2")
.inLibrary("com.github.pureconfig" %% "pureconfig" % "0.7.0")
.inProject
)
确保添加正确的无形版本。