spark版本升级问题org.apache.spark.Logging

git下面有一个spark项目,用的版本是1.6.2,据说很稳定的一个版本,因为在2.0以后出来一个sparksession整合df和df 于是将spar库版本升到2.4.3,下面是遇到的问题

1.升级后找不到org.apache.spark.Logging。

  1.6.2中用的trait Logging 找不到org.apache.spark.Logging。

  在spark2.4.3中对应是org.apache.spark.internal.Logging2.toArray()算子已经被collect替代

3.并且编译报错 missing or invalid dependency detected while loading class file 'ProductRDDFunctions.class'.

Error:scalac: missing or invalid dependency detected while loading class file 'ProductRDDFunctions.class'.
Could not access type Logging in package org.apache.spark,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'ProductRDDFunctions.class' was compiled against an incompatible version of org.apache.spark.

进入到ProductRDDFunctions源码属于 phoenix-spark版本4.9.0-hbase-1.2包中,报错提到Could not access type Logging in package org.apache.spark, 上面提到logging在2.4.3中全路径是org.apache.spark.internal.Logging。可以判定jar不匹配导致的

本地用的spark是2.4.3  scala2.11,在maven库中找比较新的版本(自己选用的4.14.3-HBase-1.3版本),更新pom依赖版本后问题解决

 

4.升级后编译报错算子mean(),问题为解决,后期解决了补上

   val test: DataFrame = frame.select("rating", "prediction")
  // rating为表中已有的数据,prediction为计算出的预测值
  // mean()为取平均值
// 原来的用法
 // test.map(x=>math.pow(x.getDouble(0)-x.getDouble(1),2)).mean()


//修改后的用法
  val testresult: Dataset[Double] = test.map(x=>math.pow(x.getDouble(0)-x.getDouble(1),2))
   val MSE: DataFrame = testresult.describe("mean")


//修改后编译时报错信息
Error:(32, 45) Unable to find encoder for type Double. An implicit Encoder[Double] is needed to store Double instances in a Dataset. Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._  Support for serializing other types will be added in future releases.
  val testresult: Dataset[Double] = test.map(x=>math.pow(x.getDouble(0)-x.getDouble(1),2))

//按照报错提示添加implicit  var matchError = org.apache.spark.sql.Encoders[DoubleType]依然报错
Spark升级至新版本后,可能会遇到在使用IDEA进行开发时出现找不到org.apache.spark.Logging类的问题,这通常是因为IDEA的项目依赖未能正确更新导致。要解决这个问题,首先需要确保你使用的是与Spark升级版本相兼容的依赖库。一个有效的解决方案是将《spark-core_2.11-1.5.2.logging.jar解决spark升级没有log的jar包》放入Spark的lib目录中,并在IDEA中将这个jar包作为依赖导入。具体操作步骤如下:(详细操作步骤,此处略) 参考资源链接:[spark-core_2.11-1.5.2.logging.jar解决spark升级没有log的jar包](https://wenku.csdn.net/doc/6412b6a1be7fbd1778d47692?spm=1055.2569.3001.10343) 此外,文档中包含了详细的图解说明,能够帮助你直观地理解如何在IDEA中添加这个jar包。这样做可以确保项目在编译和运行时能够识别到org.apache.spark.Logging类,从而解决java.lang.NoClassDefFoundError错误。一旦你完成了上述步骤,你的IDEA环境应该就可以正常工作,不再报找不到类的错误了。为了更深入地了解Spark的运行机制和调试技巧,你可以进一步阅读《spark-core_2.11-1.5.2.logging.jar解决spark升级没有log的jar包》中的其他内容,这份文档将助你全面掌握Spark应用的开发和维护。 参考资源链接:[spark-core_2.11-1.5.2.logging.jar解决spark升级没有log的jar包](https://wenku.csdn.net/doc/6412b6a1be7fbd1778d47692?spm=1055.2569.3001.10343)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值