google-cloud-bigquery 0.16.1-preview

Google Cloud Client Libraries for Rust - BigQuery
Documentation
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub(super) mod builder;
pub(super) mod client;
pub(super) mod client_builder;
mod execution;
pub(super) mod from_sql;
mod iterator;
mod query_handle;
mod retry_policy;
mod row;
mod schema;

pub use iterator::RowIterator;
pub use query_handle::{CompleteQuery, Query};
pub(crate) use schema::Schema;

pub use from_sql::FromSql;
pub use google_cloud_bigquery_derive::{FromRow, FromSql};
pub use row::Row;

/// Result type for query execution.
pub(super) type Result<T> = std::result::Result<T, crate::error::QueryError>;

#[cfg(test)]
pub(crate) mod tests {
    use google_cloud_bigquery_v2::Result;
    use google_cloud_bigquery_v2::client::JobService;
    use google_cloud_bigquery_v2::model::{
        GetJobRequest, GetQueryResultsRequest, GetQueryResultsResponse, InsertJobRequest, Job,
        PostQueryRequest, QueryResponse,
    };
    use google_cloud_gax::options::RequestOptions;
    use google_cloud_gax::polling_backoff_policy::PollingBackoffPolicy;
    use google_cloud_gax::polling_state::PollingState;
    use google_cloud_gax::response::Response;
    use google_cloud_gax::retry_state::RetryState;
    use std::sync::Arc;

    mockall::mock! {
        #[derive(Debug)]
        pub JobService {}
        impl google_cloud_bigquery_v2::stub::JobService for JobService {
            async fn get_job(
                &self,
                req: GetJobRequest,
                options: RequestOptions,
            ) -> Result<Response<Job>>;
            async fn insert_job(
                &self,
                req: InsertJobRequest,
                options: RequestOptions,
            ) -> Result<Response<Job>>;
            async fn query(
                &self,
                req: PostQueryRequest,
                options: RequestOptions,
            ) -> Result<Response<QueryResponse>>;
            async fn get_query_results(
                &self,
                req: GetQueryResultsRequest,
                options: RequestOptions,
            ) -> Result<Response<GetQueryResultsResponse>>;
        }
    }

    mockall::mock! {
        #[derive(Debug)]
        pub BackoffPolicy {}
        impl PollingBackoffPolicy for BackoffPolicy {
            fn wait_period(&self, _state: &PollingState) -> std::time::Duration;
        }
        impl google_cloud_gax::backoff_policy::BackoffPolicy for BackoffPolicy {
            fn on_failure(&self, state: &RetryState) -> std::time::Duration;
        }
    }

    pub(crate) fn create_job_service(mock: MockJobService) -> Arc<JobService> {
        Arc::new(JobService::from_stub::<MockJobService>(Arc::new(mock)))
    }

    pub(crate) fn create_test_backoff_policy() -> MockBackoffPolicy {
        MockBackoffPolicy::new()
    }
}