How do I drop a Cassandra table with Spark JDBC?

86 Views Asked by At

I'm writing a Spark-based app and have to drop some tables in Cassandra DB.

I know how to read from tables with spark.read.format("jdbc"). I know how to save dataframe with df.write.format("jbdc").

But how can I drop a table that I don't need anymore?

1

There are 1 best solutions below

2
Erick Ramirez On

To drop a Cassandra table, you can simply use the Spark SQL DROP TABLE command:

spark.sql("DROP TABLE table_name")

Note that the JDBC API is limited so our general recommendation is to use the Spark Cassandra connector. It is fully open-source so is free to use.

The Spark Cassandra connector is a library specifically designed for connecting to Cassandra clusters from Spark applications. Cassandra tables are exposed as DataFrames or RDDs and the connector also allows execution of the full CQL API. Cheers!