3

倹約を使用してJavaでスーパーカラムを削除する方法の明確な例を誰かが提供できますか?

編集:解決策が見つかりました。これにより、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();
    }
4

2 に答える 2

2

わかりません。生のThriftも使用しましたが、より高いレベルのクライアントを使用する必要があります

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

ドキュメンテーション

于 2012-06-14T09:09:34.603 に答える
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();
}
于 2012-06-14T18:53:07.617 に答える