Search code examples
scalaapache-sparkcassandraspark-cassandra-connector

spark-cassandra-connector: add column on the fly


The following cqlsh command adds a column to an already existing cassandra table.

cqlsh:demodb> ALTER TABLE users ADD coupon_code varchar;

How would I do the same with the scala spark-cassandra-connector?

I am not seeing reference in the documents.

ALSO: Is there a scaladoc for com.datastax.spark.connector?


Solution

  • You can use withSessionDo method of the CassandraConnector, like this:

    import com.datastax.spark.connector.cql.CassandraConnector
    
    CassandraConnector(conf).withSessionDo { session =>
       session.execute("ALTER TABLE users ADD coupon_code varchar;")
    }
    

    See more examples in documentation for Spark Cassandra connector...