Decoding BInary Data from BigTable

521 Views Asked by At

I am tying to decode responses from Google Cloud BigTable using either the CLI tool cbt or the Python API. I am using this command with cbt to just read one row from the table

cbt read <table-name> count=1 

which is returning binary data which is not readable.

This query with the Python API

building_table_row = building_table.scan(limit= 1)

is returning a similar response:

p:pattern                                @ 2021/08/20-20:58:10.519000
    
NPY\x00p\x14j\x11streak-accuraciesn\x04d\x01d\x01\x00\x00j\rmin-drawdownsn\x047=\xbff\xaf$\xf1\xf3i\x0077j\ngain-ratesn\x04=?\x8f\xad\xc5\xf3\x05\xde\x00=?\x8f\xad\xc5\xf3\x05\xde\x0077j\x15extended-sharpe-ratio=?\xf6%\xd1\xefh\xa5\xf7j\rmax-drawdownsn\x047=?\x9e\x0f\x8f\xe7n\xa8@77j\adates-rrq+\x00\x00\x01j\xfb\xbc\x90\x00+\x00\x00\x01j\xfb\xbc\x90\x00q+\x00\x00\x01rSm\xbc\x00+\x00\x00\x01rSm\xbc\x00q+\x00\x00\x01y\xab\x1e\xe8\x00+\x00\x00\x01y\xab\x1e\xe8\x00j\againsesn\x04r=?\x91\u007f\x0e\xd9\xea\x00@=?Q\x1fs\x85\xd80\x00=?\x9c\xf3\xa2\xdaAI\xc0r=?\x91\u007f\x0e\xd9\xea\x00@=?Q\x1fs\x85\xd80\x00=?\x9c\xf3\xa2\xdaAI\xc0r777r777j\x06symboli\bSPGSAL.Xj\x12extended-gain-rate=?\x8f\xad\xc5\xf3\x05\xde\x00j\fsharpe-ratio=?\xf6%\xd1\xefh\xa5\xf7j\x04partqd\x05d\x1bj\x0fpartition-countd\x03j\x04year*\x00\x00\a\xe5j\x0faverage-move-up=?\x8f\xad\xc5\xf3\x05\xde\x00j\x18extended-streak-accuracyd\x01j\astd-dev7j\x11average-move-down\x00j\vsd-of-gains=?\x86⬷r\xd5fj\x06rating7j\rstreak-lengthd\x01"

I tried decoding with row.decode('utf-8') and this did not work.

How can I decode the response from BigTable?

1

There are 1 best solutions below

0
On
for (Row row : rows) { // here you have rows from bigtable
        finalList.addAll(row.getCells(COLUMN_FAMILY, COLUMN_QUALIFIER).stream()
                                .map(rowCell -> GsonUtility.JAVA_BASED_GSON.fromJson(rowCell.getValue().toStringUtf8(), MyObject.class)) // converting binery cell data to MyObject
                                .collect(Collectors.toList())); // collect objects as list
           }
            
            
        // here is util for converting to Object    
    ublic <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException {
        Object object = this.fromJson((String)json, (Type)classOfT);
        return Primitives.wrap(classOfT).cast(object);
    }

Good Luck