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
15#[cfg(any(
16    google_cloud_unstable_bigquery_arrow,
17    google_cloud_unstable_bigquery_storage_read
18))]
19#[cfg_attr(not(test), allow(dead_code))]
20pub(crate) mod arrow;
21pub(super) mod builder;
22pub(super) mod client;
23pub(super) mod client_builder;
24mod execution;
25pub(super) mod from_sql;
26mod iterator;
27mod query_handle;
28pub mod retry_policy;
29mod row;
30mod schema;
31
32pub use iterator::RowIterator;
33pub use query_handle::{CompleteQuery, Query};
34pub(crate) use schema::Schema;
35
36pub use from_sql::{FromSql, SqlValue};
37pub use google_cloud_bigquery_derive::{FromRow, FromSql};
38pub use row::{ColumnIndex, Row};
39
40/// Result type for query execution.
41pub(super) type Result<T> = std::result::Result<T, crate::error::QueryError>;
42
43#[cfg(test)]
44pub(crate) mod tests {
45    use google_cloud_bigquery_v2::Result;
46    use google_cloud_bigquery_v2::client::JobService;
47    use google_cloud_bigquery_v2::model::{
48        GetJobRequest, GetQueryResultsRequest, GetQueryResultsResponse, InsertJobRequest, Job,
49        PostQueryRequest, QueryResponse,
50    };
51    use google_cloud_gax::options::RequestOptions;
52    use google_cloud_gax::polling_backoff_policy::PollingBackoffPolicy;
53    use google_cloud_gax::polling_state::PollingState;
54    use google_cloud_gax::response::Response;
55    use google_cloud_gax::retry_state::RetryState;
56    use std::sync::Arc;
57
58    mockall::mock! {
59        #[derive(Debug)]
60        pub JobService {}
61        impl google_cloud_bigquery_v2::stub::JobService for JobService {
62            async fn get_job(
63                &self,
64                req: GetJobRequest,
65                options: RequestOptions,
66            ) -> Result<Response<Job>>;
67            async fn insert_job(
68                &self,
69                req: InsertJobRequest,
70                options: RequestOptions,
71            ) -> Result<Response<Job>>;
72            async fn query(
73                &self,
74                req: PostQueryRequest,
75                options: RequestOptions,
76            ) -> Result<Response<QueryResponse>>;
77            async fn get_query_results(
78                &self,
79                req: GetQueryResultsRequest,
80                options: RequestOptions,
81            ) -> Result<Response<GetQueryResultsResponse>>;
82        }
83    }
84
85    mockall::mock! {
86        #[derive(Debug)]
87        pub BackoffPolicy {}
88        impl PollingBackoffPolicy for BackoffPolicy {
89            fn wait_period(&self, _state: &PollingState) -> std::time::Duration;
90        }
91        impl google_cloud_gax::backoff_policy::BackoffPolicy for BackoffPolicy {
92            fn on_failure(&self, state: &RetryState) -> std::time::Duration;
93        }
94    }
95
96    pub(crate) fn create_job_service(mock: MockJobService) -> Arc<JobService> {
97        Arc::new(JobService::from_stub::<MockJobService>(Arc::new(mock)))
98    }
99
100    pub(crate) fn create_test_backoff_policy() -> MockBackoffPolicy {
101        MockBackoffPolicy::new()
102    }
103}