2015-10-18 67 views
2

我在單個鍵空間中有兩個列族。這些列族具有相同的模式和數據。當在第一個列上執行刪除操作時,我想要刪除具有相同主鍵的第二行。 這是我曾嘗試在ITrigger擴充方法如何使用cassandra觸發器執行刪除操作?

@Override 
public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) { 
    List<Mutation> mutations = new ArrayList<>(update.getColumnCount()); 
    String indexKeySpace = properties.getProperty("keyspace"); 
    String indexColumnFamily = properties.getProperty("table"); 
    if (!update.deletionInfo().isLive()) { 
     Mutation mutation = new Mutation(indexKeySpace, key); 
     mutation.delete(indexColumnFamily, System.currentTimeMillis()); 
     mutations.add(mutation); 
    } 
    return mutations; 
} 

回答

3

我解決它:d
這裏是工作的代碼

@Override 
public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) { 
    List<Mutation> mutations = new ArrayList<>(update.getColumnCount()); 
    String indexKeySpace = properties.getProperty("keyspace"); 
    String indexColumnFamily = properties.getProperty("table"); 
    if (!update.deletionInfo().isLive()) { 
     CFMetaData cfMetaData = Schema.instance.getCFMetaData(indexKeySpace, indexColumnFamily); 
     for (ColumnDefinition columnDefinition : cfMetaData.allColumns()) { 
      Mutation mutation = new Mutation(indexKeySpace, key); 
      mutation.delete(indexColumnFamily, CellNames.simpleSparse(columnDefinition.name), System.currentTimeMillis()); 
      mutations.add(mutation); 
     } 
    } 
    return mutations; 
} 
相關問題