Je suis en train de créer une base de données, mais cassandra peu importe quelles versions de cassandra et hector J'utilise Je continue à obtenir l'erreur suivante:Cassandra-Hector: java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB
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/:?]
Voici mon Code:
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();
}
}
}
Est-ce que quelqu'un sait comment puis-je résoudre ce problème?
Je suis actuellement en utilisant la version 0.8.0-2 et de cassandra 1.2.5 de hector
Merci à l'avance de
Il ne devrait pas y avoir de raison d'écrire quoi que ce soit dans Hector, car il est depuis longtemps obsolète. Le projet Hector sur GitHub n'a pas eu d'engagement depuis presque 2 ans, et son readme dit même qu'il ne devrait plus être utilisé. Vos meilleures chances de succès seront d'utiliser Cassandra 2.1.14 avec le pilote DataStax Java. – Aaron