Skip to main content

google_cloud_bigquery/
query.rs

1// Copyright 2026 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub(super) mod builder;
16pub(super) mod client;
17pub(super) mod client_builder;
18mod execution;
19pub(super) mod from_sql;
20mod iterator;
21mod query_handle;
22mod retry_policy;
23mod row;
24mod schema;
25
26pub use iterator::RowIterator;
27pub use query_handle::{CompleteQuery, Query};
28pub(crate) use schema::Schema;
29
30pub use from_sql::FromSql;
31pub use google_cloud_bigquery_derive::{FromRow, FromSql};
32pub use row::Row;
33
34/// Result type for query execution.
35pub(super) type Result<T> = std::result::Result<T, crate::error::QueryError>;
36
37#[cfg(test)]
38pub(crate) mod tests {
39    use google_cloud_bigquery_v2::Result;
40    use google_cloud_bigquery_v2::client::JobService;
41    use google_cloud_bigquery_v2::model::{
42        GetJobRequest, GetQueryResultsRequest, GetQueryResultsResponse, InsertJobRequest, Job,
43        PostQueryRequest, QueryResponse,
44    };
45    use google_cloud_gax::options::RequestOptions;
46    use google_cloud_gax::polling_backoff_policy::PollingBackoffPolicy;
47    use google_cloud_gax::polling_state::PollingState;
48    use google_cloud_gax::response::Response;
49    use google_cloud_gax::retry_state::RetryState;
50    use std::sync::Arc;
51
52    mockall::mock! {
53        #[derive(Debug)]
54        pub JobService {}
55        impl google_cloud_bigquery_v2::stub::JobService for JobService {
56            async fn get_job(
57                &self,
58                req: GetJobRequest,
59                options: RequestOptions,
60            ) -> Result<Response<Job>>;
61            async fn insert_job(
62                &self,
63                req: InsertJobRequest,
64                options: RequestOptions,
65            ) -> Result<Response<Job>>;
66            async fn query(
67                &self,
68                req: PostQueryRequest,
69                options: RequestOptions,
70            ) -> Result<Response<QueryResponse>>;
71            async fn get_query_results(
72                &self,
73                req: GetQueryResultsRequest,
74                options: RequestOptions,
75            ) -> Result<Response<GetQueryResultsResponse>>;
76        }
77    }
78
79    mockall::mock! {
80        #[derive(Debug)]
81        pub BackoffPolicy {}
82        impl PollingBackoffPolicy for BackoffPolicy {
83            fn wait_period(&self, _state: &PollingState) -> std::time::Duration;
84        }
85        impl google_cloud_gax::backoff_policy::BackoffPolicy for BackoffPolicy {
86            fn on_failure(&self, state: &RetryState) -> std::time::Duration;
87        }
88    }
89
90    pub(crate) fn create_job_service(mock: MockJobService) -> Arc<JobService> {
91        Arc::new(JobService::from_stub::<MockJobService>(Arc::new(mock)))
92    }
93
94    pub(crate) fn create_test_backoff_policy() -> MockBackoffPolicy {
95        MockBackoffPolicy::new()
96    }
97}