我是 Cassandra 的新手,我需要它来完成一项快速而小型的临时工作。但是,我遇到了一个问题。我有一个使用下面的 CQL 创建的列族:
创建表 dummy_file_test ( dtPtn INT, pxID 整数, startTm INT, endTm INT, patID BIGINT, 电子文件 BLOB, 主键(dtPtn,pxID,startTm) );
我编写了以下方法将数据插入表中。
public static void insertDataKey(HashMap nameValuePair, String colFamily) {
try {
Cluster cluster = HFactory.getOrCreateCluster(clusterName, hostPort);
Keyspace keyspace = HFactory.createKeyspace(CASSANDRA_DUMMY_KEY_SPACE, cluster);
Integer dtPtn = (Integer)nameValuePair.get("dtPtn");
Integer pxID = (Integer)nameValuePair.get("pxID");
Integer startTm = (Integer)nameValuePair.get("startTm");
Integer endTm = (Integer)nameValuePair.get("endTm");
Long patID = (Long)nameValuePair.get("patID");
byte[] efile = (byte[])nameValuePair.get("efile");
HColumn<String, Integer> column1 = HFactory.createColumn("dtPtn", dtPtn, new StringSerializer(), IntegerSerializer.get());
HColumn<String, Integer> column2 = HFactory.createColumn("pxID", pxID, new StringSerializer(), IntegerSerializer.get());
HColumn<String, Integer> column3 = HFactory.createColumn("startTm", startTm, new StringSerializer(), IntegerSerializer.get());
HColumn<String, Integer> column4 = HFactory.createColumn("endTm", endTm, new StringSerializer(), IntegerSerializer.get());
HColumn<String, Long> column5 = HFactory.createColumn("patID", patID, new StringSerializer(), LongSerializer.get());
HColumn<String, byte[]> column6 = HFactory.createColumn("efile", efile, new StringSerializer(), BytesArraySerializer.get());
Composite rowKey = new Composite();
rowKey.addComponent("dtPtn", StringSerializer.get());
rowKey.addComponent(dtPtn, IntegerSerializer.get());
rowKey.addComponent("pxID", StringSerializer.get());
rowKey.addComponent(pxID, IntegerSerializer.get());
rowKey.addComponent("startTm", StringSerializer.get());
rowKey.addComponent(startTm, IntegerSerializer.get());
Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
mutator.addInsertion(rowKey, colFamily, column1);
mutator.addInsertion(rowKey, colFamily, column2);
mutator.addInsertion(rowKey, colFamily, column3);
mutator.addInsertion(rowKey, colFamily, column4);
mutator.addInsertion(rowKey, colFamily, column5);
mutator.addInsertion(rowKey, colFamily, column6);
mutator.execute();
} catch (Exception ex) {
ex.printStackTrace();
}
}
但是,当我运行代码时,我得到
InvalidRequestException(为什么:预期 4 或 0 字节 int (21))
我对 Hector API 很困惑,找不到任何我可以完全依赖的完整教程/材料。解决上述问题的任何建议都会有很大帮助。
提前致谢。
ps:我在 Cassandra 1.2