1
我試圖使用hector api將數據插入到cassandra數據庫中。我使用的代碼顯示如下。使用hector將數據插入到Cassandra中
<i>
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import java.util.UUID;
public class HectorAPI {
private static final String USER="data";
public static void main(String[] args) throws Exception{
StringSerializer ss = StringSerializer.get();
Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "127.0.0.1:9160");
Keyspace keyspace = HFactory.createKeyspace("myKeySpace", cluster);
String id = UUID.randomUUID().toString();
Mutator<String> mutator = HFactory.createMutator(keyspace, ss);
mutator.addInsertion(id, USER, HFactory.createStringColumn("full_name", "John"))
.addInsertion(id, USER, HFactory.createStringColumn("email", "test"))
.addInsertion(id, USER, HFactory.createStringColumn("state","yfcy"))
.addInsertion(id, USER, HFactory.createStringColumn("gender", "male"))
.addInsertion(id, USER, HFactory.createStringColumn("birth_year", "1990"));
mutator.execute();
}
}
但無法找到任何插入的數據在/ var給定的密鑰空間下的/ lib目錄/卡桑德拉/ data文件夾。好像數據插入不能正常工作。代碼有什麼問題。下面顯示了我用來創建「數據」列族的命令。
CREATE COLUMN FAMILY data
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: full_name, validation_class: UTF8Type}
{column_name: email, validation_class: UTF8Type}
{column_name: state, validation_class: UTF8Type, index_type: KEYS}
{column_name: gender, validation_class: UTF8Type}
{column_name: birth_year, validation_class: UTF8Type, index_type: KEYS}
];
而不是檢查插入到文件夾中的數據,檢查從cassandra cli插入的數據或使用CQL,爲您的UUID。 –