I am using the Spark Cassandra Connector 3.1.0 Java API to both add and delete rows in a Cassandra 3.11.2 database. However, I am having trouble coding the delete operations using the SCC Java classes.
I have read the SCC Github documentation as well as other web postings regarding use of the Java API and row deletion using SCC. While this appears to be pretty straightforward using Scala, I haven't found good guidance on how to do it in Java.
I am simply trying to delete all the rows with a given partition key, which in Scala would be something like this.
sc.cassandraTable("myKeyspace", "myTable") .where("key1 = 'a' AND key2 = 'b' and key3 = 'c'") .deleteFromCassandra("myKeyspace", "myTable")
In Java, I am trying to use the CassandraJavaUtil.javaFunctions wrapper methods to accomplish the same, something like this.
CassandraTableScanJavaRDD<CassandraRow> rdd = javaFunctions(sc.cassandraTable("myKeyspace", "myTable")) .where("key1 = 'a' AND key2 = 'b' and key3 = 'c'"); javaFunctions(rdd).deleteFromCassandra("myKeyspace", "myTable", ...);
However, the RDDJavaFunctions.deleteFromCassandra() signature after the first two parameters seems confusing and verbose:
deleteFromCassandra(keyspace: String, table: String, rowWriterFactory: RowWriterFactory[T], deleteColumns: ColumnSelector, keyColumns: ColumnSelector, conf: WriteConf, connector: CassandraConnector): Unit
In particular, I don't know how to construct the appropriate RowWriterFactory object and why it would even be relevant to a delete. The ColumnSelector entries look like they could be simple maps, although I don't need to specify any mappings in this case. I understand the WriteConf and the CassandraConnector, although I don't know why the latter would be necessary.
It would be easier if the simpler RDDFunctions.deleteFromCassandra() implementation could be used, but that doesn't seem to be an option. Looking at the source code, I see that RDDJavaFunctions.deleteFromCassandra() delegates to RDDFunctions.deleteFromCassandra(), which doesn't use the RowWriterFactory object at all although the parameter is required.
At this point I expect there is something I am missing that would make this easier. Is there another deleteFromCassandra() implementation that can be directly called in Java? What is the best way to process basic deletes in Java using the Spark Cassandra Connector?