Skip to content
Advertisement

NoSuchMethodError in shapeless seen only in Spark

I am trying to write a Spark connector to pull AVRO messages off a RabbitMQ message queue. When decoding the AVRO messages, there is a NoSuchMethodError error that occurs only when running in Spark.

I could not reproduce the Spark code exactly outside of spark, but I believe the two examples are sufficiently similar. I think this is the smallest code that reproduces the same scenario.

I’ve removed all the connection parameters both because the information is private and the connection does not appear to be the issue.

Spark code:

JavaScript

Non-Spark code:

JavaScript

Non-Spark Output (the last line is a successfully decoded update):

JavaScript

Spark Output:

JavaScript

build.sbt:

JavaScript

I am also using assembly to put together a “fat jar” for spark (addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.4")) and using the command sbt assembly to produce the jar used in both examples above. I’m running Spark 2.1.0.

I’m relatively new to the Spark / Scala ecosystem so hopefully this is a problem with my build settings. It makes no sense that shapeless would be unavailable in Spark.

Advertisement

Answer

Same issue myself. I just add more details for others facing it.

Error

Everything works fine till I deploy to cluster. Then I get

JavaScript

Root Cause

Following the stacktrace, I know it is related to the circe library. Then I run the dependency (make sure you have addDependencyTreePlugin in your ~/.sbt/1.0/plugins/plugins.sbt file):

JavaScript

but if I run the dependency with “provided” scope, I get:

JavaScript

As you can see, the instance function in version 2.3.7 is not present in version 2.3.3 (it is added in version 2.3.5):

Didn’t work

Adding the dependency didn’t fix my issue.

JavaScript

I keep this in my code just for documentation purpose only.

What worked

The main fix is actually to rename Shapeless library (see my comments)the question that I pick the answer

JavaScript

Update 2022-08-20

Based on @denis-arnaud comment, here is a simpler version from pureconfig

JavaScript

I guess the simple one works for most the situations. The more complex one is good for when there are different versions of shapeless in the classpath, and you’d like to rename them in @1, @2, etc.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement