背景:
很抱歉打扰您,我正在努力安装 Cassandra-Spark 连接器。我的目标是安装它以使用 Spark-SQL,因为 Cassandra 对执行请求有很大的限制。
我有:
它匹配 3.1.0 连接器 (https://github.com/datastax/spark-cassandra-connector)。
我尝试提交一个名为 titi.py 的简单文件(例如)来检查它是否适用于该命令:
spark-submit dev_spark/titi.py \
--packages com.datastax.spark:spark-cassandra-connector_2.12:3.1.0
错误部分:
我收到错误消息:
Traceback (most recent call last): File "/home/ubuntu/dev_spark/titi.py", line 12, in \\\<module\\\> .load()
File "/home/ubuntu/spark/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 210, \
in load File "/home/ubuntu/spark/python/lib/py4j-0.10.9-src.zip/py4j/java_gateway.py", line 1304, \
in \__call_\_ File "/home/ubuntu/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 111, \
in deco File "/home/ubuntu/spark/python/lib/py4j-0.10.9-src.zip/py4j/protocol.py", line 326, \
in get_return_value py4j.protocol.Py4JJavaError: An error occurred while calling o36.load. : \
java.lang.ClassNotFoundException: Failed to find data source: org.apache.spark.sql.cassandra. \
Please find packages at http://spark.apache.org/third-party-projects.html \
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:689) \
at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSourceV2(DataSource.scala:743) \
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:266) \
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:226) \
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:750) \
Caused by: java.lang.ClassNotFoundException: org.apache.spark.sql.cassandra.DefaultSource \
at java.net.URLClassLoader.findClass(URLClassLoader.java:387) \
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) \
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) \
at org.apache.spark.sql.execution.datasources.DataSource$.$anonfun$lookupDataSource$5(DataSource.scala:663) \
at scala.util.Try$.apply(Try.scala:213) \
at org.apache.spark.sql.execution.datasources.DataSource$.$anonfun$lookupDataSource$4(DataSource.scala:663) \
at scala.util.Failure.orElse(Try.scala:224)
Python 文件信息
有关信息,请在测试 titi.py 文件中:
from pyspark.sql import SparkSession
spark = SparkSession.builder \
.appName("CassandraIntegration") \
.config("spark.cassandra.connection.host", "tp-hadoop-33") \
.config("spark.cassandra.connection.port", "9042") \
.getOrCreate()
df = spark.read \
.format("org.apache.spark.sql.cassandra") \
.options(table="request_2", keyspace="gdelt") \
.load()
spark.stop()
感谢您的帮助,如果您有任何想法,祝您周末愉快!
首先,您是将作业发送到集群还是在独立机器上运行?看起来 Application Master 无法找到 Cassandra 包。您可以尝试将 JAR 复制到 Spark 安装目录吗?如果是集群设置,最好在所有节点上都有 JAR。
您可以参考一个非常好的博客这里