大数据

pyspark运行启动报java.lang.NoSuchMethodError错误

文 / sptk 来源 / 原创 阅读 / 35 4天前

错误说明

遇到报 java.lang.NoSuchMethodError 这个错误,基本可以确定是环境问题导致的

排查问题的思路

  1. 检查pyspark版本与spark版本是否一致, 例如: pyspark版本是3.2 spark版本是3.1.2那么很大可能会有问题
  2. 检查是否是缺少对应的jar包依赖, java.lang.NoSuchMethodError: org.apache.hadoop.fs.FileSystem.openFile 例如提示缺少这个 说明 运行过程搜索不到 org.apache.hadoop.fs.FileSystem 这个类 2.1 可以先尝试搜索引擎搜索下
FileSystem.openFile()/FileContext.openFile()
This is a method provided by both FileSystem and FileContext for advanced file opening options and, where implemented, an asynchrounous/lazy opening of a file.

Creates a builder to open a file, supporting options both standard and filesystem specific. The return value of the build() call is a Future<FSDataInputStream>, which must be waited on. The file opening may be asynchronous, and it may actually be postponed (including permission/existence checks) until reads are actually performed.

This API call was added to FileSystem and FileContext in Hadoop 3.3.0; 

根据提示信息 这个是hadoop3.3 以后得版本引入的 说明运行过程没有加载到对应的jar包 2.2 借助gtp帮助我们快速定位对应的jar包 ,运行期间没有加载hadoop相关的jar包 hadoop-common-3.3.0.jar 或者 hadoop-hdfs-client-3.3.0.jar 2.3 去spark的jars目录中查看是否有对应的模块包 ls $SPARK_HOME/jars | grep hadoop- 查看是否有对应包或者模块, 如果没有我们则拷贝对应的包到这个目录中 2.4 如果有, 那么说明肯呢个是包冲突 因为haodop中也有对应的jar包 运行过程可能优先加载 hadoop的中jar包 . 正常情况优先加载$SPARK_HOME/jars 中的依赖包 注意: 我们也可能是因为pyspark版本高导致的降低即可

  1. 如果想进一步检查启动过程的家长的jar的 我们可以启动pyspark的时候指定对应的参数
// 这两个参数科技帮助我们 展示启动那个过程加载了哪些jar包, 通过这个确定对应的jar包是否有正常加载
pyspark --conf "spark.driver.extraJavaOptions=-verbose:class" \
        --conf "spark.executor.extraJavaOptions=-verbose:class" > driver_excutor.log 2>&1

总结

  1. 版本冲突导致的 调整版本
  2. jar依赖缺失 下载对应的依赖添加到我们的jar相关的库目录

拓展 jar包中类与方法确定

# 1. 缺省某个包是否有指定的类
jar -tf xxx.jar |  grep classname
#  示例
jar -tf hadoop-common-3.2.0.jar | grep FileSystem

# 2. 确定某个类中是否有对一个的方法  利用javap反向编码
#  javap -cp xxx.jar complete_classname 可以展示某个类中有什么方法
javap -cp hadoop-common-3.2.0.jar org.apache.hadoop.fs.FileSystem | grep openFile

0

站点声明:站点主要用于个人技术文章。

冀ICP备19037883号
相关侵权、举报、投诉及建议等,请发E-mail:804330969@qq.com