command-linebigtablegoogle-cloud-bigtable

How to format a byte string to set a value with cbt set (cloud bigtable command line tool)?


I have a field in Bigtable storing a timestamp. Using cbt lookup, the field displays like this "\x00\x00\x01d\x865W\x00"

This bytestring converts to an integer, for example via Python.

int.from_bytes(b"\x00\x00\x01d\x865W\x00",'big')
1531260000000

1531260000000 is a unix timestamp in microseconds. Converting to a human-readable format gives 2018-07-10T22:00:00+00:00

How can we update this field to a different timestamp using cbt?

From the docs we get the command

cbt set <table> <row> family:column=val

But how should the value be formatted to store it correctly?

I've tried cbt set mytable row1 family:timestamp=1531260000000, but then cbt lookup displays it as 1531260000000, not as a bytestring, and BigQuery does not display it at all, failing because the format is wrong.

I've also tried tried cbt set mytable row1 family:timestamp="\x00\x00\x01d\x865W\x00", but then cbt lookup displays the bytestring with escaped backslashes, which also does not work: "\\x00\\x00\\x01d\\x865W\\x00"

I looked in the source code for cbt but I'm not familiar enough with Go to figure it out from there.


Solution

  • According to this issue, you are not able to pass arbitrary bytes with cbt. The timestamp you provided is handled like a string by cbt, that's why it is escaped.