'How to delete rows in YugabyteDB YCQL spark connector?

[Question posted by a user on YugabyteDB Community Slack]

Is it possible in YugabyteDB YCQL Spark connector to delete rows? If yes, how?



Solution 1:[1]

Yes, it is possible. You can apply this patch to the repo to see how you would run a delete inside a test case:

diff --git a/java/yb-cql-4x/src/test/java/org/yb/loadtest/TestSpark3Jsonb.java b/java/yb-cql-4x/src/test/java/org/yb/loadtest/TestSpark3Jsonb.java
index 50d075b529..3ccf3b42f4 100644
--- a/java/yb-cql-4x/src/test/java/org/yb/loadtest/TestSpark3Jsonb.java
+++ b/java/yb-cql-4x/src/test/java/org/yb/loadtest/TestSpark3Jsonb.java
@@ -124,6 +124,7 @@ public class TestSpark3Jsonb extends BaseMiniClusterTest {
       }
       // TODO to update a JSONB sub-object only using Spark SQL --
       // for now requires using the Cassandra session directly.
+      session.execute("delete from " + tableWithKeysapce + " where id=3");
       String update = "update " + tableWithKeysapce +
           " set phone->'key'->1->'m'->2->'b'='320' where id=4";
       session.execute(update);

In the test output, you would see:

+---+----------------------+-----+-----------------------------------------------------------------+
|id |address               |name |phone                                                            |
+---+----------------------+-----+-----------------------------------------------------------------+
|2  |Acton London, UK      |Nick |{"code":"+43","phone":1200}                                      |
|4  |4 Act London, UK      |Kumar|{"code":"+45","key":[0,{"m":[12,-1,{"b":320},500]}],"phone":1500}|
|1  |Hammersmith London, UK|John |{"code":"+42","phone":1000}                                      |
+---+----------------------+-----+-----------------------------------------------------------------+

where the row below is deleted:

|3  |11 Acton London, UK   |Smith|{"code":"+44","phone":1400}|

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dh YB