我正在尝试使用 hector api 将数据插入到 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();
}
}
但是在给定 KeySpace 下的 /var/lib/cassandra/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}
];