google_cloud_bigquery/http/job/
get_query_results.rs

1use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
2
3use crate::http::job::JobReference;
4use crate::http::table::TableSchema;
5use crate::http::tabledata::list::Tuple;
6use crate::http::types::{DataFormatOptions, ErrorProto};
7
8#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize, Debug, Default)]
9#[serde(rename_all = "camelCase")]
10pub struct GetQueryResultsRequest {
11    /// Zero-based index of the starting row.
12    pub start_index: i64,
13    /// Page token, returned by a previous call, to request the next page of results.
14    pub page_token: Option<String>,
15    /// Maximum number of results to read.
16    pub max_results: Option<i64>,
17    /// Optional: Specifies the maximum amount of time, in milliseconds,
18    /// that the client is willing to wait for the query to complete.
19    /// By default, this limit is 10 seconds (10,000 milliseconds).
20    /// If the query is complete, the jobComplete field in the response is true.
21    /// If the query has not yet completed, jobComplete is false.
22    /// You can request a longer timeout period in the timeoutMs field.
23    /// However, the call is not guaranteed to wait for the specified timeout;
24    /// it typically returns after around 200 seconds (200,000 milliseconds),
25    /// even if the query is not complete.
26    /// If jobComplete is false, you can continue to wait for the query to complete
27    /// by calling the getQueryResults method until the jobComplete field in the getQueryResults response is true.
28    pub timeout_ms: Option<i64>,
29    /// The geographic location of the job. You must specify the location to run the job for the following scenarios:
30    /// If the location to run a job is not in the us or the eu multi-regional location
31    /// If the job's location is in a single region (for example, us-central1)
32    /// For more information, see https://cloud.google.com/bigquery/docs/locations#specifying_your_location.
33    pub location: Option<String>,
34    /// Optional. Output format adjustments.
35    pub format_options: Option<DataFormatOptions>,
36}
37
38#[derive(Clone, PartialEq, serde::Deserialize, serde::Serialize, Debug, Default)]
39#[serde(rename_all = "camelCase")]
40pub struct GetQueryResultsResponse {
41    /// The resource type.
42    pub kind: String,
43    /// A hash of this response.
44    pub etag: String,
45    /// The schema of the results. Present only when the query completes successfully.
46    pub schema: Option<TableSchema>,
47    /// Reference to the Job that was created to run the query.
48    /// This field will be present even if the original request timed out,
49    /// in which case jobs.getQueryResults can be used to read the results once the query has completed.
50    /// Since this API only returns the first page of results,
51    /// subsequent pages can be fetched via the same mechanism (jobs.getQueryResults).
52    pub job_reference: JobReference,
53    /// The total number of rows in the complete query result set,
54    /// which can be more than the number of rows in this single page of results.
55    #[serde(deserialize_with = "crate::http::from_str")]
56    pub total_rows: i64,
57    /// A token used for paging results.
58    /// A non-empty token indicates that additional results are available.
59    /// To see additional results, query the jobs.getQueryResults method.
60    /// For more information, see Paging through table data.
61    pub page_token: Option<String>,
62    /// An object with as many results as can be contained within the maximum permitted reply size.
63    /// To get any additional rows, you can call jobs.getQueryResults and specify the jobReference returned above.
64    pub rows: Option<Vec<Tuple>>,
65    /// The total number of bytes processed for this query.
66    /// If this query was a dry run, this is the number of bytes that would be processed if the query were run.
67    #[serde(default, deserialize_with = "crate::http::from_str_option")]
68    pub total_bytes_processed: Option<i64>,
69    /// Whether the query has completed or not.
70    /// If rows or totalRows are present, this will always be true.
71    /// If this is false, totalRows will not be available.
72    pub job_complete: bool,
73    /// Output only. The first errors or warnings encountered during the running of the job.
74    /// The final message includes the number of errors that caused the process to stop.
75    /// Errors here do not necessarily mean that the job has completed or was unsuccessful.
76    /// For more information about error messages, see Error messages.
77    pub errors: Option<Vec<ErrorProto>>,
78    /// Whether the query result was fetched from the query cache.
79    pub cache_hit: Option<bool>,
80    /// Output only. The number of rows affected by a DML statement.
81    /// Present only for DML statements INSERT, UPDATE or DELETE.
82    #[serde(default, deserialize_with = "crate::http::from_str_option")]
83    pub num_dml_affected_rows: Option<i64>,
84}
85
86pub fn build(
87    base_url: &str,
88    client: &Client,
89    project_id: &str,
90    job_id: &str,
91    data: &GetQueryResultsRequest,
92) -> RequestBuilder {
93    let url = format!("{}/projects/{}/queries/{}", base_url, project_id, job_id);
94    client.get(url).query(data)
95}