I am trying to move all my data from one column-family (table) to the other. Since both the tables have different descriptions, I would have to pull all data from table-1 and create a new object for table-2 and then do a bulk aync insert. My table-1 has millions of records so I cannot get all the data directly in my data structure and work that out. I am looking out for solutions to do that easily using Spring Data Cassandra with Java.
I initially planned for moving all the data to a temp table first followed by creating some composite key relations and then querying back my master table. However, it doesn't seems favorable to me. Can anyone suggest a good strategy to do this? Any leads would be appreciated. Thanks!
解决方案My table-1 has millions of records so I cannot get all the data directly in my data structure and work that out.
With datastax java driver you can get all data by token ranges and work out data from each token range. For example:
Set tokenRanges = cassandraSession.getCluster().getMetadata().getTokenRanges();
for(TokenRange tr: tokenRanges) {
List rows = new ArrayList<>();
for(TokenRange sub: tr.unwrap()){
String query = "SELECT * FROM keyspace.table WHERE token(pk) > ? AND token(pk) <= ?";
SimpleStatement st = new SimpleStatement( query, sub.getStart(), sub.getEnd() );
rows.addAll( session.execute( st ).all() );
}
transformAndWriteToNewTable(rows);
}
Each token range contains only piece of all data and can be handled by one physical machine. You can handle each token range independently (in parallel or asynchronously) to get more performance.