【发布时间】:2017-10-18 01:07:39
【问题描述】:
我是 Cassandra 的新手,使用 Cassandra 3.10 并且有类似的表格
create table db1.table1 (id text, trip_id text, event_time timestamp, mileage double, primary key(id, event_time));
create table db1.table2 (id text, trip_id text, start_time timestamp, mileage double, primary key(id, start_time));
我需要将 table1 中的数据传输到 table2,通过 trip_id 聚合并汇总里程并更新 table2 中的数据
我写了一个触发函数来获取列名和值
public Collection<Mutation> augment(Partition partition) {
HashMap map = new HashMap();
CFMetaData cfm = partition.metadata();
String tableName = cfm.cfName;
try {
UnfilteredRowIterator it = partition.unfilteredIterator();
while (it.hasNext()) {
Unfiltered un = it.next();
Clustering clt = (Clustering) un.clustering();
Iterator<Cell> cells = partition.getRow(clt).cells().iterator();
while(cells.hasNext()){
Cell cell = cells.next();
map.put(cell.column().name.toString(), cell.value().array());
...
}
}
} catch (Exception e) {
}
...
}
但是我怎样才能得到主键和主键的值呢?如果这些都无法获取,我该如何使用触发功能来完成这项工作?
【问题讨论】: