Skip to main content

Query

Struct Query 

Source
pub struct Query { /* private fields */ }
Expand description

A builder for configuring and executing a SQL query.

BigQuery::query() returns a Query builder.

Use this builder to configure query parameters, dataset defaults, geographic location, result limits, and caching before executing the query with send() or until_done().

§Example

let mut rows = client
    .query("SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` WHERE state = 'TX' LIMIT 100")
    .set_location("US")
    .set_max_results(50_u32)
    .until_done()
    .await?
    .read();

while let Some(row) = rows.next().await.transpose()? {
    let name: String = row.get("name");
    println!("Name: {name}");
}

Implementations§

Source§

impl Query

Source

pub fn with_project_id<S: Into<String>>(self, project_id: S) -> Self

Sets the project ID to override the default client project ID for query execution and billing.

If you configured a default project ID on the BigQuery client via ClientBuilder::with_project_id, the query inherits it automatically. Calling this method overrides the project ID for this specific query.

You must specify a project ID either on the client or on the query builder before calling send().

§Example
let query_handle = client
    .query("SELECT 1 AS count")
    .with_project_id("my-project-id")
    .send()
    .await?;
Source

pub async fn send(self) -> Result<QueryHandle, QueryError>

Executes the SQL query.

Returns a Query handle representing the query execution. You can call until_done() on the returned handle to wait for results, or inspect the initial metadata().

You must configure a target project ID on either the BigQuery client via ClientBuilder::with_project_id or on this builder via with_project_id().

§Example
let query_handle = client
    .query("SELECT CURRENT_TIMESTAMP() AS now")
    .send()
    .await?;

let completed_query = query_handle
    .until_done()
    .await?;

let mut rows = completed_query.read();
if let Some(row) = rows.next().await.transpose()? {
    let now: String = row.get("now");
    println!("Current time: {now}");
}
Source

pub async fn until_done(self) -> Result<CompleteQuery, QueryError>

Sends the query execution request and waits until execution completes.

This is a convenience method equivalent to calling .send().await?.until_done().await.

§Errors

Returns QueryError::DryRun if the query was configured as a dry run.

Returns an error if a remote service or network failure happens during execution or polling, or if the BigQuery job fails due to runtime execution errors.

§Example
let completed_query = client
    .query("SELECT CURRENT_TIMESTAMP() AS now")
    .until_done()
    .await?;

let mut rows = completed_query.read();
if let Some(row) = rows.next().await.transpose()? {
    let now: String = row.get("now");
    println!("Current time: {now}");
}
§

impl Query

pub fn set_allow_large_results<T>(self, v: T) -> Self
where T: Into<BoolValue>,

Sets the value of request.allow_large_results.

pub fn set_or_clear_allow_large_results<T>(self, v: Option<T>) -> Self
where T: Into<BoolValue>,

Sets or clears the value of request.allow_large_results.

pub fn set_clustering<T>(self, v: T) -> Self
where T: Into<Clustering>,

Sets the value of request.clustering.

pub fn set_or_clear_clustering<T>(self, v: Option<T>) -> Self
where T: Into<Clustering>,

Sets or clears the value of request.clustering.

pub fn set_connection_properties<T, V>(self, v: T) -> Self
where T: IntoIterator<Item = V>, V: Into<ConnectionProperty>,

Sets the value of request.connection_properties.

pub fn set_create_disposition<T: Into<String>>(self, v: T) -> Self

Sets the value of request.create_disposition.

pub fn set_create_session<T>(self, v: T) -> Self
where T: Into<BoolValue>,

Sets the value of request.create_session.

pub fn set_or_clear_create_session<T>(self, v: Option<T>) -> Self
where T: Into<BoolValue>,

Sets or clears the value of request.create_session.

pub fn set_default_dataset<T>(self, v: T) -> Self

Sets the value of request.default_dataset.

pub fn set_or_clear_default_dataset<T>(self, v: Option<T>) -> Self

Sets or clears the value of request.default_dataset.

pub fn set_destination_encryption_configuration<T>(self, v: T) -> Self

pub fn set_or_clear_destination_encryption_configuration<T>( self, v: Option<T>, ) -> Self

Sets or clears the value of request.destination_encryption_configuration.

pub fn set_destination_table<T>(self, v: T) -> Self
where T: Into<TableReference>,

Sets the value of request.destination_table.

pub fn set_or_clear_destination_table<T>(self, v: Option<T>) -> Self
where T: Into<TableReference>,

Sets or clears the value of request.destination_table.

pub fn set_dry_run<T: Into<bool>>(self, v: T) -> Self

Sets the value of request.dry_run.

pub fn set_external_table_definitions<T, K, V>(self, v: T) -> Self

pub fn set_flatten_results<T>(self, v: T) -> Self
where T: Into<BoolValue>,

Sets the value of request.flatten_results.

