I'm trying to connect spark to cassandra and then I make a query to the keyspace and table from flask.
The problem is that when I run the web application I get an error saying that the keyspace in not created.
cassandra.InvalidRequest: Error from server: code=2200 [Invalid query] message="Keyspace MyKeyspace does not exist"
In spark I run the following commands:
val flightRecommendations = finalPredictions.writeStream.foreachBatch {
(batchDF: DataFrame, batchId: Long) =>
batchDF
.write
.cassandraFormat("MytableName", "MyKeyspace")
.option("cluster", "cassandra_cluster")
.mode("append")
.save
}.start()
My question is whether the above code automatically generates the keyspace and the table.
I think it could also be a problem of connection because I'm working in docker and the setting I put is this:
spark.setCassandraConf("cassandra_cluster", CassandraConnectorConf.ConnectionHostParam.option("cassandra"))
Also in the spark-submit command I put the following two configurations:
--conf spark.cassandra.connection.host=cassandra \
--conf spark.sql.extensions=com.datastax.spark.connector.CassandraSparkExtensions \
It's weird because the spark-submit doesn't give errors but the keyspace is not created.