有人能提供一个明确的例子,说明如何使用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();
}
答案 0 :(得分:2)
我不知道,我也使用了原始Thrift,但你应该使用更高级别client
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
答案 1 :(得分:1)
找到一个解决方案,这允许我在一个批处理变异中删除任何数量的超级列。
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();
}