Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java/thrift删除超级列_Java_Cassandra_Thrift - Fatal编程技术网

如何使用java/thrift删除超级列

如何使用java/thrift删除超级列,java,cassandra,thrift,Java,Cassandra,Thrift,有谁能提供一个清晰的例子,说明如何使用thrift删除Java中的超级列 编辑:找到了一个解决方案,这允许我删除任何数量的超级列,我想在一批变异 List<Mutation> mutations = new ArrayList<Mutation>(); Map<String, List<Mutation>> keyMutations = new HashMap<String, List<Mutation>>(

有谁能提供一个清晰的例子,说明如何使用thrift删除Java中的超级列

编辑:找到了一个解决方案,这允许我删除任何数量的超级列,我想在一批变异

    List<Mutation> mutations = new ArrayList<Mutation>();
    Map<String, List<Mutation>> keyMutations = new HashMap<String, List<Mutation>>();
    Map<ByteBuffer, Map<String, List<Mutation>>> mutationsMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
    try {
        tr.open();
        client.set_keyspace("my_keyspace");

        Deletion deletion = new Deletion();
        SlicePredicate slicePredicate = new SlicePredicate();

        List<ByteBuffer> columns = new ArrayList<ByteBuffer>();

        // Add as many supercolumns as you want here 
        columns.add(toByteBuffer("supercolumn_name"));

        slicePredicate.setColumn_names(columns);
        deletion.setPredicate(slicePredicate);

        // timestamp in microseconds        
        deletion.setTimestamp(System.currentTimeMillis() * 1000);

        Mutation m = new Mutation();
        m.setDeletion(deletion);

        mutations.add(m);

        keyMutations.put("column_family_name", mutations);

        mutationsMap.put(toByteBuffer("row_id_in_column_family"), keyMutations);
        client.batch_mutate(mutationsMap, ConsistencyLevel.ONE);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
         tr.flush();
         tr.close();
    }
List<Mutation> mutations = new ArrayList<Mutation>();
Map<String, List<Mutation>> keyMutations = new HashMap<String, List<Mutation>>();
Map<ByteBuffer, Map<String, List<Mutation>>> mutationsMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
try {
    tr.open();
    client.set_keyspace("my_keyspace");

    Deletion deletion = new Deletion();
    SlicePredicate slicePredicate = new SlicePredicate();

    List<ByteBuffer> columns = new ArrayList<ByteBuffer>();

    // Add as many supercolumns as you want here 
    columns.add(toByteBuffer("supercolumn_name"));

    slicePredicate.setColumn_names(columns);
    deletion.setPredicate(slicePredicate);

    // timestamp in microseconds        
    deletion.setTimestamp(System.currentTimeMillis() * 1000);

    Mutation m = new Mutation();
    m.setDeletion(deletion);

    mutations.add(m);

    keyMutations.put("column_family_name", mutations);

    mutationsMap.put(toByteBuffer("row_id_in_column_family"), keyMutations);
    client.batch_mutate(mutationsMap, ConsistencyLevel.ONE);
} catch (Exception e) {
    e.printStackTrace();
} finally {
     tr.flush();
     tr.close();
}
List mutations=new ArrayList();
Map-keytrantations=newhashmap();
Map mutationsMap=新的HashMap();
试一试{
tr.open();
客户端。设置密钥空间(“我的密钥空间”);
删除=新删除();
SlicePredicate SlicePredicate=新的SlicePredicate();
列表列=新的ArrayList();
//在此处添加任意数量的超级柱
添加(toByteBuffer(“超级列名称”);
slicePredicate.setColumn_名称(列);
删除.setPredicate(slicePredicate);
//以微秒为单位的时间戳
删除.setTimestamp(System.currentTimeMillis()*1000);
突变m=新突变();
m、 设置删除(删除);
添加(m);
关键字突变。put(“列族名”,突变);
mutationsMap.put(toByteBuffer(“row\u id\u in\u column\u family”),键突变;
客户批量变异(变异图,一致性等级1);
}捕获(例外e){
e、 printStackTrace();
}最后{
tr.flush();
tr.close();
}

我不知道,我也用过原始的节俭,但你应该用更高的等级

Hector添加CF时的操作如下所示:

String KEYSPACE = "Keyspace";
Cluster cluster = getOrCreateCluster("MyCluster", "127.0.0.1:9170");
CfDef cfDef = new CfDef(KEYSPACE, "Users").setComparator_type(BytesType.class.getSimpleName()).setKey_cache_size(0)
            .setRow_cache_size(0).setGc_grace_seconds(86400));

try {
    cluster.addColumnFamily(new ThriftCfDef(cfDef));
} catch (Throwable e) {
    logger.error("Exception while creating CF, " + cfDef.getName()
        + " - probably already exists", e);
    }
}
下降更容易:

cluster.dropColumnFamily(KEYSPACE, "Users"); //with exceptions

找到了一个解决方案,这允许我删除任何数量的超级柱,我想在一个批次中进行变异

    List<Mutation> mutations = new ArrayList<Mutation>();
    Map<String, List<Mutation>> keyMutations = new HashMap<String, List<Mutation>>();
    Map<ByteBuffer, Map<String, List<Mutation>>> mutationsMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
    try {
        tr.open();
        client.set_keyspace("my_keyspace");

        Deletion deletion = new Deletion();
        SlicePredicate slicePredicate = new SlicePredicate();

        List<ByteBuffer> columns = new ArrayList<ByteBuffer>();

        // Add as many supercolumns as you want here 
        columns.add(toByteBuffer("supercolumn_name"));

        slicePredicate.setColumn_names(columns);
        deletion.setPredicate(slicePredicate);

        // timestamp in microseconds        
        deletion.setTimestamp(System.currentTimeMillis() * 1000);

        Mutation m = new Mutation();
        m.setDeletion(deletion);

        mutations.add(m);

        keyMutations.put("column_family_name", mutations);

        mutationsMap.put(toByteBuffer("row_id_in_column_family"), keyMutations);
        client.batch_mutate(mutationsMap, ConsistencyLevel.ONE);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
         tr.flush();
         tr.close();
    }
List<Mutation> mutations = new ArrayList<Mutation>();
Map<String, List<Mutation>> keyMutations = new HashMap<String, List<Mutation>>();
Map<ByteBuffer, Map<String, List<Mutation>>> mutationsMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
try {
    tr.open();
    client.set_keyspace("my_keyspace");

    Deletion deletion = new Deletion();
    SlicePredicate slicePredicate = new SlicePredicate();

    List<ByteBuffer> columns = new ArrayList<ByteBuffer>();

    // Add as many supercolumns as you want here 
    columns.add(toByteBuffer("supercolumn_name"));

    slicePredicate.setColumn_names(columns);
    deletion.setPredicate(slicePredicate);

    // timestamp in microseconds        
    deletion.setTimestamp(System.currentTimeMillis() * 1000);

    Mutation m = new Mutation();
    m.setDeletion(deletion);

    mutations.add(m);

    keyMutations.put("column_family_name", mutations);

    mutationsMap.put(toByteBuffer("row_id_in_column_family"), keyMutations);
    client.batch_mutate(mutationsMap, ConsistencyLevel.ONE);
} catch (Exception e) {
    e.printStackTrace();
} finally {
     tr.flush();
     tr.close();
}
List mutations=new ArrayList();
Map-keytrantations=newhashmap();
Map mutationsMap=新的HashMap();
试一试{
tr.open();
客户端。设置密钥空间(“我的密钥空间”);
删除=新删除();
SlicePredicate SlicePredicate=新的SlicePredicate();
列表列=新的ArrayList();
//在此处添加任意数量的超级柱
添加(toByteBuffer(“超级列名称”);
slicePredicate.setColumn_名称(列);
删除.setPredicate(slicePredicate);
//以微秒为单位的时间戳
删除.setTimestamp(System.currentTimeMillis()*1000);
突变m=新突变();
m、 设置删除(删除);
添加(m);
关键字突变。put(“列族名”,突变);
mutationsMap.put(toByteBuffer(“row\u id\u in\u column\u family”),键突变;
客户批量变异(变异图,一致性等级1);
}捕获(例外e){
e、 printStackTrace();
}最后{
tr.flush();
tr.close();
}

不幸的是,我一直在使用thrift,如果我能正确的话,我肯定会使用Hector。行删除不是thrift的问题,您的问题是如何删除列族?好的,刚才看到您的评论,在这种情况下,请这样做,所有其他客户机也会扩展thrift,因此使用thrift删除CF应该是可能的