我使用下面的代码来提取cassandra触发器中的数据。我在cassandra表上创建了触发器。在表中插入新行时,将调用触发器。但是,单元格和列的大小为0。columns.next()返回false。有人能帮忙告诉我缺了什么吗?为什么单元格或列是空的。
我在本地服务器上使用apachecassandra3.11.3。
pom.xml文件:
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>3.11.3</version>
</dependency>
触发器类
public class TestTrigger implements ITrigger {
private static final Logger logger = LoggerFactory.getLogger(TestTrigger.class);
public Collection<Mutation> augment(Partition partition)
{
String tableName = partition.metadata().cfName;
logger.info("Table: " + tableName);
String topicname = null;
String type = null;
String subtype = null;
String id = "0";
int value = 0;
ByteBuffer partitionKeyValues = partition.partitionKey().getKey();
id = new String (partitionKeyValues.array());
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();
Iterator<ColumnDefinition> columns = partition.getRow(clt).columns().iterator();
while(columns.hasNext()){
....
}
}
} catch (Exception e) {
}
return Collections.emptyList();
}
}
架构和触发器详细信息
CREATE KEYSPACE test_keyspace WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1': '1'} AND durable_writes = true;
CREATE TABLE test_keyspace.test_table (
f1 text,
f2 text,
f3 int,
f4 text,
f5 text,
f6 double,
PRIMARY KEY ((f1, f2, f3), f4, f5)
) WITH CLUSTERING ORDER BY (f4 ASC, f5 ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';
create trigger test_trigger ON test_keyspace.test_table USING 'com.test.TestTrigger';
插入查询
insert into test_keyspace.test_table(f1, f2, f3, f4, f5, f6) values('test1','test',1, 'test','test',null);
谢谢
暂无答案!
目前还没有任何答案,快来回答吧!