首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hector + Cassandra:获取列族列表

Hector + Cassandra:获取列族列表
EN

Stack Overflow用户
提问于 2011-08-25 06:56:31
回答 1查看 3.5K关注 0票数 1

我正在尝试获取我正在使用的当前键空间中的所有列族,因为我想消除错误:

InvalidRequestException(why:[column family] already exists in keyspace)

我的逻辑是获取当前键空间中的所有列族&检查返回的列表中是否出现特定的列族。所以,我试着:

KeyspaceDefinition keyspaceDef = HFactory.createKeyspaceDefinition("test");

..。

List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();

似乎在创建

List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();

我执行了一个System.out.println(keyspaceDef.getCfDefs()),它返回了

[]

一个空的列表--这是我所期望的。我不明白的是为什么List<ColumnFamilyDefinition> lsCf = keyspaceDef.getCfDefs();是不正确的。Eclipse不同意这一行的"List“部分。除此之外,看起来他的代码是正确的。有没有人能告诉我为什么这条线是错的,或者我的方法是不是错了?

下面是完整的代码片段:

代码语言:javascript
复制
package org.cassandra.examples;

import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.service.CassandraHostConfigurator;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.cassandra.service.ThriftCluster;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.*;
import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.model.thrift.ThriftConverter;

import org.apache.cassandra.db.ColumnFamily;
import org.apache.cassandra.thrift.Cassandra;
import me.prettyprint.cassandra.service.ThriftKsDef;
import me.prettyprint.hector.api.*;
import me.prettyprint.hector.api.beans.HColumn;
import me.prettyprint.hector.api.beans.HSuperColumn;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.cassandra.service.template.ColumnFamilyTemplate;
import me.prettyprint.cassandra.service.template.ColumnFamilyUpdater;
import me.prettyprint.cassandra.service.template.ThriftColumnFamilyTemplate;
import me.prettyprint.hector.api.mutation.Mutator;
import me.prettyprint.hector.api.query.ColumnQuery;
import me.prettyprint.hector.api.query.QueryResult;
import me.prettyprint.hector.api.query.SuperColumnQuery;

public class HectorTest {
    private static String keyspaceName = "test3";
    private static KeyspaceDefinition newKeyspaceDef;
    private static Cluster cluster;
    private static Keyspace ksp;

    public static void main(String[] args) {

        cluster = HFactory.getOrCreateCluster("test cluster", "xxx.xxx.x.xx:9160");
        newKeyspaceDef = HFactory.createKeyspaceDefinition(keyspaceName);
        ColumnFamilyDefinition cfDef = HFactory.createColumnFamilyDefinition("MyKeyspace",                              
                "ColumnFamilyName", 
                ComparatorType.BYTESTYPE);
        List<ColumnFamilyDefinition> lCf = newKeyspaceDef.getCfDefs(); //= new ArrayList<ColumnFamilyDefinition>();
        if((cluster.describeKeyspace(keyspaceName)) == null){
            createSchema();
        }

        ksp = HFactory.createKeyspace(keyspaceName, cluster);
        //Articles art = new Articles(cluster, newKeyspaceDef);
        //cluster.dropColumnFamily(keyspaceName, "Articles");


    }

    public static void createSchema(){
        cluster.addKeyspace(newKeyspaceDef,true);
    }
}

错误:

代码语言:javascript
复制
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    List cannot be resolved to a type

    at org.cassandra.examples.HectorTest.main(HectorTest.java:55)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-25 22:45:04

添加

代码语言:javascript
复制
import java.util.List; 

为了你的进口。在eclipse中,CTRL-SHIFT-O将为您组织导入,并添加任何缺少的内容。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7183305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档