我正在尝试创建cassandra数据库,但是无论我使用哪些版本的cassandra和hector,我都会得到以下错误:
java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB
at me.prettyprint.cassandra.service.ThriftCfDef.<init>(ThriftCfDef.java:119) ~[hector-core-0.8.0-2.jar:?]
at me.prettyprint.cassandra.service.ThriftCfDef.<init>(ThriftCfDef.java:125) ~[hector-core-0.8.0-2.jar:?]
at me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition(HFactory.java:679) ~[hector-core-0.8.0-2.jar:?]
at Databases.NoSQL.CassandraDB.AuthorsAndFeaturesCassandraSchema.writeAuthorsAndFeaturesPerKeywordToCassandraDB(AuthorsAndFeaturesCassandraSchema.java:87) ~[classes/:?]这是我的密码:
public class AuthorsAndFeaturesCassandraSchema {
public static StringSerializer stringSerializer=new StringSerializer();
public static String[] readAuthorsAndFeaturesPerKeywordFromCassandraDB(){
CassandraHostConfigurator hostConfigurator=new CassandraHostConfigurator("localhost:9160");
Cluster cluster= HFactory.getOrCreateCluster("TestCluster","localhost:9160");
KeyspaceDefinition keyspaceDefinition=cluster.describeKeyspace("authorAndFeaturesKeyspace");
if(cluster.describeKeyspace("authorAndFeaturesKeyspace")==null){
ColumnFamilyDefinition columnFamilyDefinition=HFactory.createColumnFamilyDefinition("authorAndFeaturesKeyspace","authorAndFeaturesKeyword", ComparatorType.BYTESTYPE);
KeyspaceDefinition keyspaceDefinition1=HFactory.createKeyspaceDefinition("authorAndFeaturesKeyspace", ThriftKsDef.DEF_STRATEGY_CLASS,1, Arrays.asList(columnFamilyDefinition));
cluster.addKeyspace(keyspaceDefinition1,true);
}
ConfigurableConsistencyLevel configurableConsistencyLevel=new ConfigurableConsistencyLevel();
Map<String,HConsistencyLevel> consistencyLevelMap=new HashMap<String, HConsistencyLevel>();
consistencyLevelMap.put("AUTHOR_AND_FEATURES",HConsistencyLevel.ONE);
configurableConsistencyLevel.setReadCfConsistencyLevels(consistencyLevelMap);
configurableConsistencyLevel.setWriteCfConsistencyLevels(consistencyLevelMap);
me.prettyprint.hector.api.Keyspace keyspace=HFactory.createKeyspace("authorAndFeaturesKeyspace",cluster,configurableConsistencyLevel);
String[] serializedauthorsAndFeaturesHashmap=new String[3],authorsAndFeatures={"authorAndFeaturesKeyword-1","authorAndFeaturesKeyword-2","authorAndFeaturesKeyword-3"};
try {
ColumnQuery<String,String,String> columnQuery=HFactory.createStringColumnQuery(keyspace);
for(int i=1;i<=authorsAndFeatures.length;i++){
columnQuery.setColumnFamily("AUTHOR_AND_FEATURES").setKey("authorsAndFeaturesKeyword").setName(authorsAndFeatures[i]);
QueryResult<HColumn<String,String>>result=columnQuery.execute();
if(result==null){
return null;
}
HColumn<String,String>column=result.get();
if(column==null){
return null;
}
serializedauthorsAndFeaturesHashmap[i]=column.getValue();
}
}catch (HectorException e){
e.printStackTrace();
}
return serializedauthorsAndFeaturesHashmap;
}
public static void writeAuthorsAndFeaturesPerKeywordToCassandraDB( String serializedAuthorsAndFeaturesPerKeywordHashmap,int index){
CassandraHostConfigurator hostConfigurator=new CassandraHostConfigurator("localhost:9160");
Cluster cluster=HFactory.getOrCreateCluster("TestCluster","localhost:9160");
ConfigurableConsistencyLevel configurableConsistencyLevel=new ConfigurableConsistencyLevel();
Map<String,HConsistencyLevel>consistencyLevelMap=new HashMap<String, HConsistencyLevel>();
consistencyLevelMap.put("AUTHOR_AND_FEATURES",HConsistencyLevel.ONE);
configurableConsistencyLevel.setReadCfConsistencyLevels(consistencyLevelMap);
configurableConsistencyLevel.setWriteCfConsistencyLevels(consistencyLevelMap);
KeyspaceDefinition keyspaceDefinition=cluster.describeKeyspace("authorAndFeaturesKeyspace");
if(cluster.describeKeyspace("authorAndFeaturesKeyspace")==null){
ColumnFamilyDefinition columnFamilyDefinition=HFactory.createColumnFamilyDefinition("authorAndFeaturesKeyspace","authorAndFeaturesKeyword",ComparatorType.BYTESTYPE);
KeyspaceDefinition keyspaceDefinition1=HFactory.createKeyspaceDefinition("authorAndFeaturesKeyspace",ThriftKsDef.DEF_STRATEGY_CLASS,1,Arrays.asList(columnFamilyDefinition));
cluster.addKeyspace(keyspaceDefinition1,true);
}
me.prettyprint.hector.api.Keyspace keyspace=HFactory.createKeyspace("authorAndFeaturesKeyspace",cluster,configurableConsistencyLevel);
Mutator<String>mutator=HFactory.createMutator(keyspace,StringSerializer.get());
try {
mutator.insert("authorAndFeaturesKeyword","AUTHOR_AND_FEATURES",HFactory.createStringColumn("authorAndFeaturesKeyword-"+index,serializedAuthorsAndFeaturesPerKeywordHashmap));
}catch (HectorException e){
e.printStackTrace();
}
}}
有人知道我该怎么修吗?
我目前使用的是hector的0.8.0-2和cassandra的1.2.5版本
提前感谢
发布于 2016-06-23 02:28:12
这很可能是因为您使用的是不兼容版本的Hector和Cassandra。您应该使用Hector 1.0-5和Cassandra1.2.5。
https://stackoverflow.com/questions/37981255
复制相似问题