我正在尝试使用CLI工具cbt
或Python API解码来自Google Cloud BigTable的响应。我对cbt
使用这个命令只是从表
cbt read <table-name> count=1
返回不可读的二进制数据。
Python API
building_table_row = building_table.scan(limit= 1)
返回类似的响应:
p:pattern @ 2021/08/20-20:58:10.519000
NPYx00px14jx11streak-accuraciesnx04dx01dx01x00x00jrmin-drawdownsnx047=xbffxaf$xf1xf3ix0077jngain-ratesnx04=?x8fxadxc5xf3x05xdex00=?x8fxadxc5xf3x05xdex0077jx15extended-sharpe-ratio=?xf6%xd1xefhxa5xf7jrmax-drawdownsnx047=?x9ex0fx8fxe7nxa8@77jadates-rrq+x00x00x01jxfbxbcx90x00+x00x00x01jxfbxbcx90x00q+x00x00x01rSmxbcx00+x00x00x01rSmxbcx00q+x00x00x01yxabx1exe8x00+x00x00x01yxabx1exe8x00jagainsesnx04r=?x91u007fx0exd9xeax00@=?Qx1fsx85xd80x00=?x9cxf3xa2xdaAIxc0r=?x91u007fx0exd9xeax00@=?Qx1fsx85xd80x00=?x9cxf3xa2xdaAIxc0r777r777jx06symbolibSPGSAL.Xjx12extended-gain-rate=?x8fxadxc5xf3x05xdex00jfsharpe-ratio=?xf6%xd1xefhxa5xf7jx04partqdx05dx1bjx0fpartition-countdx03jx04year*x00x00axe5jx0faverage-move-up=?x8fxadxc5xf3x05xdex00jx18extended-streak-accuracydx01jastd-dev7jx11average-move-downx00jvsd-of-gains=?x86⬷rxd5fjx06rating7jrstreak-lengthdx01"
我尝试用row.decode('utf-8')
解码,这不起作用。
如何解码来自BigTable的响应?
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);
}
好运