After checking all sources found datastax-spark-cassandra connector supports automatic creation of table in cassandra with rdd in scala and java. For pyspark specifically another package is available to do this job -- https://github.com/anguenot/pyspark-cassandra. But even with this package unable to create table automatically. With dataframe I didn't found any option at all. Am new to pyspark and cassandra, any help is highly appreciated. Tried using only anguenot package as dependency as well. Spark version : 2.4.7 Cassandra : latest docker image
Pyspark shell >> pyspark --packages anguenot/pyspark-cassandra:2.4.0,com.datastax.spark:spark-cassandra-connector_2.11:2.5.1
>>> spark = SparkSession.builder.master('local[*]').appName('cassandra').config("spark.cassandra.connection.host", "ip").config("spark.cassandra.connection.port", "port").config("spark.cassandra.auth.username", "username").config("spark.cassandra.auth.password", "password").getOrCreate()
>>> from datetime import datetime
>>> rdd = sc.parallelize([{
... "key": k,
... "stamp": datetime.now(),
... "tags": ["a", "b", "c"],
... "options": {
... "foo": "bar",
... "baz": "qux",
... }
... } for k in ["x", "y", "z"]])
>>> rdd.saveToCassandra("test", "testTable")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'RDD' object has no attribute 'saveToCassandra'