pub fn set_or_clear_flatten_results<T>(self, v: Option<T>) -> Self
where T: Into<BoolValue>,

Sets or clears the value of request.flatten_results.

pub fn set_job_creation_mode<T: Into<JobCreationMode>>(self, v: T) -> Self

Sets the value of request.job_creation_mode.

pub fn set_job_timeout_ms<T>(self, v: T) -> Self
where T: Into<i64>,

Sets the value of request.job_timeout_ms.

pub fn set_or_clear_job_timeout_ms<T>(self, v: Option<T>) -> Self
where T: Into<i64>,

Sets or clears the value of request.job_timeout_ms.

pub fn set_labels<T, K, V>(self, v: T) -> Self
where T: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

Sets the value of request.labels.

pub fn set_location<T: Into<String>>(self, v: T) -> Self

Sets the value of request.location.

pub fn set_max_results<T>(self, v: T) -> Self
where T: Into<UInt32Value>,

Sets the value of request.max_results.

pub fn set_or_clear_max_results<T>(self, v: Option<T>) -> Self
where T: Into<UInt32Value>,

Sets or clears the value of request.max_results.

pub fn set_max_slots<T>(self, v: T) -> Self
where T: Into<i32>,

Sets the value of request.max_slots.

pub fn set_or_clear_max_slots<T>(self, v: Option<T>) -> Self
where T: Into<i32>,

Sets or clears the value of request.max_slots.

pub fn set_maximum_bytes_billed<T>(self, v: T) -> Self
where T: Into<Int64Value>,

Sets the value of request.maximum_bytes_billed.

pub fn set_or_clear_maximum_bytes_billed<T>(self, v: Option<T>) -> Self
where T: Into<Int64Value>,

Sets or clears the value of request.maximum_bytes_billed.

pub fn set_parameter_mode<T: Into<String>>(self, v: T) -> Self

Sets the value of request.parameter_mode.

pub fn set_priority<T: Into<String>>(self, v: T) -> Self

Sets the value of request.priority.

pub fn set_query<T: Into<String>>(self, v: T) -> Self

Sets the value of request.query.

pub fn set_query_parameters<T, V>(self, v: T) -> Self
where T: IntoIterator<Item = V>, V: Into<QueryParameter>,

Sets the value of request.query_parameters.

pub fn set_range_partitioning<T>(self, v: T) -> Self

Sets the value of request.range_partitioning.

pub fn set_or_clear_range_partitioning<T>(self, v: Option<T>) -> Self

Sets or clears the value of request.range_partitioning.

pub fn set_reservation<T>(self, v: T) -> Self
where T: Into<String>,

Sets the value of request.reservation.

pub fn set_or_clear_reservation<T>(self, v: Option<T>) -> Self
where T: Into<String>,

Sets or clears the value of request.reservation.

pub fn set_schema_update_options<T, V>(self, v: T) -> Self
where T: IntoIterator<Item = V>, V: Into<String>,

Sets the value of request.schema_update_options.

pub fn set_script_options<T>(self, v: T) -> Self
where T: Into<ScriptOptions>,

Sets the value of request.script_options.

pub fn set_or_clear_script_options<T>(self, v: Option<T>) -> Self
where T: Into<ScriptOptions>,

Sets or clears the value of request.script_options.

pub fn set_time_partitioning<T>(self, v: T) -> Self

Sets the value of request.time_partitioning.

pub fn set_or_clear_time_partitioning<T>(self, v: Option<T>) -> Self

Sets or clears the value of request.time_partitioning.

pub fn set_timeout_ms<T>(self, v: T) -> Self
where T: Into<UInt32Value>,

Sets the value of request.timeout_ms.

pub fn set_or_clear_timeout_ms<T>(self, v: Option<T>) -> Self
where T: Into<UInt32Value>,

Sets or clears the value of request.timeout_ms.

pub fn set_use_legacy_sql<T>(self, v: T) -> Self
where T: Into<BoolValue>,

Sets the value of request.use_legacy_sql.

pub fn set_or_clear_use_legacy_sql<T>(self, v: Option<T>) -> Self
where T: Into<BoolValue>,

Sets or clears the value of request.use_legacy_sql.

pub fn set_use_query_cache<T>(self, v: T) -> Self
where T: Into<BoolValue>,

Sets the value of request.use_query_cache.

pub fn set_or_clear_use_query_cache<T>(self, v: Option<T>) -> Self
where T: Into<BoolValue>,

Sets or clears the value of request.use_query_cache.

pub fn set_user_defined_function_resources<T, V>(self, v: T) -> Self

pub fn set_write_disposition<T: Into<String>>(self, v: T) -> Self

Sets the value of request.write_disposition.

Trait Implementations§

Source§

impl Clone for Query

Source§

fn clone(&self) -> Query

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Query

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Query

§

impl !UnwindSafe for Query

§

impl Freeze for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnsafeUnpin for Query

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more