Module bigtable_rs::bigtable
source · Expand description
bigtable
module provides a few convenient structs for calling Google Bigtable from Rust code.
Example usage:
use bigtable_rs::bigtable;
use bigtable_rs::google::bigtable::v2::row_filter::{Chain, Filter};
use bigtable_rs::google::bigtable::v2::row_range::{EndKey, StartKey};
use bigtable_rs::google::bigtable::v2::{ReadRowsRequest, RowFilter, RowRange, RowSet};
use env_logger;
use std::error::Error;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
let project_id = "project-1";
let instance_name = "instance-1";
let table_name = "table-1";
let channel_size = 4;
let timeout = Duration::from_secs(10);
let key_start: String = "key1".to_owned();
let key_end: String = "key4".to_owned();
// make a bigtable client
let connection = bigtable::BigTableConnection::new(
project_id,
instance_name,
true,
channel_size,
Some(timeout),
)
.await?;
let mut bigtable = connection.client();
// prepare a ReadRowsRequest
let request = ReadRowsRequest {
app_profile_id: "default".to_owned(),
table_name: bigtable.get_full_table_name(table_name),
rows_limit: 10,
rows: Some(RowSet {
row_keys: vec![], // use this field to put keys for reading specific rows
row_ranges: vec![RowRange {
start_key: Some(StartKey::StartKeyClosed(key_start.into_bytes())),
end_key: Some(EndKey::EndKeyOpen(key_end.into_bytes())),
}],
}),
filter: Some(RowFilter {
filter: Some(Filter::Chain(Chain {
filters: vec![
RowFilter {
filter: Some(Filter::FamilyNameRegexFilter("cf1".to_owned())),
},
RowFilter {
filter: Some(Filter::ColumnQualifierRegexFilter("c1".as_bytes().to_vec())),
},
RowFilter {
filter: Some(Filter::CellsPerColumnLimitFilter(1)),
},
],
})),
}),
..ReadRowsRequest::default()
};
// calling bigtable API to get results
let response = bigtable.read_rows(request).await?;
// simply print results for example usage
response.into_iter().for_each(|(key, data)| {
println!("------------\n{}", String::from_utf8(key.clone()).unwrap());
data.into_iter().for_each(|row_cell| {
println!(
" [{}:{}] \"{}\" @ {}",
row_cell.family_name,
String::from_utf8(row_cell.qualifier).unwrap(),
String::from_utf8(row_cell.value).unwrap(),
row_cell.timestamp_micros
)
})
});
Ok(())
}
Modules§
Structs§
- The core struct for Bigtable client, which wraps a gPRC client defined by Bigtable proto. In order to easily use this struct in multiple threads, we only store cloneable references here.
BigtableClient<AuthSvc>
is a type alias ofBigtableClient
and it wraps a tonic Channel. Cloning onBigtable
is cheap. - For initiate a Bigtable connection, then a
Bigtable
client can be made from it. - A data structure for returning the read content of a cell in a row.
Enums§
- Error types the client may have