Expand description
Google Cloud Client Libraries for Rust - BigQuery
WARNING: this is a preview release of the crate. We believe the APIs to be stable. We also are seeking feedback about the APIs and may need to make breaking changes if we discover that some parts are hard to use.
We welcome feedback about the APIs, documentation, missing features, bugs, etc.
This crate contains traits, types, and functions to interact with Google Cloud BigQuery. Most applications will use the structs defined in the client module.
For executing queries and managing jobs:
For streaming data to BigQuery:
§Example: Executing a Query
// Create a client configured with a default project ID.
let client = BigQuery::builder()
.with_project_id("my-project-id")
.build()
.await?;
// Configure, run, and read query results.
let mut rows = client
.query("SELECT 'hello world' AS greeting")
.until_done()
.await?
.read();
while let Some(row) = rows.next().await.transpose()? {
let greeting: String = row.get("greeting");
println!("Greeting: {greeting}");
}§Example: Mapping Rows to Rust Structs
Define typed Rust structs with #[derive(FromRow)] to convert rows
directly into domain types using TryFrom<Row>:
#[derive(FromRow, Debug)]
struct UserStats {
name: String,
count: i64,
}
let mut rows = client
.query("SELECT name, count FROM `bigquery-public-data.usa_names.usa_1910_2013` WHERE state = 'WA' LIMIT 5")
.until_done()
.await?
.read();
while let Some(row) = rows.next().await.transpose()? {
let user: UserStats = row.try_into()?;
println!("{} has count {}", user.name, user.count);
}§Example: Writing to BigQuery
use google_cloud_bigquery::client::Write;
use google_cloud_bigquery::model::{ArrowSchema, ArrowRecordBatch};
let client = Write::builder().build().await?;
let writer = client
.arrow(schema())
.default("projects/my-project/datasets/my-dataset/tables/my-table")?;
let f1 = writer.append(rows()).send();
let f2 = writer.append(rows()).send();
let _ = f1.await?;
let _ = f2.await?;
fn schema() -> ArrowSchema {
todo!("Define your table's schema...")
}
fn rows() -> ArrowRecordBatch {
todo!("Serialize your rows...")
}Modules§
- builder
- Request and client builders.
- client
- Clients to interact with Google Cloud BigQuery.
- datatypes
- Custom data types for BigQuery.
- error
- Custom errors for the BigQuery clients.
- model
- The messages and enums that are part of this client library
- model_
ext - Extends crate::model.
- query
- Types related to querying with a BigQuery client.
- write
- Types related to writing with a Write client.
Structs§
- Error
- The core error returned by all client libraries.
Type Aliases§
- Result
- An alias of std::result::Result where the error is always Error.