SBT测试错误:java.lang.NoSuchMethodError:net.jpountz.lz4.LZ4BlockInputStream

时间:2018-06-18 10:28:43

标签: scala apache-spark sbt spark-streaming scalatest

获得以下异常,当我尝试使用scalatest在SBT窗口上对我的火花流代码执行单元测试时。

sbt testOnly <<ClassName>>

  

*
  *
  *
  *
  *
  *

     

2018-06-18 02:39:00错误执行者:91 - 阶段3.0(TID 11)中任务1.0中的异常   java.lang.NoSuchMethodError:net.jpountz.lz4.LZ4BlockInputStream。(Ljava / io / InputStream; Z)V           在org.apache.spark.io.LZ4CompressionCodec.compressedInputStream(CompressionCodec.scala:122)           在org.apache.spark.serializer.SerializerManager.wrapForCompression(SerializerManager.scala:163)           在org.apache.spark.serializer.SerializerManager.wrapStream(SerializerManager.scala:124)           在org.apache.spark.shuffle.BlockStoreShuffleReader $$ anonfun $ 2.apply(BlockStoreShuffleReader.scala:50)           在org.apache.spark.shuffle.BlockStoreShuffleReader $$ anonfun $ 2.apply(BlockStoreShuffleReader.scala:50)           在org.apache.spark.storage.ShuffleBlockFetcherIterator.next(ShuffleBlockFetcherIterator.scala:417)           在org.apache.spark.storage.ShuffleBlockFetcherIterator.next(ShuffleBlockFetcherIterator.scala:61)           在scala.collection.Iterator $$ anon $ 12.nextCur(Iterator.scala:435)           在scala.collection.Iterator $$ anon $ 12.hasNext(Iterator.scala:441)           在scala.collection.Iterator $$ anon $ 11.hasNext(Iterator.scala:409)           在org.apache.spark.util.CompletionIterator.hasNext(CompletionIterator.scala:32)           在org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:37)           在scala.collection.Iterator $$ anon $ 11.hasNext(Iterator.scala:409)           at org.apache.spark.sql.catalyst.expressions.GeneratedClass $ GeneratedIteratorForCodegenStage1.sort_addToSorter $(未知来源)           at org.apache.spark.sql.catalyst.expressions.GeneratedClass $ GeneratedIteratorForCodegenStage1.processNext(Unknown Source)           在org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)           在org.apache.spark.sql.execution.WholeStageCodegenExec $$ anonfun $ 10 $$ anon $ 1.hasNext(WholeStageCodegenExec.scala:614)           在org.apache.spark.sql.execution.GroupedIterator $ .apply(GroupedIterator.scala:29)           at org.apache.spark.sql.execution.streaming.FlatMapGroupsWithStateExec $ StateStoreUpdater.updateStateForKeysWithData(FlatMapGroupsWithStateExec.scala:176)**

尝试了几项以排除net.jpountz.lz4 jar(包含其他帖子的建议),但输出中又出现了同样的错误。

目前使用spark 2.3,scalatest 3.0.5,Scala 2.11版本。我只有在升级到spark 2.3和scalatest 3.0.5之后才会看到这个问题

有什么建议吗?

2 个答案:

答案 0 :(得分:20)

Kafka与Spark有冲突的依赖关系,这就是导致我这个问题的原因。

这是如何exclude sbt文件中的依赖项

lazy val excludeJpountz = ExclusionRule(organization = "net.jpountz.lz4", name = "lz4")

lazy val kafkaClients = "org.apache.kafka" % "kafka-clients" % userKafkaVersionHere excludeAll(excludeJpountz) // add more exclusions here

现在,当您使用此kafkaClients依赖项时,它将排除有问题的lz4库。


更新:  这似乎是Kafka 0.11.x.x和更早版本的问题。自1.x.x起,Kafka似乎已不再使用有问题的net.jpountz.lz4库。因此,将最新的Kafka(1.x)与最新的Spark(2.3.x)一起使用应该不会出现此问题。

答案 1 :(得分:0)

此工件“ net.jpountz.lz4:lz4”已移至: “ org.lz4»lz4-java”

通过使用; libraryDependencies + =“ org.lz4”%“ lz4-java”%“ 1.7.1”,此问题已解决。