Cassandra-Hector: java.lang.NoSuchFieldError: DEFAULT_MEMTABLE_THROUGHPUT_IN_MB

979 Views Asked by At

I'm trying to create a cassandra database but no matter what versions of cassandra and hector I use I keep getting the following error:

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/:?]

Here's my 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();
    }
}

}

Does anyone know how can I fix it?

I'm currently using hector's 0.8.0-2 and cassandra's 1.2.5 version

Thanks in advance

1

There are 1 best solutions below

0
ck1 On

This is happening most likely because you're using incompatible versions of Hector and Cassandra. You should use Hector 1.0-5 with Cassandra 1.2.5.