【问题标题】:Exception "com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor" in scala Applicationscala 应用程序中的异常“com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor”
【发布时间】:2020-08-21 04:00:58
【问题描述】:

我使用shadow jar为从Mysql DB到GCS的数据移动过程制作了一个scala应用程序。

使用的 Gradle 依赖项:

 compile group: 'org.apache.spark', name: 'spark-sql_2.11', version: '2.3.0'
 compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
 compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.3.0'
 compile group: 'com.google.cloud', name: 'google-cloud-storage', version: '1.110.0'
 compile group: 'com.google.oauth-client', name: 'google-oauth-client', version: '1.30.6'
 compile group: 'com.typesafe', name: 'config', version: '1.0.2'
 compile group: 'com.google.cloud', name: 'google-cloud-bigquery', version: '1.116.3'
 compile group: 'com.google.api', name: 'gax', version: '0.2.0'
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre7'

使用的Java版本:1.8

错误 1:

无法在 GCS 中创建 blob 以将 parquet 文件移动到那里,但以下异常:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

解决方案 1: 在对此错误的研究中,我得出结论,这是由于我使用影子 jar 时缺少依赖项或某些依赖项版本冲突,并解决了我添加的问题

--conf spark.driver.userClassPathFirst=true --conf spark.executor.userClassPathFirst=true

在我的 spark 提交 cmd。

错误2: 现在我能够在我的 GCS 中创建 blob 并且 error1 已解决,但 spark 会话停止工作并且无法从数据库中获取数据并抛出以下异常:

Exception in thread "main" java.util.ServiceConfigurationError: org.apache.spark.sql.sources.DataSourceRegister: Provider org.apache.spark.sql.hive.orc.OrcFileFormat not a subtype

那么我怎样才能在没有任何错误的情况下执行我的影子 jar。

GCS 错误(Error1)的代码 sn-p:

val Credentials: GoogleCredentials = ServiceAccountCredentials.fromPkcs8(client_id, client_email, private_key, private_key_id, null)
val Storage= StorageOptions.newBuilder().setCredentials(Credentials).setProjectId(strProjectId).build().getService

val blobId: BlobId = BlobId.of(strGcsBucket, s"$Dir")
val blobInfo: BlobInfo = BlobInfo.newBuilder(blobId).build()
Storage.create(blobInfo, Files.readAllBytes(fPath))

Spark 会话错误(Error2)的代码 sn-p:

val Spark: SparkSession = SparkSession.builder()
    .master("local")
    .appName("Migration App")
    .getOrCreate()

【问题讨论】:

    标签: scala apache-spark google-cloud-platform google-cloud-storage


    【解决方案1】:

    我通过在 build.gradle 中使用 relocate() 解决了这个错误。参考如下:

    shadowJar {
        zip64 true
        mergeServiceFiles()
        relocate ('com.google.common', 'shaded.com.google.common')
    }
    

    这让我的 fatjar 清楚地知道,它对提到的 shadowjar 依赖版本而不是本地平台依赖提供了偏好。

    【讨论】:

      猜你喜欢
      • 2019-01-18
      • 1970-01-01
      • 2020-04-13
      • 2017-10-11
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 2018-02-01
      相关资源
      最近更新 更多