Crates.io | bigtable |
lib.rs | bigtable |
version | 0.5.0 |
source | src |
created_at | 2017-01-06 23:48:12.817653 |
updated_at | 2019-12-09 14:03:32.563806 |
description | Lib for interfacing with Google BigTable Data API |
homepage | |
repository | https://github.com/durch/rust-bigtable |
max_upload_size | |
id | 7963 |
size | 537,213 |
Rust library for working with Google Bigtable Data API
Interface towards Cloud Bigtable, supports all Data API methods.
Includes support for JWT auth:
Initial plans was to go full grpc
over http/2
, unfortunately Rust support is not there yet, so a middle way was taken :).
Requests objects are protobuf
messages, generated using proto
definitions available from Google. And all configuration is done through very nice interfaces generated in this way. These messages are then transparently converted to json
, and sent to predefined google.api.http
endpoints, also defined here. Responses are returned as serde_json::Value.
In theory this should enable easy upgrade to full grpc
over http/2
as soon as it becomes viable, the only remaining work would be utilising proper return types, also available as protobuf
messages.
You can provide the json
service accounts credentials obtained from Google Cloud Console or the private key file in pem
or (see random_rsa_for_testing for proper format) format as well as Google Cloud service account with proper scopes (scopes are handled by goauth, as part of authentication),
In your Cargo.toml
[dependencies]
bigtable = '0.3'
wraps
)There and higher wrappers available for reading and writing rows, so there is not need to craft protobufs
manually. Write can also be used to update, but not very robustly yet, coming soon :).
Read wrappers allows for simple limit on the number of rows, it uses the ReadRows
underlying method.
There are two write strategies available, bulk_write_rows
and write_rows
. bulk_write_rows
first collects all writes and fires only one request, underlying method is MutateRows
, this results in a much higher write throughput. write_rows
shoots one request per row to be written, underlying method is ReadModifyWriteRow
.
extern crate bigtable as bt;
use bt::utils::*;
use bt::wraps;
const TOKEN_URL: &'static str = "https://www.googleapis.com/oauth2/v4/token";
const ISS: &'static str = "some-service-account@developer.gserviceaccount.com";
const PK: &'static str = "pk_for_the_acc_above.pem";
fn read_rows(limit: i64) -> Result<(serde_json::Value), BTErr> {
let token = get_auth_token(TOKEN_URL, ISS, PK)?;
let table = Default::default();
wraps::read_rows(table, &token, Some(limit))
}
fn write_rows(n: usize, bulk: bool) -> Result<(), BTErr> {
let mut rows: Vec<wraps::Row> = vec!(wraps::Row::default()); // put some real data here
let token = get_auth_token(TOKEN_URL, ISS, PK)?;
let table = Default::default(); // Again use a real table here
if bulk {
let _ = wraps::bulk_write_rows(&mut rows, &token, table);
} else {
let _ = wraps::write_rows(&mut rows, &token, table);
}
Ok(())
}