Skip to content

Instantly share code, notes, and snippets.

@jsanda
Last active August 5, 2016 22:00
Show Gist options
  • Save jsanda/91abe44243748d9606818dbf2efca40a to your computer and use it in GitHub Desktop.
Save jsanda/91abe44243748d9606818dbf2efca40a to your computer and use it in GitHub Desktop.
// Resets keyspace by truncating all tables in keyspace.
//
// session is an Rx wrapper around com.datastax.driver.core.Session and
// and uses the async methods in Session. The execute method return an
// Observable<ResultSet>.
public void truncateTables(String keyspace) {
session.execute("select table_name from system_schema.tables where keyspace_name = '" + keyspace + "'")
.flatMap(Observable::from)
.flatMap(row -> session.execute("truncate " + row.getString(0)))
.toCompletable()
.await(10, TimeUnit.SECONDS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment