google-cloud-ruby: Cloud Bigtable setCell timestamp field does not set timestamp on cell.

When setting the timestamp on a cell value, the timestamp is ignored. You can test this with the hello world

  entry = table.new_mutation_entry "greeting#{i}"
  entry.set_cell(
    column_family,
    column_qualifier,
    value,
    timestamp: Time.now.to_i * 1000
  )

  table.mutate_row entry

When I read the results, this is what I see:

greeting0
  cf:greeting                              @ 1970/01/18-21:16:13.999000
    "Hello World!"
----------------------------------------
greeting1
  cf:greeting                              @ 1970/01/18-21:16:14.000000
    "Hello Bigtable!"
----------------------------------------
greeting2
  cf:greeting                              @ 1970/01/18-21:16:14.000000
    "Hello Ruby!"

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I think the problem is that the example code is using milliseconds, but the table is likely configured for microseconds. The API’s Mutation.SetCell documentation states:

Values must match the granularity of the table (e.g. micros, millis).

So there seems to me to be a mismatch here. The example code is clearly using milliseconds, but the “granularity of the table” that the user is using is likely set to microseconds.

If you don’t want to change the table granularity, I would replace Time.now.to_i * 1000 with Time.now.to_i * 1000000, or the more accurate (t = Time.now; t.to_i * 1000000 + t.usec):

  entry.set_cell(
    column_family,
    column_qualifier,
    value,
    timestamp: (t = Time.now; t.to_i * 1000000 + t.usec)
  )