To connect to a Cassandra database from a Spark application, you need to use the Spark Cassandra connector library. I am not aware of alternative options that would allow you to connect to Cassandra otherwise.
Here's an example that shows how to use the connector from a Spark 3.2 cluster with spark-shell
:
$ spark-shell
--packages com.datastax.spark:spark-cassandra-connector_2.12:3.2.0
--master <master_url>
--conf spark.cassandra.connection.host=cass_ip
--conf spark.cassandra.auth.username=cass_user
--conf spark.cassandra.auth.password=cass_pass
--conf spark.sql.extensions=com.datastax.spark.connector.CassandraSparkExtensions
Here's an example code that you can run in a Spark shell to count the the number of keyspaces:
val rdd = sc.cassandraTable("system_schema","keyspaces")
println("Row count: " + rdd.count)
Please support the Apache Cassandra community by hovering over the cassandra tag then click on the Watch tag
button. Thanks!