Ihor M.
Ihor M.

Reputation: 3148

How to retrieve row's last modification timestamp in HBase?

Does each Cell in returned Result object have same timestamp? Is it save to do something like this?

  try (Table table = connectionFactory.getConnection().getTable(TABLE)) {
   try (ResultScanner scanner = table.getScanner(generateScan(systemId))) {
    for (Result result: scanner) {
     if (result == null) {
      break;
     }
     long ts = result.rawCells()[0].getTimestamp();
     System.out.println("Row last update time: " + ts);
    }
   }
  }

Will I obtain time stamp of the last row modification?

Upvotes: 0

Views: 1283

Answers (1)

AdamSkywalker
AdamSkywalker

Reputation: 11609

Cells in Result can have different timestamp. Each cell is a combination of CF:C:V, where CF is column family, C is a column and V is a version. Even if you store only 1 version, you can update columns of a cell independently. Cell timestamp is updated when you store something.

For example you have table user with cf:main and two columns name and age. If you update both columns in same Put they will have same timetamp. If you update only name column, timestamps will be different. So generally it depends on your usage pattern.

Upvotes: 1

Related Questions