java将一个表的字段全部复制,使用Java在Cassandra中将数据从一个表复制到另一个表...

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值