Update data

Hypertable extends the traditional two-dimensional table model by adding a timestamp dimension. This timestamp dimension can be thought of as representing different versions of each table cell. Updating s cell  is nothing else than inserting a new cell which creates a new cell revision. When queried, the most recent cell version is returned first.  By default, all cell versions are retained for each column, but the number of versions retained can be capped by specifying the MAX_VERSIONS and/or the TTL option to the column specification in the table schema.

 

Obtain a ITableMutator from a ITable interface to create new cell versions, for example:

using (var mutator = table.CreateMutator())
   
   // Create a new cell
   var key = new Key("row") { ColumnFamily = "name" };   
   byte[] value = ...;
   mutator.Set(key, value);
   mutator.Flush();

   // Query the newly created cell
   var scanSpec = new ScanSpec(key.Row).AddColumn("name");
   using (var scanner = table.CreateScanner(scanSpec)) {
      Cell cell;
      scanner.Next(out cell));
   }

   // Create a new cell revision
   byte[] newValue = ...;
   mutator.Set(key, newValue);
   mutator.Flush();

   // Query all cell revisions
   using (var scanner = table.CreateScanner(scanSpec)) {
      Cell newCell;
      scanner.Next(out newCell));
      
      Cell oldCell;
      scanner.Next(out oldCell));
   }

   // Or query only the most recent cell revision
   scanSpec.MaxVersions = 1;
   using (var scanner = table.CreateScanner(scanSpec)) {
      Cell recentCell;
      scanner.Next(out recentCell));
   }
}

 

Hypertable allows you to update a specific cell revision as well, for example:

using (var mutator = table.CreateMutator())
   
   // Create a new cell
   var key = new Key("row") { ColumnFamily = "name" };   
   byte[] value = ...;
   mutator.Set(key, value);
   mutator.Flush();

   // Query the newly created cell
   Cell cell;
   var scanSpec = new ScanSpec(key.Row).AddColumn("name");
   using (var scanner = table.CreateScanner(scanSpec)) {
      scanner.Next(out cell));
   }

   // Update this specific cell revision
   byte[] newValue = ...;
   cell.Value = newValue;
   mutator.Set(cell);
}