如何在aws胶水中使用spark包?

hpxqektj  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(498)

我想用datastax的SparkCassandra连接器在aws胶水。如果我在本地运行pyspark,我的命令

path/to/spark-3.0.1-bin-hadoop2.7/bin/spark-submit \
--conf spark.cassandra.connection.host=XXX \
--conf spark.cassandra.auth.username=XXX \
--conf spark.cassandra.auth.password=XXX \
--packages com.datastax.spark:spark-cassandra-connector_2.12:2.5.1 \
~/my_script.py

如何用胶水运行这个脚本?
我试过的东西
如何在aws胶水中导入spark包?看起来和我的问题很相似。公认的答案是添加一个压缩的python模块作为参数。但是 spark-cassandra-connector 不是python模块。
(根据@alex的评论)把scc组件放到胶水作业的 Jar lib path
错误:

File "/tmp/delta_on_s3_spark.py", line 75, in _write_df_to_cassandra
    df.write.format(format_).mode('append').options(table=table, keyspace=keyspace).save()
  File "/opt/amazon/spark/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 732, in save
    self._jwrite.save()
  File "/opt/amazon/spark/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/opt/amazon/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 63, in deco
    return f(*a,**kw)
  File "/opt/amazon/spark/python/lib/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 o84.save.
: java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V
    at com.datastax.spark.connector.TableRef.<init>(TableRef.scala:4)
    at org.apache.spark.sql.cassandra.DefaultSource$.TableRefAndOptions(DefaultSource.scala:142)
    at org.apache.spark.sql.cassandra.DefaultSource.createRelation(DefaultSource.scala:83)
......

(根据@alex的评论)把 spark.jars.packages = com.datastax.spark:spark-cassandra-connector_2.12:2.5.1 在胶水工作的 job parameter
错误:

File "/tmp/delta_on_s3_spark.py", line 75, in _write_df_to_cassandra
    df.write.format(format_).mode('append').options(table=table, keyspace=keyspace).save()
  File "/opt/amazon/spark/python/lib/pyspark.zip/pyspark/sql/readwriter.py", line 732, in save
    self._jwrite.save()
  File "/opt/amazon/spark/python/lib/py4j-0.10.7-src.zip/py4j/java_gateway.py", line 1257, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/opt/amazon/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 63, in deco
    return f(*a,**kw)
  File "/opt/amazon/spark/python/lib/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 o83.save.
: 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:657)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:245)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
......
6ss1mwsb

6ss1mwsb1#

推荐的方法是 --packages 或者 --conf spark.jars.packages 使用maven坐标,因此spark将正确地提取spark cassandra连接器(java驱动程序等)使用的所有必要的依赖项 --jars 只有scc jar,那么你的工作就会失败。
从SCC2.5.1开始,还有一个新的工件—spark cassandra连接器组件,它包含所有必要的依赖项。有了它,您可以避免与冲突的依赖关系有关的问题,而且您还可以将它用于 --jars 或者使用glue job的jar lib路径。
p、 对于spark3.0,建议使用scc3.0.0-beta,因为sparksql的内部结构发生了重大变化。

相关问题