aws_sdk_timestreamquery/operation/
query.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Orchestration and serialization glue logic for `Query`.
3#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct Query;
6impl Query {
7    /// Creates a new `Query`
8    pub fn new() -> Self {
9        Self
10    }
11    pub(crate) async fn orchestrate(
12        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
13        input: crate::operation::query::QueryInput,
14    ) -> ::std::result::Result<
15        crate::operation::query::QueryOutput,
16        ::aws_smithy_runtime_api::client::result::SdkError<
17            crate::operation::query::QueryError,
18            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
19        >,
20    > {
21        let map_err = |err: ::aws_smithy_runtime_api::client::result::SdkError<
22            ::aws_smithy_runtime_api::client::interceptors::context::Error,
23            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
24        >| { err.map_service_error(|err| err.downcast::<crate::operation::query::QueryError>().expect("correct error type")) };
25        let context = Self::orchestrate_with_stop_point(runtime_plugins, input, ::aws_smithy_runtime::client::orchestrator::StopPoint::None)
26            .await
27            .map_err(map_err)?;
28        let output = context.finalize().map_err(map_err)?;
29        ::std::result::Result::Ok(output.downcast::<crate::operation::query::QueryOutput>().expect("correct output type"))
30    }
31
32    pub(crate) async fn orchestrate_with_stop_point(
33        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
34        input: crate::operation::query::QueryInput,
35        stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
36    ) -> ::std::result::Result<
37        ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
38        ::aws_smithy_runtime_api::client::result::SdkError<
39            ::aws_smithy_runtime_api::client::interceptors::context::Error,
40            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
41        >,
42    > {
43        let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
44        use ::tracing::Instrument;
45        ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("Timestream Query", "Query", input, runtime_plugins, stop_point)
46            // Create a parent span for the entire operation. Includes a random, internal-only,
47            // seven-digit ID for the operation orchestration so that it can be correlated in the logs.
48            .instrument(::tracing::debug_span!(
49                "Timestream Query.Query",
50                "rpc.service" = "Timestream Query",
51                "rpc.method" = "Query",
52                "sdk_invocation_id" = ::fastrand::u32(1_000_000..10_000_000),
53                "rpc.system" = "aws-api",
54            ))
55            .await
56    }
57
58    pub(crate) fn operation_runtime_plugins(
59        client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
60        client_config: &crate::config::Config,
61        config_override: ::std::option::Option<crate::config::Builder>,
62    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
63        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
64        runtime_plugins = runtime_plugins
65            .with_operation_plugin(crate::client_idempotency_token::IdempotencyTokenRuntimePlugin::new(
66                |token_provider, input| {
67                    let input: &mut crate::operation::query::QueryInput = input.downcast_mut().expect("correct type");
68                    if input.client_token.is_none() {
69                        input.client_token = ::std::option::Option::Some(token_provider.make_idempotency_token());
70                    }
71                },
72            ))
73            .with_client_plugin(crate::auth_plugin::DefaultAuthOptionsPlugin::new(vec![
74                ::aws_runtime::auth::sigv4::SCHEME_ID,
75            ]));
76        if let ::std::option::Option::Some(config_override) = config_override {
77            for plugin in config_override.runtime_plugins.iter().cloned() {
78                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
79            }
80            runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
81                config_override,
82                client_config.config.clone(),
83                &client_config.runtime_components,
84            ));
85        }
86        runtime_plugins
87    }
88}
89impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for Query {
90    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
91        let mut cfg = ::aws_smithy_types::config_bag::Layer::new("Query");
92
93        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
94            QueryRequestSerializer,
95        ));
96        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
97            QueryResponseDeserializer,
98        ));
99
100        cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
101            ::aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolverParams::new(),
102        ));
103
104        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new("Query", "Timestream Query"));
105        let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
106        signing_options.double_uri_encode = true;
107        signing_options.content_sha256_header = false;
108        signing_options.normalize_uri_path = true;
109        signing_options.payload_override = None;
110
111        cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
112            signing_options,
113            ..::std::default::Default::default()
114        });
115
116        ::std::option::Option::Some(cfg.freeze())
117    }
118
119    fn runtime_components(
120        &self,
121        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
122    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
123        #[allow(unused_mut)]
124        let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("Query")
125            .with_interceptor(::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default())
126            .with_interceptor(QueryEndpointParamsInterceptor)
127            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
128                crate::operation::query::QueryError,
129            >::new())
130            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
131                crate::operation::query::QueryError,
132            >::new())
133            .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
134                crate::operation::query::QueryError,
135            >::new());
136
137        ::std::borrow::Cow::Owned(rcb)
138    }
139}
140
141#[derive(Debug)]
142struct QueryResponseDeserializer;
143impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for QueryResponseDeserializer {
144    fn deserialize_nonstreaming(
145        &self,
146        response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
147    ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
148        let (success, status) = (response.status().is_success(), response.status().as_u16());
149        let headers = response.headers();
150        let body = response.body().bytes().expect("body loaded");
151        #[allow(unused_mut)]
152        let mut force_error = false;
153        ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
154        let parse_result = if !success && status != 200 || force_error {
155            crate::protocol_serde::shape_query::de_query_http_error(status, headers, body)
156        } else {
157            crate::protocol_serde::shape_query::de_query_http_response(status, headers, body)
158        };
159        crate::protocol_serde::type_erase_result(parse_result)
160    }
161}
162#[derive(Debug)]
163struct QueryRequestSerializer;
164impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for QueryRequestSerializer {
165    #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
166    fn serialize_input(
167        &self,
168        input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
169        _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
170    ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
171        let input = input.downcast::<crate::operation::query::QueryInput>().expect("correct type");
172        let _header_serialization_settings = _cfg
173            .load::<crate::serialization_settings::HeaderSerializationSettings>()
174            .cloned()
175            .unwrap_or_default();
176        let mut request_builder = {
177            fn uri_base(
178                _input: &crate::operation::query::QueryInput,
179                output: &mut ::std::string::String,
180            ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
181                use ::std::fmt::Write as _;
182                ::std::write!(output, "/").expect("formatting should succeed");
183                ::std::result::Result::Ok(())
184            }
185            #[allow(clippy::unnecessary_wraps)]
186            fn update_http_builder(
187                input: &crate::operation::query::QueryInput,
188                builder: ::http::request::Builder,
189            ) -> ::std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
190                let mut uri = ::std::string::String::new();
191                uri_base(input, &mut uri)?;
192                ::std::result::Result::Ok(builder.method("POST").uri(uri))
193            }
194            let mut builder = update_http_builder(&input, ::http::request::Builder::new())?;
195            builder = _header_serialization_settings.set_default_header(builder, ::http::header::CONTENT_TYPE, "application/x-amz-json-1.0");
196            builder = _header_serialization_settings.set_default_header(
197                builder,
198                ::http::header::HeaderName::from_static("x-amz-target"),
199                "Timestream_20181101.Query",
200            );
201            builder
202        };
203        let body = ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_query::ser_query_input(&input)?);
204        if let Some(content_length) = body.content_length() {
205            let content_length = content_length.to_string();
206            request_builder = _header_serialization_settings.set_default_header(request_builder, ::http::header::CONTENT_LENGTH, &content_length);
207        }
208        ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
209    }
210}
211#[derive(Debug)]
212struct QueryEndpointParamsInterceptor;
213
214impl ::aws_smithy_runtime_api::client::interceptors::Intercept for QueryEndpointParamsInterceptor {
215    fn name(&self) -> &'static str {
216        "QueryEndpointParamsInterceptor"
217    }
218
219    fn read_before_execution(
220        &self,
221        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
222            '_,
223            ::aws_smithy_runtime_api::client::interceptors::context::Input,
224            ::aws_smithy_runtime_api::client::interceptors::context::Output,
225            ::aws_smithy_runtime_api::client::interceptors::context::Error,
226        >,
227        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
228    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
229        let _input = context.input().downcast_ref::<QueryInput>().ok_or("failed to downcast to QueryInput")?;
230
231        let params = crate::config::endpoint::Params::builder()
232            .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
233            .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
234            .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
235            .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
236            .build()
237            .map_err(|err| {
238                ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
239            })?;
240        cfg.interceptor_state()
241            .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
242        ::std::result::Result::Ok(())
243    }
244}
245
246// The get_* functions below are generated from JMESPath expressions in the
247// operationContextParams trait. They target the operation's input shape.
248
249/// Error type for the `QueryError` operation.
250#[non_exhaustive]
251#[derive(::std::fmt::Debug)]
252pub enum QueryError {
253    /// <p>You do not have the necessary permissions to access the account settings.</p>
254    AccessDeniedException(crate::types::error::AccessDeniedException),
255    /// <p>Unable to poll results for a cancelled query.</p>
256    ConflictException(crate::types::error::ConflictException),
257    /// <p>An internal server error occurred while processing the request.</p>
258    InternalServerException(crate::types::error::InternalServerException),
259    /// <p>The requested endpoint is invalid.</p>
260    InvalidEndpointException(crate::types::error::InvalidEndpointException),
261    /// <p>Timestream was unable to run the query successfully.</p>
262    QueryExecutionException(crate::types::error::QueryExecutionException),
263    /// <p>The request was throttled due to excessive requests.</p>
264    ThrottlingException(crate::types::error::ThrottlingException),
265    /// <p>Invalid or malformed request.</p>
266    ValidationException(crate::types::error::ValidationException),
267    /// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code).
268    #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
269    variable wildcard pattern and check `.code()`:
270     \
271    &nbsp;&nbsp;&nbsp;`err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
272     \
273    See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-QueryError) for what information is available for the error.")]
274    Unhandled(crate::error::sealed_unhandled::Unhandled),
275}
276impl QueryError {
277    /// Creates the `QueryError::Unhandled` variant from any error type.
278    pub fn unhandled(
279        err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
280    ) -> Self {
281        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
282            source: err.into(),
283            meta: ::std::default::Default::default(),
284        })
285    }
286
287    /// Creates the `QueryError::Unhandled` variant from an [`ErrorMetadata`](::aws_smithy_types::error::ErrorMetadata).
288    pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
289        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
290            source: err.clone().into(),
291            meta: err,
292        })
293    }
294    ///
295    /// Returns error metadata, which includes the error code, message,
296    /// request ID, and potentially additional information.
297    ///
298    pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
299        match self {
300            Self::AccessDeniedException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
301            Self::ConflictException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
302            Self::InternalServerException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
303            Self::InvalidEndpointException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
304            Self::QueryExecutionException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
305            Self::ThrottlingException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
306            Self::ValidationException(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
307            Self::Unhandled(e) => &e.meta,
308        }
309    }
310    /// Returns `true` if the error kind is `QueryError::AccessDeniedException`.
311    pub fn is_access_denied_exception(&self) -> bool {
312        matches!(self, Self::AccessDeniedException(_))
313    }
314    /// Returns `true` if the error kind is `QueryError::ConflictException`.
315    pub fn is_conflict_exception(&self) -> bool {
316        matches!(self, Self::ConflictException(_))
317    }
318    /// Returns `true` if the error kind is `QueryError::InternalServerException`.
319    pub fn is_internal_server_exception(&self) -> bool {
320        matches!(self, Self::InternalServerException(_))
321    }
322    /// Returns `true` if the error kind is `QueryError::InvalidEndpointException`.
323    pub fn is_invalid_endpoint_exception(&self) -> bool {
324        matches!(self, Self::InvalidEndpointException(_))
325    }
326    /// Returns `true` if the error kind is `QueryError::QueryExecutionException`.
327    pub fn is_query_execution_exception(&self) -> bool {
328        matches!(self, Self::QueryExecutionException(_))
329    }
330    /// Returns `true` if the error kind is `QueryError::ThrottlingException`.
331    pub fn is_throttling_exception(&self) -> bool {
332        matches!(self, Self::ThrottlingException(_))
333    }
334    /// Returns `true` if the error kind is `QueryError::ValidationException`.
335    pub fn is_validation_exception(&self) -> bool {
336        matches!(self, Self::ValidationException(_))
337    }
338}
339impl ::std::error::Error for QueryError {
340    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
341        match self {
342            Self::AccessDeniedException(_inner) => ::std::option::Option::Some(_inner),
343            Self::ConflictException(_inner) => ::std::option::Option::Some(_inner),
344            Self::InternalServerException(_inner) => ::std::option::Option::Some(_inner),
345            Self::InvalidEndpointException(_inner) => ::std::option::Option::Some(_inner),
346            Self::QueryExecutionException(_inner) => ::std::option::Option::Some(_inner),
347            Self::ThrottlingException(_inner) => ::std::option::Option::Some(_inner),
348            Self::ValidationException(_inner) => ::std::option::Option::Some(_inner),
349            Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
350        }
351    }
352}
353impl ::std::fmt::Display for QueryError {
354    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
355        match self {
356            Self::AccessDeniedException(_inner) => _inner.fmt(f),
357            Self::ConflictException(_inner) => _inner.fmt(f),
358            Self::InternalServerException(_inner) => _inner.fmt(f),
359            Self::InvalidEndpointException(_inner) => _inner.fmt(f),
360            Self::QueryExecutionException(_inner) => _inner.fmt(f),
361            Self::ThrottlingException(_inner) => _inner.fmt(f),
362            Self::ValidationException(_inner) => _inner.fmt(f),
363            Self::Unhandled(_inner) => {
364                if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
365                    write!(f, "unhandled error ({code})")
366                } else {
367                    f.write_str("unhandled error")
368                }
369            }
370        }
371    }
372}
373impl ::aws_smithy_types::retry::ProvideErrorKind for QueryError {
374    fn code(&self) -> ::std::option::Option<&str> {
375        ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
376    }
377    fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
378        ::std::option::Option::None
379    }
380}
381impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for QueryError {
382    fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
383        match self {
384            Self::AccessDeniedException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
385            Self::ConflictException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
386            Self::InternalServerException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
387            Self::InvalidEndpointException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
388            Self::QueryExecutionException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
389            Self::ThrottlingException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
390            Self::ValidationException(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
391            Self::Unhandled(_inner) => &_inner.meta,
392        }
393    }
394}
395impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for QueryError {
396    fn create_unhandled_error(
397        source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
398        meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
399    ) -> Self {
400        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
401            source,
402            meta: meta.unwrap_or_default(),
403        })
404    }
405}
406impl ::aws_types::request_id::RequestId for crate::operation::query::QueryError {
407    fn request_id(&self) -> Option<&str> {
408        self.meta().request_id()
409    }
410}
411
412pub use crate::operation::query::_query_output::QueryOutput;
413
414pub use crate::operation::query::_query_input::QueryInput;
415
416mod _query_input;
417
418mod _query_output;
419
420/// Builders
421pub mod builders;