2
votes

I'd like to use Datastax's spark-cassandra-connector in AWS Glue. If I run pyspark locally, my command would look like

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

How to run this script in Glue?


Things I've tried

  • How to import Spark packages in AWS Glue? It looks similar to my question. The accepted answer talks about adding a zipped python module as parameter. But the spark-cassandra-connector isn't a python module.

  • (according to @alex's comment) put the SCC assembly in the Glue job's Jar lib path enter image description here

Error:

    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)
......
  • (according to @alex's comment) put spark.jars.packages = com.datastax.spark:spark-cassandra-connector_2.12:2.5.1 in the Glue job's job parameter

enter image description here

Error:

  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)
......
1
what is the problem with things that you have tried? - Alex Ott
@AlexOtt I added the error log to my post. It seems like the spark connector library isn't properly loaded. - F.S.
can you try the things that I described about packages, and SCC 3.0 - Alex Ott

1 Answers

0
votes

The recommended way is to use --packages or --conf spark.jars.packages with Maven coordinates, so Spark will correctly pull all necessary dependencies that are used by Spark Cassandra Connector (Java driver, etc.) - if you use --jars with only SCC jar, then your job will fail.

Starting with SCC 2.5.1, there is also a new artifact - spark-cassandra-connector-assembly that includes all necessary dependencies. With it you can avoid problems with conflicting dependencies, plus you can use it with --jars or with Glue job's Jar lib path.

P.S. With Spark 3.0 it's recommended to use SCC 3.0.0-beta, because of significant changes in internals of Spark SQL.