sessionInfo.setSessionId((Long) body.get("SessionId"));
return sessionInfo.build();
}
protected QueryResult createQueryResult(BSONObject bsonBody) {
Builder queryResult = QueryResult.newBuilder();
queryResult.setInsertId((Long) bsonBody.get("InsertId"));
BSONObject fields = (BSONObject) bsonBody.get("Fields");
for (String index : fields.keySet()) {
BSONObject field = (BSONObject) fields.get(index);
queryResult.addFields(
Field.newBuilder()
.setName(new String((byte[]) field.get("Name"), StandardCharsets.UTF_8))
.setType(Type.valueOf(Ints.checkedCast((Long) field.get("Type"))))
.build()
);
}
BSONObject rows = (BSONObject) bsonBody.get("Rows");
for (String rowIndex : rows.keySet()) {
BSONObject bsonRow = (BSONObject) rows.get(rowIndex);
Row.Builder queryRow = Row.newBuilder();
for (String cellIndex : bsonRow.keySet()) {
queryRow.addValues(Cell.newBuilder()
.setValue(ByteString.copyFrom((byte[]) bsonRow.get(cellIndex))));
}
queryResult.addRows(queryRow);
}
queryResult.setRowsAffected((Long) bsonBody.get("RowsAffected"));
return queryResult.build();
}