I am trying to read data stored in Solr through the spark, but I am not able to show the execession below. However I am passing the following drivers in the Livy configuration. I have tried other driver versions, but to no avail. My Spark is version 2.3.1 and Solr 7.4.0.
I already tried to remove Solr-solrj.jar, because spark-solr contains it, but without success too.
Livy config:
"jars": [
"hdfs://hdfs-name/utils/jars/solr/solr-solrj-8.6.1.jar",
"hdfs://hdfs-name/utils/jars/spark-solr-3.8.0.jar"
]
Pyspark code:
df = spark.read.format('solr').option("zkhost","zk-host:2181").option('collection','collection_name').load()
Error:
An error was encountered:
An error occurred while calling o135.load.
: java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParameter
at solr.DefaultSource.createRelation(DefaultSource.scala:12)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:341)
at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:239)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:227)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
Traceback (most recent call last):
File "/dados01/yarn/local/usercache/livy/appcache/application_1592863719820_6421/container_e574_1592863719820_6421_01_000001/pyspark.zip/pyspark/sql/readwriter.py", line 172, in load
return self._df(self._jreader.load())
File "/dados01/yarn/local/usercache/livy/appcache/application_1592863719820_6421/container_e574_1592863719820_6421_01_000001/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/dados01/yarn/local/usercache/livy/appcache/application_1592863719820_6421/container_e574_1592863719820_6421_01_000001/pyspark.zip/pyspark/sql/utils.py", line 63, in deco
return f(*a, **kw)
File "/dados01/yarn/local/usercache/livy/appcache/application_1592863719820_6421/container_e574_1592863719820_6421_01_000001/py4j-0.10.7-src.zip/py4j/protocol.py", line 328, in get_return_value
format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o135.load.
: java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParameter
at solr.DefaultSource.createRelation(DefaultSource.scala:12)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:341)
at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:239)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:227)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more
the problem was solved as follows:
I entered all the servers that run Spark and also hdfs, looked for the solr jar that was in the spark system path (spark-solr-3.6.0.jar), as the jar was in one of Yarn's caches (/data/yarn/local/filecache or /data/yarn/local/usercache), I deleted the jar from all cache places, so it stopped showing up in spark's system path. After that, I just imported the necessary jars for Livy and it worked again. The jar looks like it was corrupted, so it was imported into Spark but the libs were not working