I tried to set up a basic example getting a Spark job to read an Avro container file with Avro specifics. This results in a ClassNotFoundException: can't convert GenericData.Record to com.cloudera.sparkavro.User.
The reason is:
- When creating records, to decide whether to be specific or generic, Avro tries to load a class with the name specified in the schema.
- Initially, executors just have the system jars (which include Avro), and load the app jars dynamically with a URLClassLoader that's set as the context classloader for the task threads.
- Avro tries to load the generated classes with SpecificData.class.getClassLoader(), which sidesteps this URLClassLoader and goes up to the AppClassLoader.
Avro 1.7.6 has a change (
AVRO-987) that falls back to the Thread's context classloader when the SpecificData.class.getClassLoader() fails. I tested with Avro 1.7.6 and did not observe the problem.