pub struct Query { /* private fields */ }Expand description
A handle representing a running or completed SQL query execution.
Query::send() returns a Query.
To obtain the final result set, call until_done(),
which waits for the query execution to complete and returns a
CompleteQuery.
§Example
let query_handle = client
.query("SELECT 42 AS answer")
.send()
.await?;
// Poll until execution completes.
let completed = query_handle.until_done().await?;Implementations§
Source§impl Query
impl Query
Sourcepub fn metadata(&self) -> &QueryMetadata
pub fn metadata(&self) -> &QueryMetadata
Returns the initial metadata from query execution.
Depending on how the query was executed, the metadata contains:
job_reference: The reference to the BigQuery job, if one was created.query_id: The unique ID of the query if executed without creating a job.job_creation_reason: The reason why a job was created (controlled viaset_job_creation_mode).job_complete: Whether the query completed immediately without requiring polling.
To wait for the query to finish and retrieve full results and final
metadata, call until_done.
Sourcepub fn get_job(&self) -> Option<GetJob>
pub fn get_job(&self) -> Option<GetJob>
Build a request to fetch full Job execution metadata from the service for this query.
Returns
Noneif the query was executed without creating a job (for example, when usingJobCreationMode::JobCreationOptional, or when the query was a dry run).
§Example
let query = client
.query("SELECT 1")
.set_job_creation_mode(JobCreationMode::JobCreationRequired) // Forces a job to be created
.send()
.await?;
match query.get_job() {
Some(req) => {
let job_info = req.send().await?;
println!("Executed by user: {}", job_info.user_email);
}
None => {
println!(
"Query was run without creating a job. Query ID: {}",
query.metadata().query_id
);
}
}Sourcepub async fn until_done(self) -> Result<CompleteQuery, QueryError>
pub async fn until_done(self) -> Result<CompleteQuery, QueryError>
Waits for query execution to complete.
If the query completed immediately, this method returns a
CompleteQuery without making additional
network calls. Otherwise, it polls the service until the query finishes.
§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 polling, or if the BigQuery job fails due to runtime execution errors.
§Example
let query_handle = client
.query("SELECT 1 + 1 AS result")
.send()
.await?;
let complete = query_handle.until_done().await?;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