title: Use token ranges to delete billions of Cassandra records using Spark?
body: <p>Over half of the records in my 15TB Cassandra table are now obsolete and I want to delete them. I've written a Spark job for it but it seems fragile and usually dies with timeout errors (no mention of tombstones). So I'd like to scan the table in a series of smaller jobs, each processing a distinct and limited part of the table (thus hopefully avoiding dreaded tombstone problems). Unfortunately with my index I can't query for exactly the obsolete records, so I have to check them all. My intended approach is to select WHERE TOKEN(partition_key) &gt; M AND TOKEN(partition_key) &lt; N and choose a series of M,N to work my way through the table. Alas, Spark seems to have a similar idea, and so I get this error:</p>
  <p>Exception during preparation of SELECT ... FROM ... WHERE token(&quot;context&quot;, &quot;itemid&quot;) &gt; ? AND token(&quot;context&quot;, &quot;itemid&quot;) &lt;= ? AND token(context, itemid) &gt; 9200000005000000000 AND token(context, itemid) &lt; 9223372036854775807 ALLOW FILTERING: More than one restriction was found for the start bound on context, itemid</p>
  <p>I'm pretty sure that the first two conditions are being inject by Spark. I don't know where the ALLOW FILTERING is coming from.</p>
  <p>This index obviously wasn't designed with this purge operation in mind. And at some point I might bite the bullet and migrate to a copied table sans the obsolete records. But I'd like to do this purge in-place, if feasible.</p>