pub struct BigQuery { /* private fields */ }Expand description
A high-level BigQuery client for executing queries and managing jobs.
§Configuration
To configure a BigQuery client, use the with_* methods on the ClientBuilder returned
by BigQuery::builder(). The default configuration uses Application Default Credentials (ADC)
and connects to the global default endpoint, which works for most applications.
Common configuration customizations include:
with_project_id(): Sets the default Google Cloud project ID for the client.with_endpoint(): Overrides the default API endpoint (https://bigquery.googleapis.com). Useful when testing against mock servers or running in restricted network environments (for example, with VPC Service Controls).with_credentials(): Overrides the default Application Default Credentials with explicit or custom authentication credentials.
§Pooling and Cloning
BigQuery holds an internal gRPC/HTTP client and connection pool wrapped in an Arc.
You should create a single BigQuery client instance upon application initialization and reuse it across multiple tasks or requests.
Cloning a BigQuery instance is cheap and does not duplicate underlying connections or thread pools, so you do not need to wrap BigQuery in an additional Arc.
§Example: Basic Setup and Query Execution
let client = BigQuery::builder().build().await?;
let mut rows = client
.query("SELECT name, count FROM `bigquery-public-data.usa_names.usa_1910_2013` WHERE state = 'WA' ORDER BY count DESC LIMIT 5")
.with_project_id("my-project-id")
.until_done()
.await?
.read();
while let Some(row) = rows.next().await.transpose()? {
let name: String = row.get("name");
let count: i64 = row.get("count");
println!("{name}: {count}");
}Implementations§
Source§impl BigQuery
impl BigQuery
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Returns a new ClientBuilder for configuring and instantiating a BigQuery client.
§Example
let client = BigQuery::builder()
.with_endpoint("https://bigquery.googleapis.com")
.build()
.await?;Sourcepub fn query<S: Into<String>>(&self, sql: S) -> Query
pub fn query<S: Into<String>>(&self, sql: S) -> Query
Creates a request builder to configure and execute a SQL query.
This method returns a Query builder used to set parameters, specify options,
and execute the query.
If you configured a default project ID on the client via
ClientBuilder::with_project_id,
the returned query builder inherits it automatically.
Call Query::send() to start query execution, or Query::until_done()
to start execution and wait for results.
§Example
use google_cloud_bigquery::client::BigQuery;
let client = BigQuery::builder().build().await?;
// Execute a query and read the resulting rows.
let mut rows = client
.query("SELECT name, count FROM `my-project.my_dataset.stats` LIMIT 50")
.with_project_id("my-project-id")
.set_location("US")
.until_done()
.await?
.read();
while let Some(row) = rows.next().await.transpose()? {
let name: String = row.get("name");
let count: i64 = row.get("count");
println!("{name}: {count}");
}Sourcepub async fn attach_job(
&self,
job_ref: JobReference,
) -> Result<QueryHandle, QueryError>
pub async fn attach_job( &self, job_ref: JobReference, ) -> Result<QueryHandle, QueryError>
Binds an existing out-of-process query job reference to a high-level Query handle.
Fetches the job metadata via JobService::get_job and initializes a
Query handle.
If job_ref.project_id is empty, it defaults to the client’s billing project ID.
§Arguments
job_ref- AJobReferenceidentifying the job to attach to.
§Example
let job_ref = JobReference::new()
.set_project_id("my-project")
.set_job_id("my_job_id")
.set_location("us-central1");
let query = client.attach_job(job_ref).await?;
let mut results = query.until_done().await?.read();
while let Some(row) = results.next().await {
let row = row?;
// process row
}Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for BigQuery
impl !UnwindSafe for BigQuery
impl Freeze for BigQuery
impl Send for BigQuery
impl Sync for BigQuery
impl Unpin for BigQuery
impl UnsafeUnpin for BigQuery
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request