无法在来自 Apache Spark SQL 1.5.2 的 SQL 上下文中 运行 查询,获取 java.lang.NoSuchMethodError

Cannot run queries in SQLContext from Apache Spark SQL 1.5.2, getting java.lang.NoSuchMethodError

我有一个使用 Spark SQL 的 Java 应用程序(Spark 1.5.2 使用 本地模式),但我无法在不出错的情况下执行任何SQL命令。

这是我正在执行的代码:

//confs
SparkConf sparkConf = new SparkConf();  
sparkConf.set("spark.master","local");
sparkConf.set("spark.app.name","application01");
sparkConf.set("spark.driver.host","10.1.1.36");
sparkConf.set("spark.driver.port", "51810");
sparkConf.set("spark.executor.port", "51815");
sparkConf.set("spark.repl.class.uri","http://10.1.1.36:46146");
sparkConf.set("spark.executor.instances","2");
sparkConf.set("spark.jars","");
sparkConf.set("spark.executor.id","driver");
sparkConf.set("spark.submit.deployMode","client");
sparkConf.set("spark.fileserver.uri","http://10.1.1.36:47314");
sparkConf.set("spark.localProperties.clone","true");
sparkConf.set("spark.app.id","app-45631207172715-0002");

//Initialize contexts
JavaSparkContext sparkContext = new JavaSparkContext(sparkConf);
SQLContext sqlContext = new SQLContext(sparkContext);           

//execute command
sqlContext.sql("show tables").show();

pom.xml 中的 Spark 依赖项如下所示:

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_2.10</artifactId>
  <version>1.5.2</version>
</dependency>

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-sql_2.10</artifactId>
  <version>1.5.2</version>
</dependency>

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-hive_2.10</artifactId>
  <version>1.5.2</version>
</dependency>

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-repl_2.10</artifactId>
  <version>1.5.2</version>
</dependency>

这是我收到的错误:

java.lang.NoSuchMethodError: com.fasterxml.jackson.module.scala.deser.BigDecimalDeserializer$.handledType()Ljava/lang/Class;

堆栈跟踪here

我的应用程序是一个 Web 应用程序 运行ning on Tomcat 7. 我没有任何其他配置文件。我做错了什么?会不会是某种依赖冲突,因为我能够 运行 在干净的项目中使用相同的代码?

编辑:我找到了一个issue,它提供了有关该问题的更多信息。

BigDecimalDeserializer wasn't introduced to FasterXML/jackson-module-scala until 2.4。确认以下内容:

  1. 您编译时使用的相同 jar 在运行时位于类路径中。
  2. pom.xml file for Spark SQL 中的
  3. ${fasterxml.jackson.version} 为 2.4.x 或更大。
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.4.4</version>
</dependency>

在这种情况下,由于maven 依赖冲突,出现了NoSuchMethodError。

您的项目在编译时使用的库不可用,或者在运行时正在使用其他版本的库。

我尝试了很多方法来解决这个冲突问题,最后以下对我有用 -

只需将 jackson.databind 的正确依赖版本添加为 pom.xml 中的第一个依赖项即可。

使用版本 2。4.x 或 jackson.databind 依赖项的更高版本。

注意:这仅适用于 Maven 版本 2.0.9 及更高版本。

为什么会这样?

在 Maven 2.0.9 中,添加了传递依赖的新特性。

Dependency mediation - this determines what version of a dependency will be used when multiple versions of an artifact are encountered. Currently, Maven 2.0 only supports using the "nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, until Maven 2.0.8 it was not defined which one would win, but since Maven 2.0.9 it's the order in the declaration that counts: the first declaration wins.

Maven Transitive Dependency