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
impl Query
Sourcepub fn with_project_id<S: Into<String>>(self, project_id: S) -> Self
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?;Sourcepub async fn send(self) -> Result<QueryHandle, QueryError>
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}");
}Sourcepub async fn until_done(self) -> Result<CompleteQuery, QueryError>
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
impl Query
pub fn set_allow_large_results<T>(self, v: T) -> Self
pub fn set_allow_large_results<T>(self, v: T) -> Self
Sets the value of request.allow_large_results.
pub fn set_or_clear_allow_large_results<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_allow_large_results<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.allow_large_results.
pub fn set_clustering<T>(self, v: T) -> Selfwhere
T: Into<Clustering>,
pub fn set_clustering<T>(self, v: T) -> Selfwhere
T: Into<Clustering>,
Sets the value of request.clustering.
pub fn set_or_clear_clustering<T>(self, v: Option<T>) -> Selfwhere
T: Into<Clustering>,
pub fn set_or_clear_clustering<T>(self, v: Option<T>) -> Selfwhere
T: Into<Clustering>,
Sets or clears the value of request.clustering.
pub fn set_connection_properties<T, V>(self, v: T) -> Self
pub fn set_connection_properties<T, V>(self, v: T) -> Self
Sets the value of request.connection_properties.
pub fn set_create_disposition<T: Into<String>>(self, v: T) -> Self
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
pub fn set_create_session<T>(self, v: T) -> Self
Sets the value of request.create_session.
pub fn set_or_clear_create_session<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_create_session<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.create_session.
pub fn set_default_dataset<T>(self, v: T) -> Selfwhere
T: Into<DatasetReference>,
pub fn set_default_dataset<T>(self, v: T) -> Selfwhere
T: Into<DatasetReference>,
Sets the value of request.default_dataset.
pub fn set_or_clear_default_dataset<T>(self, v: Option<T>) -> Selfwhere
T: Into<DatasetReference>,
pub fn set_or_clear_default_dataset<T>(self, v: Option<T>) -> Selfwhere
T: Into<DatasetReference>,
Sets or clears the value of request.default_dataset.
pub fn set_destination_encryption_configuration<T>(self, v: T) -> Selfwhere
T: Into<EncryptionConfiguration>,
pub fn set_destination_encryption_configuration<T>(self, v: T) -> Selfwhere
T: Into<EncryptionConfiguration>,
Sets the value of request.destination_encryption_configuration.
pub fn set_or_clear_destination_encryption_configuration<T>(
self,
v: Option<T>,
) -> Selfwhere
T: Into<EncryptionConfiguration>,
pub fn set_or_clear_destination_encryption_configuration<T>(
self,
v: Option<T>,
) -> Selfwhere
T: Into<EncryptionConfiguration>,
Sets or clears the value of request.destination_encryption_configuration.
pub fn set_destination_table<T>(self, v: T) -> Selfwhere
T: Into<TableReference>,
pub fn set_destination_table<T>(self, v: T) -> Selfwhere
T: Into<TableReference>,
Sets the value of request.destination_table.
pub fn set_or_clear_destination_table<T>(self, v: Option<T>) -> Selfwhere
T: Into<TableReference>,
pub fn set_or_clear_destination_table<T>(self, v: Option<T>) -> Selfwhere
T: Into<TableReference>,
Sets or clears the value of request.destination_table.
pub fn set_dry_run<T: Into<bool>>(self, v: T) -> Self
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_external_table_definitions<T, K, V>(self, v: T) -> Self
Sets the value of request.external_table_definitions.
pub fn set_flatten_results<T>(self, v: T) -> Self
pub fn set_flatten_results<T>(self, v: T) -> Self
Sets the value of request.flatten_results.
pub fn set_or_clear_flatten_results<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_flatten_results<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.flatten_results.
pub fn set_job_creation_mode<T: Into<JobCreationMode>>(self, v: T) -> Self
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
pub fn set_job_timeout_ms<T>(self, v: T) -> Self
Sets the value of request.job_timeout_ms.
pub fn set_or_clear_job_timeout_ms<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_job_timeout_ms<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.job_timeout_ms.
pub fn set_labels<T, K, V>(self, v: T) -> Self
pub fn set_labels<T, K, V>(self, v: T) -> Self
Sets the value of request.labels.
pub fn set_location<T: Into<String>>(self, v: T) -> Self
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) -> Selfwhere
T: Into<UInt32Value>,
pub fn set_max_results<T>(self, v: T) -> Selfwhere
T: Into<UInt32Value>,
Sets the value of request.max_results.
pub fn set_or_clear_max_results<T>(self, v: Option<T>) -> Selfwhere
T: Into<UInt32Value>,
pub fn set_or_clear_max_results<T>(self, v: Option<T>) -> Selfwhere
T: Into<UInt32Value>,
Sets or clears the value of request.max_results.
pub fn set_max_slots<T>(self, v: T) -> Self
pub fn set_max_slots<T>(self, v: T) -> Self
Sets the value of request.max_slots.
pub fn set_or_clear_max_slots<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_max_slots<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.max_slots.
pub fn set_maximum_bytes_billed<T>(self, v: T) -> Selfwhere
T: Into<Int64Value>,
pub fn set_maximum_bytes_billed<T>(self, v: T) -> Selfwhere
T: Into<Int64Value>,
Sets the value of request.maximum_bytes_billed.
pub fn set_or_clear_maximum_bytes_billed<T>(self, v: Option<T>) -> Selfwhere
T: Into<Int64Value>,
pub fn set_or_clear_maximum_bytes_billed<T>(self, v: Option<T>) -> Selfwhere
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
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
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
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
pub fn set_query_parameters<T, V>(self, v: T) -> Self
Sets the value of request.query_parameters.
pub fn set_range_partitioning<T>(self, v: T) -> Selfwhere
T: Into<RangePartitioning>,
pub fn set_range_partitioning<T>(self, v: T) -> Selfwhere
T: Into<RangePartitioning>,
Sets the value of request.range_partitioning.
pub fn set_or_clear_range_partitioning<T>(self, v: Option<T>) -> Selfwhere
T: Into<RangePartitioning>,
pub fn set_or_clear_range_partitioning<T>(self, v: Option<T>) -> Selfwhere
T: Into<RangePartitioning>,
Sets or clears the value of request.range_partitioning.
pub fn set_reservation<T>(self, v: T) -> Self
pub fn set_reservation<T>(self, v: T) -> Self
Sets the value of request.reservation.
pub fn set_or_clear_reservation<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_reservation<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.reservation.
pub fn set_schema_update_options<T, V>(self, v: T) -> Self
pub fn set_schema_update_options<T, V>(self, v: T) -> Self
Sets the value of request.schema_update_options.
pub fn set_script_options<T>(self, v: T) -> Selfwhere
T: Into<ScriptOptions>,
pub fn set_script_options<T>(self, v: T) -> Selfwhere
T: Into<ScriptOptions>,
Sets the value of request.script_options.
pub fn set_or_clear_script_options<T>(self, v: Option<T>) -> Selfwhere
T: Into<ScriptOptions>,
pub fn set_or_clear_script_options<T>(self, v: Option<T>) -> Selfwhere
T: Into<ScriptOptions>,
Sets or clears the value of request.script_options.
pub fn set_time_partitioning<T>(self, v: T) -> Selfwhere
T: Into<TimePartitioning>,
pub fn set_time_partitioning<T>(self, v: T) -> Selfwhere
T: Into<TimePartitioning>,
Sets the value of request.time_partitioning.
pub fn set_or_clear_time_partitioning<T>(self, v: Option<T>) -> Selfwhere
T: Into<TimePartitioning>,
pub fn set_or_clear_time_partitioning<T>(self, v: Option<T>) -> Selfwhere
T: Into<TimePartitioning>,
Sets or clears the value of request.time_partitioning.
pub fn set_timeout_ms<T>(self, v: T) -> Selfwhere
T: Into<UInt32Value>,
pub fn set_timeout_ms<T>(self, v: T) -> Selfwhere
T: Into<UInt32Value>,
Sets the value of request.timeout_ms.
pub fn set_or_clear_timeout_ms<T>(self, v: Option<T>) -> Selfwhere
T: Into<UInt32Value>,
pub fn set_or_clear_timeout_ms<T>(self, v: Option<T>) -> Selfwhere
T: Into<UInt32Value>,
Sets or clears the value of request.timeout_ms.
pub fn set_use_legacy_sql<T>(self, v: T) -> Self
pub fn set_use_legacy_sql<T>(self, v: T) -> Self
Sets the value of request.use_legacy_sql.
pub fn set_or_clear_use_legacy_sql<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_use_legacy_sql<T>(self, v: Option<T>) -> Self
Sets or clears the value of request.use_legacy_sql.
pub fn set_use_query_cache<T>(self, v: T) -> Self
pub fn set_use_query_cache<T>(self, v: T) -> Self
Sets the value of request.use_query_cache.
pub fn set_or_clear_use_query_cache<T>(self, v: Option<T>) -> Self
pub fn set_or_clear_use_query_cache<T>(self, v: Option<T>) -> Self
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_user_defined_function_resources<T, V>(self, v: T) -> Self
Sets the value of request.user_defined_function_resources.
pub fn set_write_disposition<T: Into<String>>(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§
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> 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