2015-09-30 209 views
3

我正在瀏覽cassandra中的觸發器實現。 我想實現觸發器,以便更新一個已經修改過的表的舊值的表。 假設我有一個表,說key.space中的test_table keyspace1。 我也有一個表,說column_track在同一個鍵空間與列的列名和列值。 現在,當在test_table中更新一行時,我想用行數據(在執行更新查詢之前的test_table中)分別填充到列的columnname和columnvalue的track_table中。Cassandra觸發器在更新另一個表時更新表格

我找不到有關cassandra觸發器的任何適當的文檔。 我設法以某種方式實現倒排索引和一些小的例子

public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) 
{ 
    List<Mutation> mutations = new ArrayList<Mutation>(update.getColumnCount()); 

    for (Cell cell : update) 
    { 
     // Skip the row marker and other empty values, since they lead to an empty key. 
     if (cell.value().remaining() > 0) 
     { 
      Mutation mutation = new Mutation(properties.getProperty("keyspace"), cell.value()); 
      mutation.add(properties.getProperty("columnfamily"), cell.name(), key, System.currentTimeMillis()); 
      mutations.add(mutation); 
     } 
    } 

    return mutations; 
} 

我怎麼能修改擴充的方法來實現該功能。 TNX

回答

0

您正在使用錯誤的鍵創建突變例如
這裏是工作的代碼

public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) 
{  
    List<Mutation> mutations = new ArrayList<Mutation>(update.getColumnCount()); 

    for (Cell cell : update) 
    { 
     if (cell.value().remaining() > 0) 
     { 
      Mutation mutation = new Mutation(properties.getProperty("keyspace"), key); 
      mutation.add(properties.getProperty("columnfamily"), cell.name(), cell.value(), System.currentTimeMillis()); 
      mutations.add(mutation); 
     } 
    } 
    return mutations; 
} 
相關問題