From 813ff290b5e00c301f7f98e68dfbb8bc9a37bc88 Mon Sep 17 00:00:00 2001 From: Gary Atwal <87947837+garya-bitquill@users.noreply.github.com> Date: Tue, 9 Nov 2021 10:05:29 -0800 Subject: [PATCH] Garya/ad 439/remove timestream from tscommunication class (#10) * [AD-451] Replace AWS ColumnInfo and Row Type with User Types https:/bitquill.atlassian.net/browse/AD-451 * [AD-451] Replace AWS ColumnInfo and Row Type with User Types https:/bitquill.atlassian.net/browse/AD-451 * [AD-451] Correct pedantic syntax https:/bitquill.atlassian.net/browse/AD-451 * [AD-451] Correct pedantic syntax https:/bitquill.atlassian.net/browse/AD-451 * remove datum and timeseries datatype parser * removing extra include * Remove 'TimestreamQuery_EXPORTS.h'. * Remove timeseries related data members and methods. * Add new file QueryStatus.(h,cpp). * Add new file Endpoint.(h,cpp). * Add new file DescribeEndpointsResult.(h,cpp). * Add new file DescribeEndpointsResult.(h,cpp). * Add QueryRequest files. * Add new file DatabaseQueryErrors.(c,cpp). * Add new file DatabaseQueryErrorMarshaller.(h,cpp) * Add new file DatabaseQueryEndpoint.(h,cpp). * Add new file QueryResult.(h,cpp). * Add new file DescribeEndpointsRequest.(h,cpp). * Add new files CancelQueryResult.(h,cpp) and DatabaseQueryClient.(h,cpp). * Fix namespace bug. * Fix error with Endpoint class. * Fix comments in CancelQueryRequest.h. * Fix comments in CancelQueryResult.h. * Remove dependency on aws/timestream-query/... and replace user-defined classes. * Remove word 'Amazon Timestream', add 'TODO' comments. * Remove word 'timestream', add 'TODO' comments. * Remove region authentication field. * Replace 'TSCommunication' with 'DBCommunication'. * Revert "Replace 'TSCommunication' with 'DBCommunication'." This reverts commit 0cc632469fd3da69b9538ad0df10d9903a5dd30f. * Revert "Remove region authentication field." This reverts commit 701e5876af7fb8746742de0519d1a83949f61cce. * Revert "Remove word 'timestream', add 'TODO' comments." This reverts commit 10fb0206b48f39a57c64cb69398b21e97ed1e75e. * Revert "Remove word 'Amazon Timestream', add 'TODO' comments." This reverts commit eb300dfb810bd62ebc1f18d12da9b1a2c9e98072. * Remove IT_REGION. * Replace 'TSCommunication' with 'DBCommunication'. * Change 'Timestream_' to 'Database_'. Co-authored-by: Bruce Irschick Co-authored-by: affonsov --- src/Tests/ITODBCHelper/it_odbc_helper.cpp | 2 - src/Tests/ITODBCHelper/it_odbc_helper.h | 1 - src/Tests/Tests/test_conn.cpp | 12 +- src/odbcdriver/CMakeLists.txt | 25 ++ src/odbcdriver/CancelQueryRequest.cpp | 33 ++ src/odbcdriver/CancelQueryRequest.h | 103 +++++ src/odbcdriver/CancelQueryResult.cpp | 34 ++ src/odbcdriver/CancelQueryResult.h | 101 +++++ src/odbcdriver/ColumnInfo.h | 11 +- src/odbcdriver/DatabaseQueryClient.cpp | 340 +++++++++++++++++ src/odbcdriver/DatabaseQueryClient.h | 304 +++++++++++++++ src/odbcdriver/DatabaseQueryEndpoint.cpp | 49 +++ src/odbcdriver/DatabaseQueryEndpoint.h | 13 + .../DatabaseQueryErrorMarshaller.cpp | 21 ++ src/odbcdriver/DatabaseQueryErrorMarshaller.h | 14 + src/odbcdriver/DatabaseQueryErrors.cpp | 45 +++ src/odbcdriver/DatabaseQueryErrors.h | 77 ++++ src/odbcdriver/DatabaseQueryRequest.h | 39 ++ src/odbcdriver/Datum.h | 20 +- src/odbcdriver/DescribeEndpointsRequest.cpp | 27 ++ src/odbcdriver/DescribeEndpointsRequest.h | 28 ++ src/odbcdriver/DescribeEndpointsResult.cpp | 38 ++ src/odbcdriver/DescribeEndpointsResult.h | 97 +++++ src/odbcdriver/Endpoint.cpp | 50 +++ src/odbcdriver/Endpoint.h | 131 +++++++ src/odbcdriver/QueryRequest.cpp | 51 +++ src/odbcdriver/QueryRequest.h | 357 ++++++++++++++++++ src/odbcdriver/QueryResult.cpp | 60 +++ src/odbcdriver/QueryResult.h | 305 +++++++++++++++ src/odbcdriver/QueryStatus.cpp | 43 +++ src/odbcdriver/QueryStatus.h | 62 +++ src/odbcdriver/Row.h | 56 +-- src/odbcdriver/ScalarType.h | 1 - src/odbcdriver/Type.cpp | 24 +- src/odbcdriver/Type.h | 43 +-- src/odbcdriver/helper.cpp | 2 +- src/odbcdriver/odbc_communication.cpp | 64 ++-- src/odbcdriver/odbc_communication.h | 12 +- src/odbcdriver/odbc_statement.cpp | 2 +- src/odbcdriver/parse_result.cpp | 59 ++- src/odbcdriver/parse_result.h | 10 +- src/odbcdriver/prefetch_queue.cpp | 6 +- src/odbcdriver/prefetch_queue.h | 8 +- src/odbcdriver/types.h | 2 +- 44 files changed, 2593 insertions(+), 189 deletions(-) create mode 100644 src/odbcdriver/CancelQueryRequest.cpp create mode 100644 src/odbcdriver/CancelQueryRequest.h create mode 100644 src/odbcdriver/CancelQueryResult.cpp create mode 100644 src/odbcdriver/CancelQueryResult.h create mode 100644 src/odbcdriver/DatabaseQueryClient.cpp create mode 100644 src/odbcdriver/DatabaseQueryClient.h create mode 100644 src/odbcdriver/DatabaseQueryEndpoint.cpp create mode 100644 src/odbcdriver/DatabaseQueryEndpoint.h create mode 100644 src/odbcdriver/DatabaseQueryErrorMarshaller.cpp create mode 100644 src/odbcdriver/DatabaseQueryErrorMarshaller.h create mode 100644 src/odbcdriver/DatabaseQueryErrors.cpp create mode 100644 src/odbcdriver/DatabaseQueryErrors.h create mode 100644 src/odbcdriver/DatabaseQueryRequest.h create mode 100644 src/odbcdriver/DescribeEndpointsRequest.cpp create mode 100644 src/odbcdriver/DescribeEndpointsRequest.h create mode 100644 src/odbcdriver/DescribeEndpointsResult.cpp create mode 100644 src/odbcdriver/DescribeEndpointsResult.h create mode 100644 src/odbcdriver/Endpoint.cpp create mode 100644 src/odbcdriver/Endpoint.h create mode 100644 src/odbcdriver/QueryRequest.cpp create mode 100644 src/odbcdriver/QueryRequest.h create mode 100644 src/odbcdriver/QueryResult.cpp create mode 100644 src/odbcdriver/QueryResult.h create mode 100644 src/odbcdriver/QueryStatus.cpp create mode 100644 src/odbcdriver/QueryStatus.h diff --git a/src/Tests/ITODBCHelper/it_odbc_helper.cpp b/src/Tests/ITODBCHelper/it_odbc_helper.cpp index a2bbe4775..cb5b30a2f 100644 --- a/src/Tests/ITODBCHelper/it_odbc_helper.cpp +++ b/src/Tests/ITODBCHelper/it_odbc_helper.cpp @@ -285,7 +285,6 @@ void CompareStrNumChar(const test_string& expected, const SQLINTEGER num_chars, test_string conn_string() { std::vector< std::pair< test_string, test_string > > conn_str_pair = { {IT_DRIVER, CREATE_STRING("timestreamodbc")}, - {IT_REGION, CREATE_STRING("us-east-1")}, {IT_AUTH, CREATE_STRING("AWS_PROFILE")}, {IT_LOGLEVEL, CREATE_STRING("5")}}; // DEBUG level logging @@ -301,7 +300,6 @@ test_string conn_string() { test_string perf_conn_string() { std::vector< std::pair< test_string, test_string > > conn_str_pair = { {IT_DRIVER, CREATE_STRING("timestreamodbc")}, - {IT_REGION, CREATE_STRING("us-east-2")}, {IT_AUTH, CREATE_STRING("AWS_PROFILE")}, {IT_LOGLEVEL, CREATE_STRING("0")}}; diff --git a/src/Tests/ITODBCHelper/it_odbc_helper.h b/src/Tests/ITODBCHelper/it_odbc_helper.h index 5db172ff7..d0d98c8c3 100644 --- a/src/Tests/ITODBCHelper/it_odbc_helper.h +++ b/src/Tests/ITODBCHelper/it_odbc_helper.h @@ -75,7 +75,6 @@ test_string to_test_string(const std::string& src); #define IT_DRIVER CREATE_STRING("Driver") #define IT_ACCESSKEYID CREATE_STRING("AccessKeyId") #define IT_SECRETACCESSKEY CREATE_STRING"SecretAccessKey") -#define IT_REGION CREATE_STRING("Region") #define IT_AUTH CREATE_STRING("Auth") #define IT_LOGLEVEL CREATE_STRING("LogLevel") #define IT_LOGOUTPUT CREATE_STRING("LogOutput") diff --git a/src/Tests/Tests/test_conn.cpp b/src/Tests/Tests/test_conn.cpp index 6b6980073..544549523 100644 --- a/src/Tests/Tests/test_conn.cpp +++ b/src/Tests/Tests/test_conn.cpp @@ -31,7 +31,7 @@ TEST(TestConnectionOptions, Good) { options.auth.uid = "UID"; options.auth.pwd = "PWD"; options.auth.auth_type = AUTHTYPE_DEFAULT; - TSCommunication conn; + DBCommunication conn; EXPECT_NO_THROW(conn.Validate(options)); EXPECT_TRUE(conn.Validate(options)); } @@ -41,7 +41,7 @@ TEST(TestConnectionOptions, UID_is_empty) { options.auth.uid = ""; options.auth.pwd = "PWD"; options.auth.auth_type = AUTHTYPE_DEFAULT; - TSCommunication conn; + DBCommunication conn; EXPECT_THROW(conn.Validate(options), std::invalid_argument); } @@ -50,7 +50,7 @@ TEST(TestConnectionOptions, PWD_is_empty) { options.auth.uid = "UID"; options.auth.pwd = ""; options.auth.auth_type = AUTHTYPE_DEFAULT; - TSCommunication conn; + DBCommunication conn; EXPECT_THROW(conn.Validate(options), std::invalid_argument); } @@ -59,7 +59,7 @@ TEST(TestConnectionOptions, Auth_type_is_empty) { options.auth.uid = "UID"; options.auth.pwd = "PWD"; options.auth.auth_type = ""; - TSCommunication conn; + DBCommunication conn; EXPECT_THROW(conn.Validate(options), std::invalid_argument); } @@ -69,12 +69,12 @@ TEST(TestConnectionOptions, Timeout_is_alpha) { options.auth.pwd = "PWD"; options.auth.auth_type = ""; options.conn.timeout = "timeout"; - TSCommunication conn; + DBCommunication conn; EXPECT_THROW(conn.Validate(options), std::invalid_argument); } TEST(TestGetUserAgent, Success) { - TSCommunication conn; + DBCommunication conn; std::string expected = "ts-odbc." TIMESTREAMDRIVERVERSION " [tests]"; EXPECT_EQ(expected, conn.GetUserAgent()); } diff --git a/src/odbcdriver/CMakeLists.txt b/src/odbcdriver/CMakeLists.txt index 1e0d5d0fe..06f63ada9 100644 --- a/src/odbcdriver/CMakeLists.txt +++ b/src/odbcdriver/CMakeLists.txt @@ -56,7 +56,19 @@ set(CPP_SOURCE_FILES communication.cpp utility.cpp odbc_communication.cpp prefetch_queue.cpp + CancelQueryRequest.cpp + CancelQueryResult.cpp ColumnInfo.cpp + DatabaseQueryClient.cpp + DatabaseQueryEndpoint.cpp + DatabaseQueryErrors.cpp + DatabaseQueryErrorMarshaller.cpp + DescribeEndpointsRequest.cpp + DescribeEndpointsResult.cpp + Endpoint.cpp + QueryRequest.cpp + QueryResult.cpp + QueryStatus.cpp Row.cpp ScalarType.cpp Type.cpp @@ -100,7 +112,20 @@ set(CPP_HEADER_FILES communication.h odbc_communication.h prefetch_queue.h version.h + CancelQueryRequest.h + CancelQueryResult.h ColumnInfo.h + DatabaseQueryClient.h + DatabaseQueryEndpoint.h + DatabaseQueryErrors.h + DatabaseQueryErrorMarshaller.h + DatabaseQueryRequest.h + DescribeEndpointsRequest.h + DescribeEndpointsResult.h + Endpoint.h + QueryRequest.h + QueryResult.h + QueryStatus.h Row.h ScalarType.h Type.h diff --git a/src/odbcdriver/CancelQueryRequest.cpp b/src/odbcdriver/CancelQueryRequest.cpp new file mode 100644 index 000000000..e52a955be --- /dev/null +++ b/src/odbcdriver/CancelQueryRequest.cpp @@ -0,0 +1,33 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include "CancelQueryRequest.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; + +CancelQueryRequest::CancelQueryRequest() : m_queryIdHasBeenSet(false) { +} + +Aws::String CancelQueryRequest::SerializePayload() const { + JsonValue payload; + + if (m_queryIdHasBeenSet) { + payload.WithString("QueryId", m_queryId); + } + + return payload.View().WriteReadable(); +} + +Aws::Http::HeaderValueCollection CancelQueryRequest::GetRequestSpecificHeaders() + const { + Aws::Http::HeaderValueCollection headers; + headers.insert(Aws::Http::HeaderValuePair( + "X-Amz-Target", "Timestream_20181101.CancelQuery")); + return headers; +} \ No newline at end of file diff --git a/src/odbcdriver/CancelQueryRequest.h b/src/odbcdriver/CancelQueryRequest.h new file mode 100644 index 000000000..a201e826e --- /dev/null +++ b/src/odbcdriver/CancelQueryRequest.h @@ -0,0 +1,103 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include + +#include "DatabaseQueryRequest.h" + +#include + +class CancelQueryRequest : public DatabaseQueryRequest { + public: + CancelQueryRequest(); + + // Service request name is the Operation name which will send this request + // out, each operation should has unique request name, so that we can get + // operation's name from this request. Note: this is not true for response, + // multiple operations may have the same response name, so we can not get + // operation's name from response. + inline virtual const char* GetServiceRequestName() const override { + return "CancelQuery"; + } + + Aws::String SerializePayload() const override; + + Aws::Http::HeaderValueCollection GetRequestSpecificHeaders() const override; + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline const Aws::String& GetQueryId() const { + return m_queryId; + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline bool QueryIdHasBeenSet() const { + return m_queryIdHasBeenSet; + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline void SetQueryId(const Aws::String& value) { + m_queryIdHasBeenSet = true; + m_queryId = value; + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline void SetQueryId(Aws::String&& value) { + m_queryIdHasBeenSet = true; + m_queryId = std::move(value); + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline void SetQueryId(const char* value) { + m_queryIdHasBeenSet = true; + m_queryId.assign(value); + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline CancelQueryRequest& WithQueryId(const Aws::String& value) { + SetQueryId(value); + return *this; + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline CancelQueryRequest& WithQueryId(Aws::String&& value) { + SetQueryId(std::move(value)); + return *this; + } + + /** + *

The id of the query that needs to be cancelled. QueryID + * is returned as part of QueryResult.

+ */ + inline CancelQueryRequest& WithQueryId(const char* value) { + SetQueryId(value); + return *this; + } + + private: + Aws::String m_queryId; + bool m_queryIdHasBeenSet; +}; \ No newline at end of file diff --git a/src/odbcdriver/CancelQueryResult.cpp b/src/odbcdriver/CancelQueryResult.cpp new file mode 100644 index 000000000..002e29164 --- /dev/null +++ b/src/odbcdriver/CancelQueryResult.cpp @@ -0,0 +1,34 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include +#include +#include +#include "CancelQueryResult.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; +using namespace Aws; + +CancelQueryResult::CancelQueryResult() { +} + +CancelQueryResult::CancelQueryResult( + const Aws::AmazonWebServiceResult< JsonValue >& result) { + *this = result; +} + +CancelQueryResult& CancelQueryResult::operator=( + const Aws::AmazonWebServiceResult< JsonValue >& result) { + JsonView jsonValue = result.GetPayload().View(); + if (jsonValue.ValueExists("CancellationMessage")) { + m_cancellationMessage = jsonValue.GetString("CancellationMessage"); + } + + return *this; +} diff --git a/src/odbcdriver/CancelQueryResult.h b/src/odbcdriver/CancelQueryResult.h new file mode 100644 index 000000000..e1c3eda1c --- /dev/null +++ b/src/odbcdriver/CancelQueryResult.h @@ -0,0 +1,101 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include + +#include + +namespace Aws { +template < typename RESULT_TYPE > +class AmazonWebServiceResult; + +namespace Utils { +namespace Json { +class JsonValue; +} // namespace Json +} // namespace Utils +} // namespace Aws + +class CancelQueryResult { + public: + CancelQueryResult(); + CancelQueryResult( + const Aws::AmazonWebServiceResult< Aws::Utils::Json::JsonValue >& + result); + CancelQueryResult& operator=( + const Aws::AmazonWebServiceResult< Aws::Utils::Json::JsonValue >& + result); + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline const Aws::String& GetCancellationMessage() const { + return m_cancellationMessage; + } + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline void SetCancellationMessage(const Aws::String& value) { + m_cancellationMessage = value; + } + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline void SetCancellationMessage(Aws::String&& value) { + m_cancellationMessage = std::move(value); + } + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline void SetCancellationMessage(const char* value) { + m_cancellationMessage.assign(value); + } + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline CancelQueryResult& WithCancellationMessage( + const Aws::String& value) { + SetCancellationMessage(value); + return *this; + } + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline CancelQueryResult& WithCancellationMessage(Aws::String&& value) { + SetCancellationMessage(std::move(value)); + return *this; + } + + /** + *

A CancellationMessage is returned when a + * CancelQuery request for the query specified by + * QueryId has already been issued.

+ */ + inline CancelQueryResult& WithCancellationMessage(const char* value) { + SetCancellationMessage(value); + return *this; + } + + private: + Aws::String m_cancellationMessage; +}; diff --git a/src/odbcdriver/ColumnInfo.h b/src/odbcdriver/ColumnInfo.h index 8d1dc8102..8db0ce465 100644 --- a/src/odbcdriver/ColumnInfo.h +++ b/src/odbcdriver/ColumnInfo.h @@ -4,12 +4,19 @@ */ #pragma once -#include #include -#include #include #include +namespace Aws { +namespace Utils { +namespace Json { +class JsonValue; +class JsonView; +} // namespace Json +} // namespace Utils +} // namespace Aws + class Type; /** diff --git a/src/odbcdriver/DatabaseQueryClient.cpp b/src/odbcdriver/DatabaseQueryClient.cpp new file mode 100644 index 000000000..822714b4b --- /dev/null +++ b/src/odbcdriver/DatabaseQueryClient.cpp @@ -0,0 +1,340 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "DatabaseQueryClient.h" +#include "DatabaseQueryEndpoint.h" +#include "DatabaseQueryErrorMarshaller.h" +#include "CancelQueryRequest.h" +#include "DescribeEndpointsRequest.h" +#include "QueryRequest.h" + +using namespace Aws; +using namespace Aws::Auth; +using namespace Aws::Client; +using namespace Aws::Http; +using namespace Aws::Utils::Json; + +static const char* SERVICE_NAME = "database"; +static const char* ALLOCATION_TAG = "DatabaseQueryClient"; + +DatabaseQueryClient::DatabaseQueryClient( + const Client::ClientConfiguration& clientConfiguration) + : BASECLASS( + clientConfiguration, + Aws::MakeShared< AWSAuthV4Signer >( + ALLOCATION_TAG, + Aws::MakeShared< DefaultAWSCredentialsProviderChain >( + ALLOCATION_TAG), + SERVICE_NAME, + Aws::Region::ComputeSignerRegion(clientConfiguration.region)), + Aws::MakeShared< DatabaseQueryErrorMarshaller >(ALLOCATION_TAG)), + m_executor(clientConfiguration.executor) { + init(clientConfiguration); +} + +DatabaseQueryClient::DatabaseQueryClient( + const AWSCredentials& credentials, + const Client::ClientConfiguration& clientConfiguration) + : BASECLASS( + clientConfiguration, + Aws::MakeShared< AWSAuthV4Signer >( + ALLOCATION_TAG, + Aws::MakeShared< SimpleAWSCredentialsProvider >(ALLOCATION_TAG, + credentials), + SERVICE_NAME, + Aws::Region::ComputeSignerRegion(clientConfiguration.region)), + Aws::MakeShared< DatabaseQueryErrorMarshaller >(ALLOCATION_TAG)), + m_executor(clientConfiguration.executor) { + init(clientConfiguration); +} + +DatabaseQueryClient::DatabaseQueryClient( + const std::shared_ptr< AWSCredentialsProvider >& credentialsProvider, + const Client::ClientConfiguration& clientConfiguration) + : BASECLASS( + clientConfiguration, + Aws::MakeShared< AWSAuthV4Signer >( + ALLOCATION_TAG, credentialsProvider, SERVICE_NAME, + Aws::Region::ComputeSignerRegion(clientConfiguration.region)), + Aws::MakeShared< DatabaseQueryErrorMarshaller >(ALLOCATION_TAG)), + m_executor(clientConfiguration.executor) { + init(clientConfiguration); +} + +DatabaseQueryClient::~DatabaseQueryClient() { +} + +void DatabaseQueryClient::init(const Client::ClientConfiguration& config) { + SetServiceClientName("Database Query"); + LoadDatabaseQuerySpecificConfig(config); + m_configScheme = SchemeMapper::ToString(config.scheme); + if (config.endpointOverride.empty()) { + m_uri = m_configScheme + "://" + + DatabaseQueryEndpoint::ForRegion(config.region, + config.useDualStack); + } else { + OverrideEndpoint(config.endpointOverride); + } +} + +void DatabaseQueryClient::LoadDatabaseQuerySpecificConfig( + const Aws::Client::ClientConfiguration& clientConfiguration) { + if (!clientConfiguration.endpointOverride.empty()) { + m_enableEndpointDiscovery = false; + } else if (clientConfiguration.enableEndpointDiscovery) { + m_enableEndpointDiscovery = + clientConfiguration.enableEndpointDiscovery.value(); + } else { + m_enableEndpointDiscovery = true; + + Aws::String enableEndpointDiscovery = + Aws::Environment::GetEnv("AWS_ENABLE_ENDPOINT_DISCOVERY"); + if (enableEndpointDiscovery.empty()) { + enableEndpointDiscovery = Aws::Config::GetCachedConfigValue( + clientConfiguration.profileName, "endpoint_discovery_enabled"); + } + + if (enableEndpointDiscovery == "true") { + m_enableEndpointDiscovery = true; + } else if (enableEndpointDiscovery == "false") { + m_enableEndpointDiscovery = false; + } else if (!enableEndpointDiscovery.empty()) { + AWS_LOGSTREAM_WARN( + "DatabaseQueryClient", + R"(Using the SDK default configuration for Endpoint Discovery. )" + R"(Make sure your environment variable "AWS_ENABLE_ENDPOINT_DISCOVERY" or )" + R"(your config file's variable "endpoint_discovery_enabled" are explicitly set to "true" or "false" (case-sensitive) or not set at all.)"); + } + } +} + +void DatabaseQueryClient::OverrideEndpoint(const Aws::String& endpoint) { + if (endpoint.compare(0, 7, "http://") == 0 + || endpoint.compare(0, 8, "https://") == 0) { + m_uri = endpoint; + } else { + m_uri = m_configScheme + "://" + endpoint; + } + m_enableEndpointDiscovery = false; +} + +CancelQueryOutcome DatabaseQueryClient::CancelQuery( + const CancelQueryRequest& request) const { + Aws::Http::URI uri = m_uri; + if (m_enableEndpointDiscovery) { + Aws::String endpointKey = "Shared"; + Aws::String endpoint; + if (m_endpointsCache.Get(endpointKey, endpoint)) { + AWS_LOGSTREAM_TRACE( + "CancelQuery", + "Making request to cached endpoint: " << endpoint); + uri = m_configScheme + "://" + endpoint; + } else { + AWS_LOGSTREAM_TRACE( + "CancelQuery", + "Endpoint discovery is enabled and there is no usable endpoint " + "in cache. Discovering endpoints from service..."); + DescribeEndpointsRequest endpointRequest; + auto endpointOutcome = DescribeEndpoints(endpointRequest); + if (endpointOutcome.IsSuccess() + && !endpointOutcome.GetResult().GetEndpoints().empty()) { + const auto& item = + endpointOutcome.GetResult().GetEndpoints()[0]; + m_endpointsCache.Put( + endpointKey, item.GetAddress(), + std::chrono::minutes(item.GetCachePeriodInMinutes())); + uri = m_configScheme + "://" + item.GetAddress(); + AWS_LOGSTREAM_TRACE("CancelQuery", + "Endpoints cache updated. Address: " + << item.GetAddress() << ". Valid in: " + << item.GetCachePeriodInMinutes() + << " minutes. Making request to newly " + "discovered endpoint."); + } else { + AWS_LOGSTREAM_ERROR("CancelQuery", + "Failed to discover endpoints " + << endpointOutcome.GetError()); + return CancelQueryOutcome( + Aws::Client::AWSError< DatabaseQueryErrors >( + DatabaseQueryErrors::RESOURCE_NOT_FOUND, + "INVALID_ENDPOINT", "Failed to discover endpoint", + false)); + } + } + } else { + Aws::String errorMessage = + R"(Unable to perform "CancelQuery" without endpoint discovery. )" + R"(Make sure your environment variable "AWS_ENABLE_ENDPOINT_DISCOVERY", )" + R"(your config file's variable "endpoint_discovery_enabled" and )" + R"(ClientConfiguration's "enableEndpointDiscovery" are explicitly set to true or not set at all.)"; + return CancelQueryOutcome( + Aws::Client::AWSError< DatabaseQueryErrors >( + DatabaseQueryErrors::INVALID_ACTION, "INVALID_ACTION", + errorMessage, false)); + } + return CancelQueryOutcome(MakeRequest(uri, request, + Aws::Http::HttpMethod::HTTP_POST, + Aws::Auth::SIGV4_SIGNER)); +} + +CancelQueryOutcomeCallable DatabaseQueryClient::CancelQueryCallable( + const CancelQueryRequest& request) const { + auto task = Aws::MakeShared< std::packaged_task< CancelQueryOutcome() > >( + ALLOCATION_TAG, + [this, request]() { return this->CancelQuery(request); }); + auto packagedFunction = [task]() { (*task)(); }; + m_executor->Submit(packagedFunction); + return task->get_future(); +} + +void DatabaseQueryClient::CancelQueryAsync( + const CancelQueryRequest& request, + const CancelQueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const { + m_executor->Submit([this, request, handler, context]() { + this->CancelQueryAsyncHelper(request, handler, context); + }); +} + +void DatabaseQueryClient::CancelQueryAsyncHelper( + const CancelQueryRequest& request, + const CancelQueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const { + handler(this, request, CancelQuery(request), context); +} + +DescribeEndpointsOutcome DatabaseQueryClient::DescribeEndpoints( + const DescribeEndpointsRequest& request) const { + Aws::Http::URI uri = m_uri; + return DescribeEndpointsOutcome( + MakeRequest(uri, request, Aws::Http::HttpMethod::HTTP_POST, + Aws::Auth::SIGV4_SIGNER)); +} + +DescribeEndpointsOutcomeCallable +DatabaseQueryClient::DescribeEndpointsCallable( + const DescribeEndpointsRequest& request) const { + auto task = + Aws::MakeShared< std::packaged_task< DescribeEndpointsOutcome() > >( + ALLOCATION_TAG, + [this, request]() { return this->DescribeEndpoints(request); }); + auto packagedFunction = [task]() { (*task)(); }; + m_executor->Submit(packagedFunction); + return task->get_future(); +} + +void DatabaseQueryClient::DescribeEndpointsAsync( + const DescribeEndpointsRequest& request, + const DescribeEndpointsResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const { + m_executor->Submit([this, request, handler, context]() { + this->DescribeEndpointsAsyncHelper(request, handler, context); + }); +} + +void DatabaseQueryClient::DescribeEndpointsAsyncHelper( + const DescribeEndpointsRequest& request, + const DescribeEndpointsResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const { + handler(this, request, DescribeEndpoints(request), context); +} + +QueryOutcome DatabaseQueryClient::Query(const QueryRequest& request) const { + Aws::Http::URI uri = m_uri; + if (m_enableEndpointDiscovery) { + Aws::String endpointKey = "Shared"; + Aws::String endpoint; + if (m_endpointsCache.Get(endpointKey, endpoint)) { + AWS_LOGSTREAM_TRACE( + "Query", "Making request to cached endpoint: " << endpoint); + uri = m_configScheme + "://" + endpoint; + } else { + AWS_LOGSTREAM_TRACE( + "Query", + "Endpoint discovery is enabled and there is no usable endpoint " + "in cache. Discovering endpoints from service..."); + DescribeEndpointsRequest endpointRequest; + auto endpointOutcome = DescribeEndpoints(endpointRequest); + if (endpointOutcome.IsSuccess() + && !endpointOutcome.GetResult().GetEndpoints().empty()) { + const auto& item = + endpointOutcome.GetResult().GetEndpoints()[0]; + m_endpointsCache.Put( + endpointKey, item.GetAddress(), + std::chrono::minutes(item.GetCachePeriodInMinutes())); + uri = m_configScheme + "://" + item.GetAddress(); + AWS_LOGSTREAM_TRACE("Query", + "Endpoints cache updated. Address: " + << item.GetAddress() << ". Valid in: " + << item.GetCachePeriodInMinutes() + << " minutes. Making request to newly " + "discovered endpoint."); + } else { + AWS_LOGSTREAM_ERROR("Query", "Failed to discover endpoints " + << endpointOutcome.GetError()); + return QueryOutcome( + Aws::Client::AWSError< DatabaseQueryErrors >( + DatabaseQueryErrors::RESOURCE_NOT_FOUND, + "INVALID_ENDPOINT", "Failed to discover endpoint", + false)); + } + } + } else { + Aws::String errorMessage = + R"(Unable to perform "Query" without endpoint discovery. )" + R"(Make sure your environment variable "AWS_ENABLE_ENDPOINT_DISCOVERY", )" + R"(your config file's variable "endpoint_discovery_enabled" and )" + R"(ClientConfiguration's "enableEndpointDiscovery" are explicitly set to true or not set at all.)"; + return QueryOutcome(Aws::Client::AWSError< DatabaseQueryErrors >( + DatabaseQueryErrors::INVALID_ACTION, "INVALID_ACTION", + errorMessage, false)); + } + return QueryOutcome(MakeRequest(uri, request, + Aws::Http::HttpMethod::HTTP_POST, + Aws::Auth::SIGV4_SIGNER)); +} + +QueryOutcomeCallable DatabaseQueryClient::QueryCallable( + const QueryRequest& request) const { + auto task = Aws::MakeShared< std::packaged_task< QueryOutcome() > >( + ALLOCATION_TAG, [this, request]() { return this->Query(request); }); + auto packagedFunction = [task]() { (*task)(); }; + m_executor->Submit(packagedFunction); + return task->get_future(); +} + +void DatabaseQueryClient::QueryAsync( + const QueryRequest& request, const QueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const { + m_executor->Submit([this, request, handler, context]() { + this->QueryAsyncHelper(request, handler, context); + }); +} + +void DatabaseQueryClient::QueryAsyncHelper( + const QueryRequest& request, const QueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const { + handler(this, request, Query(request), context); +} diff --git a/src/odbcdriver/DatabaseQueryClient.h b/src/odbcdriver/DatabaseQueryClient.h new file mode 100644 index 000000000..5ae9ddfa2 --- /dev/null +++ b/src/odbcdriver/DatabaseQueryClient.h @@ -0,0 +1,304 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "CancelQueryResult.h" +#include "DatabaseQueryErrors.h" +#include "DescribeEndpointsResult.h" +#include "QueryResult.h" + +namespace Aws { + +namespace Http { +class HttpClient; +class HttpClientFactory; +} // namespace Http + +namespace Utils { +template < typename R, typename E > +class Outcome; +namespace Threading { +class Executor; +} // namespace Threading +} // namespace Utils + +namespace Auth { +class AWSCredentials; +class AWSCredentialsProvider; +} // namespace Auth + +namespace Client { +class RetryStrategy; +} // namespace Client +} // namespace Aws + +class CancelQueryRequest; +class DescribeEndpointsRequest; +class QueryRequest; + +typedef Aws::Utils::Outcome< CancelQueryResult, DatabaseQueryError > + CancelQueryOutcome; +typedef Aws::Utils::Outcome< DescribeEndpointsResult, DatabaseQueryError > + DescribeEndpointsOutcome; +typedef Aws::Utils::Outcome< QueryResult, DatabaseQueryError > QueryOutcome; + +typedef std::future< CancelQueryOutcome > CancelQueryOutcomeCallable; +typedef std::future< DescribeEndpointsOutcome > + DescribeEndpointsOutcomeCallable; +typedef std::future< QueryOutcome > QueryOutcomeCallable; + +class DatabaseQueryClient; + +typedef std::function< void( + const DatabaseQueryClient*, const CancelQueryRequest&, + const CancelQueryOutcome&, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >&) > + CancelQueryResponseReceivedHandler; +typedef std::function< void( + const DatabaseQueryClient*, const DescribeEndpointsRequest&, + const DescribeEndpointsOutcome&, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >&) > + DescribeEndpointsResponseReceivedHandler; +typedef std::function< void( + const DatabaseQueryClient*, const QueryRequest&, + const QueryOutcome&, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >&) > + QueryResponseReceivedHandler; + +/** + *

+ */ +class DatabaseQueryClient : public Aws::Client::AWSJsonClient { + public: + typedef Aws::Client::AWSJsonClient BASECLASS; + + /** + * Initializes client to use DefaultCredentialProviderChain, with default + * http client factory, and optional client config. If client config is not + * specified, it will be initialized to default values. + */ + DatabaseQueryClient( + const Aws::Client::ClientConfiguration& clientConfiguration = + Aws::Client::ClientConfiguration()); + + /** + * Initializes client to use SimpleAWSCredentialsProvider, with default http + * client factory, and optional client config. If client config is not + * specified, it will be initialized to default values. + */ + DatabaseQueryClient( + const Aws::Auth::AWSCredentials& credentials, + const Aws::Client::ClientConfiguration& clientConfiguration = + Aws::Client::ClientConfiguration()); + + /** + * Initializes client to use specified credentials provider with specified + * client config. If http client factory is not supplied, the default http + * client factory will be used + */ + DatabaseQueryClient( + const std::shared_ptr< Aws::Auth::AWSCredentialsProvider >& + credentialsProvider, + const Aws::Client::ClientConfiguration& clientConfiguration = + Aws::Client::ClientConfiguration()); + + virtual ~DatabaseQueryClient(); + + /** + *

Cancels a query that has been issued. Cancellation is guaranteed only + * if the query has not completed execution before the cancellation request + * was issued. Because cancellation is an idempotent operation, subsequent + * cancellation requests will return a CancellationMessage, + * indicating that the query has already been canceled.

See + * Also:

AWS + * API Reference

+ */ + virtual CancelQueryOutcome CancelQuery( + const CancelQueryRequest& request) const; + + /** + *

Cancels a query that has been issued. Cancellation is guaranteed only + * if the query has not completed execution before the cancellation request + * was issued. Because cancellation is an idempotent operation, subsequent + * cancellation requests will return a CancellationMessage, + * indicating that the query has already been canceled.

See + * Also:

AWS + * API Reference

+ * + * returns a future to the operation so that it can be executed in parallel + * to other requests. + */ + virtual CancelQueryOutcomeCallable CancelQueryCallable( + const CancelQueryRequest& request) const; + + /** + *

Cancels a query that has been issued. Cancellation is guaranteed only + * if the query has not completed execution before the cancellation request + * was issued. Because cancellation is an idempotent operation, subsequent + * cancellation requests will return a CancellationMessage, + * indicating that the query has already been canceled.

See + * Also:

AWS + * API Reference

+ * + * Queues the request into a thread executor and triggers associated + * callback when operation has finished. + */ + virtual void CancelQueryAsync( + const CancelQueryRequest& request, + const CancelQueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& + context = nullptr) const; + + /** + *

DescribeEndpoints returns a list of available endpoints to make + * Timestream API calls against. This API is available through both Write + * and Query.

Because Timestream’s SDKs are designed to transparently + * work with the service’s architecture, including the management and + * mapping of the service endpoints, it is not recommended that you use + * this API unless:

  • Your application uses a programming + * language that does not yet have SDK support

  • You require + * better control over the client-side implementation

For + * detailed information on how to use DescribeEndpoints, see The + * Endpoint Discovery Pattern and REST APIs.

See Also:

AWS + * API Reference

+ */ + virtual DescribeEndpointsOutcome DescribeEndpoints( + const DescribeEndpointsRequest& request) const; + + /** + *

DescribeEndpoints returns a list of available endpoints to make + * Timestream API calls against. This API is available through both Write + * and Query.

Because Timestream’s SDKs are designed to transparently + * work with the service’s architecture, including the management and + * mapping of the service endpoints, it is not recommended that you use + * this API unless:

  • Your application uses a programming + * language that does not yet have SDK support

  • You require + * better control over the client-side implementation

For + * detailed information on how to use DescribeEndpoints, see The + * Endpoint Discovery Pattern and REST APIs.

See Also:

AWS + * API Reference

+ * + * returns a future to the operation so that it can be executed in parallel + * to other requests. + */ + virtual DescribeEndpointsOutcomeCallable DescribeEndpointsCallable( + const DescribeEndpointsRequest& request) const; + + /** + *

DescribeEndpoints returns a list of available endpoints to make + * Timestream API calls against. This API is available through both Write + * and Query.

Because Timestream’s SDKs are designed to transparently + * work with the service’s architecture, including the management and + * mapping of the service endpoints, it is not recommended that you use + * this API unless:

  • Your application uses a programming + * language that does not yet have SDK support

  • You require + * better control over the client-side implementation

For + * detailed information on how to use DescribeEndpoints, see The + * Endpoint Discovery Pattern and REST APIs.

See Also:

AWS + * API Reference

+ * + * Queues the request into a thread executor and triggers associated + * callback when operation has finished. + */ + virtual void DescribeEndpointsAsync( + const DescribeEndpointsRequest& request, + const DescribeEndpointsResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& + context = nullptr) const; + + /** + *

Query is a synchronous operation that enables you to execute a query. + * Query will timeout after 60 seconds. You must update the default timeout + * in the SDK to support a timeout of 60 seconds. The result set will be + * truncated to 1MB. Service quotas apply. For more information, see Quotas + * in the Timestream Developer Guide.

See Also:

AWS + * API Reference

+ */ + virtual QueryOutcome Query(const QueryRequest& request) const; + + /** + *

Query is a synchronous operation that enables you to execute a query. + * Query will timeout after 60 seconds. You must update the default timeout + * in the SDK to support a timeout of 60 seconds. The result set will be + * truncated to 1MB. Service quotas apply. For more information, see Quotas + * in the Timestream Developer Guide.

See Also:

AWS + * API Reference

+ * + * returns a future to the operation so that it can be executed in parallel + * to other requests. + */ + virtual QueryOutcomeCallable QueryCallable( + const QueryRequest& request) const; + + /** + *

Query is a synchronous operation that enables you to execute a query. + * Query will timeout after 60 seconds. You must update the default timeout + * in the SDK to support a timeout of 60 seconds. The result set will be + * truncated to 1MB. Service quotas apply. For more information, see Quotas + * in the Timestream Developer Guide.

See Also:

AWS + * API Reference

+ * + * Queues the request into a thread executor and triggers associated + * callback when operation has finished. + */ + virtual void QueryAsync( + const QueryRequest& request, + const QueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& + context = nullptr) const; + + void OverrideEndpoint(const Aws::String& endpoint); + + private: + void init(const Aws::Client::ClientConfiguration& clientConfiguration); + void LoadDatabaseQuerySpecificConfig( + const Aws::Client::ClientConfiguration& clientConfiguration); + void CancelQueryAsyncHelper( + const CancelQueryRequest& request, + const CancelQueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const; + void DescribeEndpointsAsyncHelper( + const DescribeEndpointsRequest& request, + const DescribeEndpointsResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const; + void QueryAsyncHelper( + const QueryRequest& request, + const QueryResponseReceivedHandler& handler, + const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) + const; + + Aws::String m_uri; + mutable Aws::Utils::ConcurrentCache< Aws::String, Aws::String > + m_endpointsCache; + bool m_enableEndpointDiscovery; + Aws::String m_configScheme; + std::shared_ptr< Aws::Utils::Threading::Executor > m_executor; +}; \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryEndpoint.cpp b/src/odbcdriver/DatabaseQueryEndpoint.cpp new file mode 100644 index 000000000..10fa0b820 --- /dev/null +++ b/src/odbcdriver/DatabaseQueryEndpoint.cpp @@ -0,0 +1,49 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include +#include "DatabaseQueryEndpoint.h" + +namespace DatabaseQueryEndpoint { +static const int CN_NORTH_1_HASH = + Aws::Utils::HashingUtils::HashString("cn-north-1"); +static const int CN_NORTHWEST_1_HASH = + Aws::Utils::HashingUtils::HashString("cn-northwest-1"); +static const int US_ISO_EAST_1_HASH = + Aws::Utils::HashingUtils::HashString("us-iso-east-1"); +static const int US_ISOB_EAST_1_HASH = + Aws::Utils::HashingUtils::HashString("us-isob-east-1"); + +Aws::String ForRegion(const Aws::String& regionName, bool useDualStack) { + // Fallback to us-east-1 if global endpoint does not exists. + Aws::String region = regionName == Aws::Region::AWS_GLOBAL + ? Aws::Region::US_EAST_1 + : regionName; + auto hash = Aws::Utils::HashingUtils::HashString(region.c_str()); + + Aws::StringStream ss; + ss << "query.database" + << "."; + + if (useDualStack) { + ss << "dualstack."; + } + + ss << region; + + if (hash == CN_NORTH_1_HASH || hash == CN_NORTHWEST_1_HASH) { + ss << ".amazonaws.com.cn"; + } else if (hash == US_ISO_EAST_1_HASH) { + ss << ".c2s.ic.gov"; + } else if (hash == US_ISOB_EAST_1_HASH) { + ss << ".sc2s.sgov.gov"; + } else { + ss << ".amazonaws.com"; + } + + return ss.str(); +} +} // namespace DatabaseQueryEndpoint \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryEndpoint.h b/src/odbcdriver/DatabaseQueryEndpoint.h new file mode 100644 index 000000000..c8c6d0d1e --- /dev/null +++ b/src/odbcdriver/DatabaseQueryEndpoint.h @@ -0,0 +1,13 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include +#include + +namespace DatabaseQueryEndpoint +{ +Aws::String ForRegion(const Aws::String& regionName, bool useDualStack = false); +} // namespace DatabaseQueryEndpoint \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryErrorMarshaller.cpp b/src/odbcdriver/DatabaseQueryErrorMarshaller.cpp new file mode 100644 index 000000000..ec822d223 --- /dev/null +++ b/src/odbcdriver/DatabaseQueryErrorMarshaller.cpp @@ -0,0 +1,21 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include "DatabaseQueryErrorMarshaller.h" +#include "DatabaseQueryErrors.h" + +using namespace Aws::Client; + +AWSError< CoreErrors > DatabaseQueryErrorMarshaller::FindErrorByName( + const char* errorName) const { + AWSError< CoreErrors > error = + DatabaseQueryErrorMapper::GetErrorForName(errorName); + if (error.GetErrorType() != CoreErrors::UNKNOWN) { + return error; + } + + return AWSErrorMarshaller::FindErrorByName(errorName); +} \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryErrorMarshaller.h b/src/odbcdriver/DatabaseQueryErrorMarshaller.h new file mode 100644 index 000000000..a6af2de25 --- /dev/null +++ b/src/odbcdriver/DatabaseQueryErrorMarshaller.h @@ -0,0 +1,14 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once + +#include + +class DatabaseQueryErrorMarshaller : public Aws::Client::JsonErrorMarshaller { + public: + Aws::Client::AWSError< Aws::Client::CoreErrors > FindErrorByName( + const char* exceptionName) const override; +}; \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryErrors.cpp b/src/odbcdriver/DatabaseQueryErrors.cpp new file mode 100644 index 000000000..3cd47829a --- /dev/null +++ b/src/odbcdriver/DatabaseQueryErrors.cpp @@ -0,0 +1,45 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include +#include "DatabaseQueryErrors.h" + +using namespace Aws::Client; +using namespace Aws::Utils; + +namespace DatabaseQueryErrorMapper +{ + +static const int INVALID_ENDPOINT_HASH = HashingUtils::HashString("InvalidEndpointException"); +static const int CONFLICT_HASH = HashingUtils::HashString("ConflictException"); +static const int INTERNAL_SERVER_HASH = HashingUtils::HashString("InternalServerException"); +static const int QUERY_EXECUTION_HASH = HashingUtils::HashString("QueryExecutionException"); + + +AWSError GetErrorForName(const char* errorName) +{ + int hashCode = HashingUtils::HashString(errorName); + + if (hashCode == INVALID_ENDPOINT_HASH) + { + return AWSError(static_cast(DatabaseQueryErrors::INVALID_ENDPOINT), false); + } + else if (hashCode == CONFLICT_HASH) + { + return AWSError(static_cast(DatabaseQueryErrors::CONFLICT), false); + } + else if (hashCode == INTERNAL_SERVER_HASH) + { + return AWSError(static_cast(DatabaseQueryErrors::INTERNAL_SERVER), false); + } + else if (hashCode == QUERY_EXECUTION_HASH) + { + return AWSError(static_cast(DatabaseQueryErrors::QUERY_EXECUTION), false); + } + return AWSError(CoreErrors::UNKNOWN, false); +} + +} // namespace DatabaseQueryErrorMapper \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryErrors.h b/src/odbcdriver/DatabaseQueryErrors.h new file mode 100644 index 000000000..1da78922f --- /dev/null +++ b/src/odbcdriver/DatabaseQueryErrors.h @@ -0,0 +1,77 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once + +#include +#include + +enum class DatabaseQueryErrors { + // From Core// + ////////////////////////////////////////////////////////////////////////////////////////// + INCOMPLETE_SIGNATURE = 0, + INTERNAL_FAILURE = 1, + INVALID_ACTION = 2, + INVALID_CLIENT_TOKEN_ID = 3, + INVALID_PARAMETER_COMBINATION = 4, + INVALID_QUERY_PARAMETER = 5, + INVALID_PARAMETER_VALUE = 6, + MISSING_ACTION = 7, // SDK should never allow + MISSING_AUTHENTICATION_TOKEN = 8, // SDK should never allow + MISSING_PARAMETER = 9, // SDK should never allow + OPT_IN_REQUIRED = 10, + REQUEST_EXPIRED = 11, + SERVICE_UNAVAILABLE = 12, + THROTTLING = 13, + VALIDATION = 14, + ACCESS_DENIED = 15, + RESOURCE_NOT_FOUND = 16, + UNRECOGNIZED_CLIENT = 17, + MALFORMED_QUERY_STRING = 18, + SLOW_DOWN = 19, + REQUEST_TIME_TOO_SKEWED = 20, + INVALID_SIGNATURE = 21, + SIGNATURE_DOES_NOT_MATCH = 22, + INVALID_ACCESS_KEY_ID = 23, + REQUEST_TIMEOUT = 24, + NETWORK_CONNECTION = 99, + + UNKNOWN = 100, + /////////////////////////////////////////////////////////////////////////////////////////// + + CONFLICT = static_cast< int >( + Aws::Client::CoreErrors::SERVICE_EXTENSION_START_RANGE) + + 1, + INTERNAL_SERVER, + INVALID_ENDPOINT, + QUERY_EXECUTION +}; + +class DatabaseQueryError : public Aws::Client::AWSError< DatabaseQueryErrors > { + public: + DatabaseQueryError() { + } + DatabaseQueryError( + const Aws::Client::AWSError< Aws::Client::CoreErrors >& rhs) + : Aws::Client::AWSError< DatabaseQueryErrors >(rhs) { + } + DatabaseQueryError(Aws::Client::AWSError< Aws::Client::CoreErrors >&& rhs) + : Aws::Client::AWSError< DatabaseQueryErrors >(rhs) { + } + DatabaseQueryError(const Aws::Client::AWSError< DatabaseQueryErrors >& rhs) + : Aws::Client::AWSError< DatabaseQueryErrors >(rhs) { + } + DatabaseQueryError(Aws::Client::AWSError< DatabaseQueryErrors >&& rhs) + : Aws::Client::AWSError< DatabaseQueryErrors >(rhs) { + } + + template < typename T > + T GetModeledError(); +}; + +namespace DatabaseQueryErrorMapper { +Aws::Client::AWSError< Aws::Client::CoreErrors > GetErrorForName( + const char* errorName); +} \ No newline at end of file diff --git a/src/odbcdriver/DatabaseQueryRequest.h b/src/odbcdriver/DatabaseQueryRequest.h new file mode 100644 index 000000000..aee9f760e --- /dev/null +++ b/src/odbcdriver/DatabaseQueryRequest.h @@ -0,0 +1,39 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include +#include +#include + +class DatabaseQueryRequest : public Aws::AmazonSerializableWebServiceRequest { + public: + virtual ~DatabaseQueryRequest() { + } + + void AddParametersToRequest(Aws::Http::HttpRequest& httpRequest) const { + AWS_UNREFERENCED_PARAM(httpRequest); + } + + inline Aws::Http::HeaderValueCollection GetHeaders() const override { + auto headers = GetRequestSpecificHeaders(); + + if (headers.size() == 0 + || (headers.size() > 0 + && headers.count(Aws::Http::CONTENT_TYPE_HEADER) == 0)) { + headers.emplace( + Aws::Http::HeaderValuePair(Aws::Http::CONTENT_TYPE_HEADER, + Aws::AMZN_JSON_CONTENT_TYPE_1_0)); + } + headers.emplace(Aws::Http::HeaderValuePair( + Aws::Http::API_VERSION_HEADER, "2018-11-01")); + return headers; + } + + protected: + virtual Aws::Http::HeaderValueCollection GetRequestSpecificHeaders() const { + return Aws::Http::HeaderValueCollection(); + } +}; \ No newline at end of file diff --git a/src/odbcdriver/Datum.h b/src/odbcdriver/Datum.h index 5881c4435..d0e712657 100644 --- a/src/odbcdriver/Datum.h +++ b/src/odbcdriver/Datum.h @@ -4,23 +4,19 @@ */ #pragma once -#include #include #include #include #include -namespace Aws -{ -namespace Utils -{ -namespace Json -{ - class JsonValue; - class JsonView; -} // namespace Json -} // namespace Utils -}// namespace Aws +namespace Aws { +namespace Utils { +namespace Json { +class JsonValue; +class JsonView; +} // namespace Json +} // namespace Utils +} // namespace Aws class Row; diff --git a/src/odbcdriver/DescribeEndpointsRequest.cpp b/src/odbcdriver/DescribeEndpointsRequest.cpp new file mode 100644 index 000000000..82d059e5e --- /dev/null +++ b/src/odbcdriver/DescribeEndpointsRequest.cpp @@ -0,0 +1,27 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include "DescribeEndpointsRequest.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; + +DescribeEndpointsRequest::DescribeEndpointsRequest() { +} + +Aws::String DescribeEndpointsRequest::SerializePayload() const { + return "{}"; +} + +Aws::Http::HeaderValueCollection +DescribeEndpointsRequest::GetRequestSpecificHeaders() const { + Aws::Http::HeaderValueCollection headers; + headers.insert(Aws::Http::HeaderValuePair( + "X-Amz-Target", "Database_20181101.DescribeEndpoints")); + return headers; +} diff --git a/src/odbcdriver/DescribeEndpointsRequest.h b/src/odbcdriver/DescribeEndpointsRequest.h new file mode 100644 index 000000000..9529af6bc --- /dev/null +++ b/src/odbcdriver/DescribeEndpointsRequest.h @@ -0,0 +1,28 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include "DatabaseQueryRequest.h" + +/** + */ +class DescribeEndpointsRequest + : public DatabaseQueryRequest { + public: + DescribeEndpointsRequest(); + + // Service request name is the Operation name which will send this request + // out, each operation should has unique request name, so that we can get + // operation's name from this request. Note: this is not true for response, + // multiple operations may have the same response name, so we can not get + // operation's name from response. + inline virtual const char* GetServiceRequestName() const override { + return "DescribeEndpoints"; + } + + Aws::String SerializePayload() const override; + + Aws::Http::HeaderValueCollection GetRequestSpecificHeaders() const override; +}; \ No newline at end of file diff --git a/src/odbcdriver/DescribeEndpointsResult.cpp b/src/odbcdriver/DescribeEndpointsResult.cpp new file mode 100644 index 000000000..da07bf9da --- /dev/null +++ b/src/odbcdriver/DescribeEndpointsResult.cpp @@ -0,0 +1,38 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include +#include +#include +#include "DescribeEndpointsResult.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; +using namespace Aws; + +DescribeEndpointsResult::DescribeEndpointsResult() { +} + +DescribeEndpointsResult::DescribeEndpointsResult( + const Aws::AmazonWebServiceResult< JsonValue >& result) { + *this = result; +} + +DescribeEndpointsResult& DescribeEndpointsResult::operator=( + const Aws::AmazonWebServiceResult< JsonValue >& result) { + JsonView jsonValue = result.GetPayload().View(); + if (jsonValue.ValueExists("Endpoints")) { + Array< JsonView > endpointsJsonList = jsonValue.GetArray("Endpoints"); + for (unsigned endpointsIndex = 0; + endpointsIndex < endpointsJsonList.GetLength(); ++endpointsIndex) { + m_endpoints.push_back(endpointsJsonList[endpointsIndex].AsObject()); + } + } + + return *this; +} diff --git a/src/odbcdriver/DescribeEndpointsResult.h b/src/odbcdriver/DescribeEndpointsResult.h new file mode 100644 index 000000000..b0f8cb309 --- /dev/null +++ b/src/odbcdriver/DescribeEndpointsResult.h @@ -0,0 +1,97 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include +#include + +#include "Endpoint.h" + +namespace Aws { +template < typename RESULT_TYPE > +class AmazonWebServiceResult; + +namespace Utils { +namespace Json { +class JsonValue; +} // namespace Json +} // namespace Utils +} // namespace Aws + +class DescribeEndpointsResult { + public: + DescribeEndpointsResult(); + DescribeEndpointsResult( + const Aws::AmazonWebServiceResult< Aws::Utils::Json::JsonValue >& + result); + DescribeEndpointsResult& operator=( + const Aws::AmazonWebServiceResult< Aws::Utils::Json::JsonValue >& + result); + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline const Aws::Vector< Endpoint >& GetEndpoints() const { + return m_endpoints; + } + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline void SetEndpoints(const Aws::Vector< Endpoint >& value) { + m_endpoints = value; + } + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline void SetEndpoints(Aws::Vector< Endpoint >&& value) { + m_endpoints = std::move(value); + } + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline DescribeEndpointsResult& WithEndpoints( + const Aws::Vector< Endpoint >& value) { + SetEndpoints(value); + return *this; + } + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline DescribeEndpointsResult& WithEndpoints( + Aws::Vector< Endpoint >&& value) { + SetEndpoints(std::move(value)); + return *this; + } + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline DescribeEndpointsResult& AddEndpoints(const Endpoint& value) { + m_endpoints.push_back(value); + return *this; + } + + /** + *

An Endpoints object is returned when a + * DescribeEndpoints request is made.

+ */ + inline DescribeEndpointsResult& AddEndpoints(Endpoint&& value) { + m_endpoints.push_back(std::move(value)); + return *this; + } + + private: + Aws::Vector< Endpoint > m_endpoints; +}; \ No newline at end of file diff --git a/src/odbcdriver/Endpoint.cpp b/src/odbcdriver/Endpoint.cpp new file mode 100644 index 000000000..0e7badf7c --- /dev/null +++ b/src/odbcdriver/Endpoint.cpp @@ -0,0 +1,50 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include "Endpoint.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; + +Endpoint::Endpoint() + : m_addressHasBeenSet(false) { +} + +Endpoint::Endpoint(JsonView jsonValue) + : m_addressHasBeenSet(false) { + *this = jsonValue; +} + +Endpoint& Endpoint::operator=(JsonView jsonValue) { + if (jsonValue.ValueExists("Address")) { + m_address = jsonValue.GetString("Address"); + m_addressHasBeenSet = true; + } + + if (jsonValue.ValueExists("CachePeriodInMinutes")) { + m_cachePeriodInMinutes = jsonValue.GetInt64("CachePeriodInMinutes"); + + m_cachePeriodInMinutesHasBeenSet = true; + } + + return *this; +} + +JsonValue Endpoint::Jsonize() const { + JsonValue payload; + + if (m_addressHasBeenSet) { + payload.WithString("Address", m_address); + } + + if (m_cachePeriodInMinutesHasBeenSet) { + payload.WithInt64("CachePeriodInMinutes", m_cachePeriodInMinutes); + } + + return payload; +} \ No newline at end of file diff --git a/src/odbcdriver/Endpoint.h b/src/odbcdriver/Endpoint.h new file mode 100644 index 000000000..c82bf7df9 --- /dev/null +++ b/src/odbcdriver/Endpoint.h @@ -0,0 +1,131 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include + +#include + +namespace Aws { +namespace Utils { +namespace Json { +class JsonValue; +class JsonView; +} // namespace Json +} // namespace Utils +} // namespace Aws + +/** + *

Represents an available endpoint against which to make API calls agaisnt, + * as well as the TTL for that endpoint.

See Also:

AWS + * API Reference

+ */ +class Endpoint { + public: + Endpoint(); + Endpoint(Aws::Utils::Json::JsonView jsonValue); + Endpoint& operator=(Aws::Utils::Json::JsonView jsonValue); + Aws::Utils::Json::JsonValue Jsonize() const; + + /** + *

An endpoint address.

+ */ + inline const Aws::String& GetAddress() const { + return m_address; + } + + /** + *

An endpoint address.

+ */ + inline bool AddressHasBeenSet() const { + return m_addressHasBeenSet; + } + + /** + *

An endpoint address.

+ */ + inline void SetAddress(const Aws::String& value) { + m_addressHasBeenSet = true; + m_address = value; + } + + /** + *

An endpoint address.

+ */ + inline void SetAddress(Aws::String&& value) { + m_addressHasBeenSet = true; + m_address = std::move(value); + } + + /** + *

An endpoint address.

+ */ + inline void SetAddress(const char* value) { + m_addressHasBeenSet = true; + m_address.assign(value); + } + + /** + *

An endpoint address.

+ */ + inline Endpoint& WithAddress(const Aws::String& value) { + SetAddress(value); + return *this; + } + + /** + *

An endpoint address.

+ */ + inline Endpoint& WithAddress(Aws::String&& value) { + SetAddress(std::move(value)); + return *this; + } + + /** + *

An endpoint address.

+ */ + inline Endpoint& WithAddress(const char* value) { + SetAddress(value); + return *this; + } + + /** + *

The TTL for the endpoint, in minutes.

+ */ + inline long long GetCachePeriodInMinutes() const{ + return m_cachePeriodInMinutes; + } + + /** + *

The TTL for the endpoint, in minutes.

+ */ + inline bool CachePeriodInMinutesHasBeenSet() const { + return m_cachePeriodInMinutesHasBeenSet; + } + + /** + *

The TTL for the endpoint, in minutes.

+ */ + inline void SetCachePeriodInMinutes(long long value) { + m_cachePeriodInMinutesHasBeenSet = true; + m_cachePeriodInMinutes = value; + } + + /** + *

The TTL for the endpoint, in minutes.

+ */ + inline Endpoint& WithCachePeriodInMinutes(long long value) { + SetCachePeriodInMinutes(value); + return *this; + } + + private: + Aws::String m_address; + bool m_addressHasBeenSet; + + long long m_cachePeriodInMinutes; + bool m_cachePeriodInMinutesHasBeenSet; +}; \ No newline at end of file diff --git a/src/odbcdriver/QueryRequest.cpp b/src/odbcdriver/QueryRequest.cpp new file mode 100644 index 000000000..12b7cbe71 --- /dev/null +++ b/src/odbcdriver/QueryRequest.cpp @@ -0,0 +1,51 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include "QueryRequest.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; + +QueryRequest::QueryRequest() + : m_queryStringHasBeenSet(false), + m_clientToken(Aws::Utils::UUID::RandomUUID()), + m_clientTokenHasBeenSet(true), + m_nextTokenHasBeenSet(false), + m_maxRows(0), + m_maxRowsHasBeenSet(false) { +} + +Aws::String QueryRequest::SerializePayload() const { + JsonValue payload; + + if (m_queryStringHasBeenSet) { + payload.WithString("QueryString", m_queryString); + } + + if (m_clientTokenHasBeenSet) { + payload.WithString("ClientToken", m_clientToken); + } + + if (m_nextTokenHasBeenSet) { + payload.WithString("NextToken", m_nextToken); + } + + if (m_maxRowsHasBeenSet) { + payload.WithInteger("MaxRows", m_maxRows); + } + + return payload.View().WriteReadable(); +} + +Aws::Http::HeaderValueCollection QueryRequest::GetRequestSpecificHeaders() + const { + Aws::Http::HeaderValueCollection headers; + headers.insert(Aws::Http::HeaderValuePair("X-Amz-Target", + "Timestream_20181101.Query")); + return headers; +} diff --git a/src/odbcdriver/QueryRequest.h b/src/odbcdriver/QueryRequest.h new file mode 100644 index 000000000..bb4848aed --- /dev/null +++ b/src/odbcdriver/QueryRequest.h @@ -0,0 +1,357 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include "DatabaseQueryRequest.h" + +#include +#include + +#include + +/** + */ +class QueryRequest : public DatabaseQueryRequest { + public: + QueryRequest(); + + // Service request name is the Operation name which will send this request + // out, each operation should has unique request name, so that we can get + // operation's name from this request. Note: this is not true for response, + // multiple operations may have the same response name, so we can not get + // operation's name from response. + inline virtual const char* GetServiceRequestName() const override { + return "Query"; + } + + Aws::String SerializePayload() const override; + + Aws::Http::HeaderValueCollection GetRequestSpecificHeaders() const override; + + /** + *

The query to be executed by Timestream.

+ */ + inline const Aws::String& GetQueryString() const { + return m_queryString; + } + + /** + *

The query to be executed by Timestream.

+ */ + inline bool QueryStringHasBeenSet() const { + return m_queryStringHasBeenSet; + } + + /** + *

The query to be executed by Timestream.

+ */ + inline void SetQueryString(const Aws::String& value) { + m_queryStringHasBeenSet = true; + m_queryString = value; + } + + /** + *

The query to be executed by Timestream.

+ */ + inline void SetQueryString(Aws::String&& value) { + m_queryStringHasBeenSet = true; + m_queryString = std::move(value); + } + + /** + *

The query to be executed by Timestream.

+ */ + inline void SetQueryString(const char* value) { + m_queryStringHasBeenSet = true; + m_queryString.assign(value); + } + + /** + *

The query to be executed by Timestream.

+ */ + inline QueryRequest& WithQueryString(const Aws::String& value) { + SetQueryString(value); + return *this; + } + + /** + *

The query to be executed by Timestream.

+ */ + inline QueryRequest& WithQueryString(Aws::String&& value) { + SetQueryString(std::move(value)); + return *this; + } + + /** + *

The query to be executed by Timestream.

+ */ + inline QueryRequest& WithQueryString(const char* value) { + SetQueryString(value); + return *this; + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline const Aws::String& GetClientToken() const { + return m_clientToken; + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline bool ClientTokenHasBeenSet() const { + return m_clientTokenHasBeenSet; + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline void SetClientToken(const Aws::String& value) { + m_clientTokenHasBeenSet = true; + m_clientToken = value; + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline void SetClientToken(Aws::String&& value) { + m_clientTokenHasBeenSet = true; + m_clientToken = std::move(value); + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline void SetClientToken(const char* value) { + m_clientTokenHasBeenSet = true; + m_clientToken.assign(value); + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline QueryRequest& WithClientToken(const Aws::String& value) { + SetClientToken(value); + return *this; + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline QueryRequest& WithClientToken(Aws::String&& value) { + SetClientToken(std::move(value)); + return *this; + } + + /** + *

Unique, case-sensitive string of up to 64 ASCII characters that you + * specify when you make a Query request. Providing a + * ClientToken makes the call to Query idempotent, + * meaning that multiple identical calls have the same effect as one single + * call.

Your query request will fail in the following cases:

+ *
  • If you submit a request with the same client token outside + * the 5-minute idepotency window.

  • If you submit a + * request with the same client token but a change in other parameters + * within the 5-minute idempotency window.

After 4 + * hours, any request with the same client token is treated as a new + * request.

+ */ + inline QueryRequest& WithClientToken(const char* value) { + SetClientToken(value); + return *this; + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline const Aws::String& GetNextToken() const { + return m_nextToken; + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline bool NextTokenHasBeenSet() const { + return m_nextTokenHasBeenSet; + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline void SetNextToken(const Aws::String& value) { + m_nextTokenHasBeenSet = true; + m_nextToken = value; + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline void SetNextToken(Aws::String&& value) { + m_nextTokenHasBeenSet = true; + m_nextToken = std::move(value); + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline void SetNextToken(const char* value) { + m_nextTokenHasBeenSet = true; + m_nextToken.assign(value); + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline QueryRequest& WithNextToken(const Aws::String& value) { + SetNextToken(value); + return *this; + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline QueryRequest& WithNextToken(Aws::String&& value) { + SetNextToken(std::move(value)); + return *this; + } + + /** + *

A pagination token passed to get a set of results.

+ */ + inline QueryRequest& WithNextToken(const char* value) { + SetNextToken(value); + return *this; + } + + /** + *

The total number of rows to return in the output. If the total number + * of rows available is more than the value specified, a NextToken is + * provided in the command's output. To resume pagination, provide the + * NextToken value in the starting-token argument of a subsequent command. + *

+ */ + inline int GetMaxRows() const { + return m_maxRows; + } + + /** + *

The total number of rows to return in the output. If the total number + * of rows available is more than the value specified, a NextToken is + * provided in the command's output. To resume pagination, provide the + * NextToken value in the starting-token argument of a subsequent command. + *

+ */ + inline bool MaxRowsHasBeenSet() const { + return m_maxRowsHasBeenSet; + } + + /** + *

The total number of rows to return in the output. If the total number + * of rows available is more than the value specified, a NextToken is + * provided in the command's output. To resume pagination, provide the + * NextToken value in the starting-token argument of a subsequent command. + *

+ */ + inline void SetMaxRows(int value) { + m_maxRowsHasBeenSet = true; + m_maxRows = value; + } + + /** + *

The total number of rows to return in the output. If the total number + * of rows available is more than the value specified, a NextToken is + * provided in the command's output. To resume pagination, provide the + * NextToken value in the starting-token argument of a subsequent command. + *

+ */ + inline QueryRequest& WithMaxRows(int value) { + SetMaxRows(value); + return *this; + } + + private: + Aws::String m_queryString; + bool m_queryStringHasBeenSet; + + Aws::String m_clientToken; + bool m_clientTokenHasBeenSet; + + Aws::String m_nextToken; + bool m_nextTokenHasBeenSet; + + int m_maxRows; + bool m_maxRowsHasBeenSet; +}; diff --git a/src/odbcdriver/QueryResult.cpp b/src/odbcdriver/QueryResult.cpp new file mode 100644 index 000000000..ae2216c09 --- /dev/null +++ b/src/odbcdriver/QueryResult.cpp @@ -0,0 +1,60 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include +#include +#include +#include "QueryResult.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; +using namespace Aws; + +QueryResult::QueryResult() { +} + +QueryResult::QueryResult( + const Aws::AmazonWebServiceResult< JsonValue >& result) { + *this = result; +} + +QueryResult& QueryResult::operator=( + const Aws::AmazonWebServiceResult< JsonValue >& result) { + JsonView jsonValue = result.GetPayload().View(); + if (jsonValue.ValueExists("QueryId")) { + m_queryId = jsonValue.GetString("QueryId"); + } + + if (jsonValue.ValueExists("NextToken")) { + m_nextToken = jsonValue.GetString("NextToken"); + } + + if (jsonValue.ValueExists("Rows")) { + Array< JsonView > rowsJsonList = jsonValue.GetArray("Rows"); + for (unsigned rowsIndex = 0; rowsIndex < rowsJsonList.GetLength(); + ++rowsIndex) { + m_rows.push_back(rowsJsonList[rowsIndex].AsObject()); + } + } + + if (jsonValue.ValueExists("ColumnInfo")) { + Array< JsonView > columnInfoJsonList = jsonValue.GetArray("ColumnInfo"); + for (unsigned columnInfoIndex = 0; + columnInfoIndex < columnInfoJsonList.GetLength(); + ++columnInfoIndex) { + m_columnInfo.push_back( + columnInfoJsonList[columnInfoIndex].AsObject()); + } + } + + if (jsonValue.ValueExists("QueryStatus")) { + m_queryStatus = jsonValue.GetObject("QueryStatus"); + } + + return *this; +} diff --git a/src/odbcdriver/QueryResult.h b/src/odbcdriver/QueryResult.h new file mode 100644 index 000000000..cf822def9 --- /dev/null +++ b/src/odbcdriver/QueryResult.h @@ -0,0 +1,305 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +#include +#include + +#include +#include "ColumnInfo.h" +#include "QueryStatus.h" +#include "Row.h" + +namespace Aws { +template < typename RESULT_TYPE > +class AmazonWebServiceResult; + +namespace Utils { +namespace Json { +class JsonValue; +} // namespace Json +} // namespace Utils +} // namespace Aws + +class QueryResult { + public: + QueryResult(); + QueryResult( + const Aws::AmazonWebServiceResult< Aws::Utils::Json::JsonValue >& + result); + QueryResult& operator=( + const Aws::AmazonWebServiceResult< Aws::Utils::Json::JsonValue >& + result); + + /** + *

A unique ID for the given query.

+ */ + inline const Aws::String& GetQueryId() const { + return m_queryId; + } + + /** + *

A unique ID for the given query.

+ */ + inline void SetQueryId(const Aws::String& value) { + m_queryId = value; + } + + /** + *

A unique ID for the given query.

+ */ + inline void SetQueryId(Aws::String&& value) { + m_queryId = std::move(value); + } + + /** + *

A unique ID for the given query.

+ */ + inline void SetQueryId(const char* value) { + m_queryId.assign(value); + } + + /** + *

A unique ID for the given query.

+ */ + inline QueryResult& WithQueryId(const Aws::String& value) { + SetQueryId(value); + return *this; + } + + /** + *

A unique ID for the given query.

+ */ + inline QueryResult& WithQueryId(Aws::String&& value) { + SetQueryId(std::move(value)); + return *this; + } + + /** + *

A unique ID for the given query.

+ */ + inline QueryResult& WithQueryId(const char* value) { + SetQueryId(value); + return *this; + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline const Aws::String& GetNextToken() const { + return m_nextToken; + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline void SetNextToken(const Aws::String& value) { + m_nextToken = value; + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline void SetNextToken(Aws::String&& value) { + m_nextToken = std::move(value); + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline void SetNextToken(const char* value) { + m_nextToken.assign(value); + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline QueryResult& WithNextToken(const Aws::String& value) { + SetNextToken(value); + return *this; + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline QueryResult& WithNextToken(Aws::String&& value) { + SetNextToken(std::move(value)); + return *this; + } + + /** + *

A pagination token that can be used again on a Query + * call to get the next set of results.

+ */ + inline QueryResult& WithNextToken(const char* value) { + SetNextToken(value); + return *this; + } + + /** + *

The result set rows returned by the query.

+ */ + inline const Aws::Vector< Row >& GetRows() const { + return m_rows; + } + + /** + *

The result set rows returned by the query.

+ */ + inline void SetRows(const Aws::Vector< Row >& value) { + m_rows = value; + } + + /** + *

The result set rows returned by the query.

+ */ + inline void SetRows(Aws::Vector< Row >&& value) { + m_rows = std::move(value); + } + + /** + *

The result set rows returned by the query.

+ */ + inline QueryResult& WithRows(const Aws::Vector< Row >& value) { + SetRows(value); + return *this; + } + + /** + *

The result set rows returned by the query.

+ */ + inline QueryResult& WithRows(Aws::Vector< Row >&& value) { + SetRows(std::move(value)); + return *this; + } + + /** + *

The result set rows returned by the query.

+ */ + inline QueryResult& AddRows(const Row& value) { + m_rows.push_back(value); + return *this; + } + + /** + *

The result set rows returned by the query.

+ */ + inline QueryResult& AddRows(Row&& value) { + m_rows.push_back(std::move(value)); + return *this; + } + + /** + *

The column data types of the returned result set.

+ */ + inline const Aws::Vector< ColumnInfo >& GetColumnInfo() const { + return m_columnInfo; + } + + /** + *

The column data types of the returned result set.

+ */ + inline void SetColumnInfo(const Aws::Vector< ColumnInfo >& value) { + m_columnInfo = value; + } + + /** + *

The column data types of the returned result set.

+ */ + inline void SetColumnInfo(Aws::Vector< ColumnInfo >&& value) { + m_columnInfo = std::move(value); + } + + /** + *

The column data types of the returned result set.

+ */ + inline QueryResult& WithColumnInfo(const Aws::Vector< ColumnInfo >& value) { + SetColumnInfo(value); + return *this; + } + + /** + *

The column data types of the returned result set.

+ */ + inline QueryResult& WithColumnInfo(Aws::Vector< ColumnInfo >&& value) { + SetColumnInfo(std::move(value)); + return *this; + } + + /** + *

The column data types of the returned result set.

+ */ + inline QueryResult& AddColumnInfo(const ColumnInfo& value) { + m_columnInfo.push_back(value); + return *this; + } + + /** + *

The column data types of the returned result set.

+ */ + inline QueryResult& AddColumnInfo(ColumnInfo&& value) { + m_columnInfo.push_back(std::move(value)); + return *this; + } + + /** + *

Information about the status of the query, including progress and + * bytes scannned.

+ */ + inline const QueryStatus& GetQueryStatus() const { + return m_queryStatus; + } + + /** + *

Information about the status of the query, including progress and + * bytes scannned.

+ */ + inline void SetQueryStatus(const QueryStatus& value) { + m_queryStatus = value; + } + + /** + *

Information about the status of the query, including progress and + * bytes scannned.

+ */ + inline void SetQueryStatus(QueryStatus&& value) { + m_queryStatus = std::move(value); + } + + /** + *

Information about the status of the query, including progress and + * bytes scannned.

+ */ + inline QueryResult& WithQueryStatus(const QueryStatus& value) { + SetQueryStatus(value); + return *this; + } + + /** + *

Information about the status of the query, including progress and + * bytes scannned.

+ */ + inline QueryResult& WithQueryStatus(QueryStatus&& value) { + SetQueryStatus(std::move(value)); + return *this; + } + + private: + Aws::String m_queryId; + + Aws::String m_nextToken; + + Aws::Vector< Row > m_rows; + + Aws::Vector< ColumnInfo > m_columnInfo; + + QueryStatus m_queryStatus; +}; \ No newline at end of file diff --git a/src/odbcdriver/QueryStatus.cpp b/src/odbcdriver/QueryStatus.cpp new file mode 100644 index 000000000..38ae304dd --- /dev/null +++ b/src/odbcdriver/QueryStatus.cpp @@ -0,0 +1,43 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include "QueryStatus.h" + +#include + +using namespace Aws::Utils::Json; +using namespace Aws::Utils; + +QueryStatus::QueryStatus() + : m_progressPercentage(0.0), + m_progressPercentageHasBeenSet(false) { +} + +QueryStatus::QueryStatus(JsonView jsonValue) + : m_progressPercentage(0.0), + m_progressPercentageHasBeenSet(false) { + *this = jsonValue; +} + +QueryStatus& QueryStatus::operator=(JsonView jsonValue) { + if (jsonValue.ValueExists("ProgressPercentage")) { + m_progressPercentage = jsonValue.GetDouble("ProgressPercentage"); + + m_progressPercentageHasBeenSet = true; + } + + return *this; +} + +JsonValue QueryStatus::Jsonize() const { + JsonValue payload; + + if (m_progressPercentageHasBeenSet) { + payload.WithDouble("ProgressPercentage", m_progressPercentage); + } + + return payload; +} diff --git a/src/odbcdriver/QueryStatus.h b/src/odbcdriver/QueryStatus.h new file mode 100644 index 000000000..44b6f685b --- /dev/null +++ b/src/odbcdriver/QueryStatus.h @@ -0,0 +1,62 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#pragma once +namespace Aws { +namespace Utils { +namespace Json { +class JsonValue; +class JsonView; +} // namespace Json +} // namespace Utils +} // namespace Aws + +/** + *

Information about the status of the query, including progress and bytes + * scannned.

See Also:

AWS + * API Reference

+ */ +class QueryStatus { + public: + QueryStatus(); + QueryStatus(Aws::Utils::Json::JsonView jsonValue); + QueryStatus& operator=(Aws::Utils::Json::JsonView jsonValue); + Aws::Utils::Json::JsonValue Jsonize() const; + + /** + *

The progress of the query, expressed as a percentage.

+ */ + inline double GetProgressPercentage() const { + return m_progressPercentage; + } + + /** + *

The progress of the query, expressed as a percentage.

+ */ + inline bool ProgressPercentageHasBeenSet() const { + return m_progressPercentageHasBeenSet; + } + + /** + *

The progress of the query, expressed as a percentage.

+ */ + inline void SetProgressPercentage(double value) { + m_progressPercentageHasBeenSet = true; + m_progressPercentage = value; + } + + /** + *

The progress of the query, expressed as a percentage.

+ */ + inline QueryStatus& WithProgressPercentage(double value) { + SetProgressPercentage(value); + return *this; + } + + private: + double m_progressPercentage; + bool m_progressPercentageHasBeenSet; +}; \ No newline at end of file diff --git a/src/odbcdriver/Row.h b/src/odbcdriver/Row.h index 5d4e77723..0f01f1e65 100644 --- a/src/odbcdriver/Row.h +++ b/src/odbcdriver/Row.h @@ -4,40 +4,51 @@ */ #pragma once -#include #include -#include +#include "Datum.h" #include - /** - *

Represents a single row in the query results.

See Also:

AWS - * API Reference

- */ - class Row - { - public: +namespace Aws { +namespace Utils { +namespace Json { +class JsonValue; +class JsonView; +} // namespace Json +} // namespace Utils +} // namespace Aws + +/** + *

Represents a single row in the query results.

See Also:

AWS + * API Reference

+ */ +class Row { + public: Row(); Row(Aws::Utils::Json::JsonView jsonValue); Row& operator=(Aws::Utils::Json::JsonView jsonValue); Aws::Utils::Json::JsonValue Jsonize() const; - /** *

List of data points in a single row of the result set.

*/ - inline const Aws::Vector& GetData() const{ return m_data; } + inline const Aws::Vector< Datum >& GetData() + const { + return m_data; + } /** *

List of data points in a single row of the result set.

*/ - inline bool DataHasBeenSet() const { return m_dataHasBeenSet; } + inline bool DataHasBeenSet() const { + return m_dataHasBeenSet; + } /** *

List of data points in a single row of the result set.

*/ inline void SetData( - const Aws::Vector< Aws::TimestreamQuery::Model::Datum >& value) { + const Aws::Vector< Datum >& value) { m_dataHasBeenSet = true; m_data = value; } @@ -46,7 +57,7 @@ *

List of data points in a single row of the result set.

*/ inline void SetData( - Aws::Vector< Aws::TimestreamQuery::Model::Datum >&& value) { + Aws::Vector< Datum >&& value) { m_dataHasBeenSet = true; m_data = std::move(value); } @@ -55,7 +66,7 @@ *

List of data points in a single row of the result set.

*/ inline Row& WithData( - const Aws::Vector< Aws::TimestreamQuery::Model::Datum >& value) { + const Aws::Vector< Datum >& value) { SetData(value); return *this; } @@ -64,7 +75,7 @@ *

List of data points in a single row of the result set.

*/ inline Row& WithData( - Aws::Vector< Aws::TimestreamQuery::Model::Datum >&& value) { + Aws::Vector< Datum >&& value) { SetData(std::move(value)); return *this; } @@ -72,7 +83,7 @@ /** *

List of data points in a single row of the result set.

*/ - inline Row& AddData(const Aws::TimestreamQuery::Model::Datum& value) { + inline Row& AddData(const Datum& value) { m_dataHasBeenSet = true; m_data.push_back(value); return *this; @@ -81,14 +92,13 @@ /** *

List of data points in a single row of the result set.

*/ - inline Row& AddData(Aws::TimestreamQuery::Model::Datum&& value) { + inline Row& AddData(Datum&& value) { m_dataHasBeenSet = true; m_data.push_back(std::move(value)); return *this; } - private: - - Aws::Vector< Aws::TimestreamQuery::Model::Datum > m_data; + private: + Aws::Vector< Datum > m_data; bool m_dataHasBeenSet; - }; +}; diff --git a/src/odbcdriver/ScalarType.h b/src/odbcdriver/ScalarType.h index d64e10967..ce2a22268 100644 --- a/src/odbcdriver/ScalarType.h +++ b/src/odbcdriver/ScalarType.h @@ -4,7 +4,6 @@ */ #pragma once -#include #include enum class ScalarType { diff --git a/src/odbcdriver/Type.cpp b/src/odbcdriver/Type.cpp index a507ddb8e..b0d1fb745 100644 --- a/src/odbcdriver/Type.cpp +++ b/src/odbcdriver/Type.cpp @@ -17,7 +17,6 @@ Type::Type() : m_scalarType(ScalarType::NOT_SET), m_scalarTypeHasBeenSet(false), m_arrayColumnInfoHasBeenSet(false), - m_timeSeriesMeasureValueColumnInfoHasBeenSet(false), m_rowColumnInfoHasBeenSet(false) { } @@ -26,7 +25,6 @@ Type::Type(JsonView jsonValue) : m_scalarType(ScalarType::NOT_SET), m_scalarTypeHasBeenSet(false), m_arrayColumnInfoHasBeenSet(false), - m_timeSeriesMeasureValueColumnInfoHasBeenSet(false), m_rowColumnInfoHasBeenSet(false) { *this = jsonValue; @@ -39,13 +37,6 @@ void Type::SetArrayColumnInfo(ColumnInfo&& value) { m_arrayColumnInfoHasBeenSet Type& Type::WithArrayColumnInfo(const ColumnInfo& value) { SetArrayColumnInfo(value); return *this;} Type& Type::WithArrayColumnInfo(ColumnInfo&& value) { SetArrayColumnInfo(std::move(value)); return *this;} -const ColumnInfo& Type::GetTimeSeriesMeasureValueColumnInfo() const{ return *m_timeSeriesMeasureValueColumnInfo; } -bool Type::TimeSeriesMeasureValueColumnInfoHasBeenSet() const { return m_timeSeriesMeasureValueColumnInfoHasBeenSet; } -void Type::SetTimeSeriesMeasureValueColumnInfo(const ColumnInfo& value) { m_timeSeriesMeasureValueColumnInfoHasBeenSet = true; m_timeSeriesMeasureValueColumnInfo = Aws::MakeShared("Type", value); } -void Type::SetTimeSeriesMeasureValueColumnInfo(ColumnInfo&& value) { m_timeSeriesMeasureValueColumnInfoHasBeenSet = true; m_timeSeriesMeasureValueColumnInfo = Aws::MakeShared("Type", std::move(value)); } -Type& Type::WithTimeSeriesMeasureValueColumnInfo(const ColumnInfo& value) { SetTimeSeriesMeasureValueColumnInfo(value); return *this;} -Type& Type::WithTimeSeriesMeasureValueColumnInfo(ColumnInfo&& value) { SetTimeSeriesMeasureValueColumnInfo(std::move(value)); return *this;} - Type& Type::operator =(JsonView jsonValue) { if(jsonValue.ValueExists("ScalarType")) @@ -62,13 +53,6 @@ Type& Type::operator =(JsonView jsonValue) m_arrayColumnInfoHasBeenSet = true; } - if(jsonValue.ValueExists("TimeSeriesMeasureValueColumnInfo")) - { - m_timeSeriesMeasureValueColumnInfo = Aws::MakeShared("Type", jsonValue.GetObject("TimeSeriesMeasureValueColumnInfo")); - - m_timeSeriesMeasureValueColumnInfoHasBeenSet = true; - } - if(jsonValue.ValueExists("RowColumnInfo")) { Array rowColumnInfoJsonList = jsonValue.GetArray("RowColumnInfo"); @@ -97,12 +81,6 @@ JsonValue Type::Jsonize() const } - if(m_timeSeriesMeasureValueColumnInfoHasBeenSet) - { - payload.WithObject("TimeSeriesMeasureValueColumnInfo", m_timeSeriesMeasureValueColumnInfo->Jsonize()); - - } - if(m_rowColumnInfoHasBeenSet) { Array rowColumnInfoJsonList(m_rowColumnInfo.size()); @@ -115,4 +93,4 @@ JsonValue Type::Jsonize() const } return payload; -} +} \ No newline at end of file diff --git a/src/odbcdriver/Type.h b/src/odbcdriver/Type.h index 54801e236..ce421715e 100644 --- a/src/odbcdriver/Type.h +++ b/src/odbcdriver/Type.h @@ -5,12 +5,20 @@ #pragma once #include -#include #include #include #include "ScalarType.h" #include "ColumnInfo.h" +namespace Aws { +namespace Utils { +namespace Json { +class JsonValue; +class JsonView; +} // namespace Json +} // namespace Utils +} // namespace Aws + /** *

Contains the data type of a column in a query result set. The data type can * be scalar or complex. The supported scalar data types are integers, boolean, @@ -108,36 +116,6 @@ class Type { */ Type& WithArrayColumnInfo(ColumnInfo&& value); - /** - *

Indicates if the column is a timeseries data type.

- */ - const ColumnInfo& GetTimeSeriesMeasureValueColumnInfo() const; - - /** - *

Indicates if the column is a timeseries data type.

- */ - bool TimeSeriesMeasureValueColumnInfoHasBeenSet() const; - - /** - *

Indicates if the column is a timeseries data type.

- */ - void SetTimeSeriesMeasureValueColumnInfo(const ColumnInfo& value); - - /** - *

Indicates if the column is a timeseries data type.

- */ - void SetTimeSeriesMeasureValueColumnInfo(ColumnInfo&& value); - - /** - *

Indicates if the column is a timeseries data type.

- */ - Type& WithTimeSeriesMeasureValueColumnInfo(const ColumnInfo& value); - - /** - *

Indicates if the column is a timeseries data type.

- */ - Type& WithTimeSeriesMeasureValueColumnInfo(ColumnInfo&& value); - /** *

Indicates if the column is a row.

*/ @@ -209,9 +187,6 @@ class Type { std::shared_ptr< ColumnInfo > m_arrayColumnInfo; bool m_arrayColumnInfoHasBeenSet; - std::shared_ptr< ColumnInfo > m_timeSeriesMeasureValueColumnInfo; - bool m_timeSeriesMeasureValueColumnInfoHasBeenSet; - Aws::Vector< ColumnInfo > m_rowColumnInfo; bool m_rowColumnInfoHasBeenSet; }; diff --git a/src/odbcdriver/helper.cpp b/src/odbcdriver/helper.cpp index 63fdbae22..476d37e2e 100644 --- a/src/odbcdriver/helper.cpp +++ b/src/odbcdriver/helper.cpp @@ -24,7 +24,7 @@ #include "odbc_statement.h" void* ConnectDBParams(const runtime_options& rt_opts) { - auto conn = new TSCommunication(); + auto conn = new DBCommunication(); if (conn != nullptr) { try { conn->Setup(rt_opts); diff --git a/src/odbcdriver/odbc_communication.cpp b/src/odbcdriver/odbc_communication.cpp index 124a8d622..115c221cd 100644 --- a/src/odbcdriver/odbc_communication.cpp +++ b/src/odbcdriver/odbc_communication.cpp @@ -30,12 +30,10 @@ #include #include #include -#include -#include +#include "CancelQueryRequest.h" +#include "QueryRequest.h" // clang-format on -using namespace Aws::TimestreamQuery; - namespace { /** * A helper class to initialize/shutdown AWS API once per DLL load/unload. @@ -72,14 +70,14 @@ namespace { const Aws::String UA_ID_PREFIX = Aws::String("ts-odbc."); const std::string DEFAULT_CREATOR_TYPE = "DEFAULT"; - typedef std::function< std::unique_ptr< TimestreamQueryClient >( + typedef std::function< std::unique_ptr< DatabaseQueryClient >( const runtime_options& options, const Aws::Client::ClientConfiguration& config) > QueryClientCreator; QueryClientCreator default_creator = [](const runtime_options& , const Aws::Client::ClientConfiguration& config) { - return std::unique_ptr< TimestreamQueryClient >(new TimestreamQueryClient(config)); + return std::unique_ptr< DatabaseQueryClient >(new DatabaseQueryClient(config)); }; std::unordered_map< std::string, QueryClientCreator > creators = { @@ -87,15 +85,15 @@ namespace { }; } -TSCommunication::TSCommunication() { +DBCommunication::DBCommunication() { ++AWS_SDK_HELPER; } -TSCommunication::~TSCommunication() { +DBCommunication::~DBCommunication() { --AWS_SDK_HELPER; } -bool TSCommunication::Validate(const runtime_options& options) { +bool DBCommunication::Validate(const runtime_options& options) { if (options.auth.auth_type != AUTHTYPE_DEFAULT) { throw std::invalid_argument("Unknown authentication type: \"" + options.auth.auth_type + "\"."); } @@ -111,7 +109,7 @@ bool TSCommunication::Validate(const runtime_options& options) { return true; } -std::unique_ptr< Aws::TimestreamQuery::TimestreamQueryClient > TSCommunication::CreateQueryClient(const runtime_options& options) { +std::unique_ptr< DatabaseQueryClient > DBCommunication::CreateQueryClient(const runtime_options& options) { Aws::Client::ClientConfiguration config; config.userAgent = GetUserAgent(); @@ -161,8 +159,8 @@ std::unique_ptr< Aws::TimestreamQuery::TimestreamQueryClient > TSCommunication:: } } -bool TSCommunication::TestQueryClient() { - Aws::TimestreamQuery::Model::QueryRequest req; +bool DBCommunication::TestQueryClient() { + QueryRequest req; req.SetQueryString("select 1"); auto outcome = m_client->Query(req); if (!outcome.IsSuccess()) { @@ -175,16 +173,16 @@ bool TSCommunication::TestQueryClient() { return true; } -bool TSCommunication::Connect(const runtime_options& options) { +bool DBCommunication::Connect(const runtime_options& options) { m_client = CreateQueryClient(options); if (m_client == nullptr) { - throw std::runtime_error("Unable to create TimestreamQueryClient."); + throw std::runtime_error("Unable to create DatabaseQueryClient."); } return TestQueryClient(); } -void TSCommunication::Disconnect() { - LogMsg(LOG_DEBUG, "Disconnecting Timestream connection."); +void DBCommunication::Disconnect() { + LogMsg(LOG_DEBUG, "Disconnecting Database connection."); if (m_client) { m_client.reset(); } @@ -194,15 +192,15 @@ void TSCommunication::Disconnect() { } } -std::string TSCommunication::GetVersion() { +std::string DBCommunication::GetVersion() { return TIMESTREAMDRIVERVERSION; } -std::string TSCommunication::GetErrorPrefix() { +std::string DBCommunication::GetErrorPrefix() { return "[Timestream][SQL ODBC Driver] "; } -void TSCommunication::StopResultRetrieval(StatementClass* stmt) { +void DBCommunication::StopResultRetrieval(StatementClass* stmt) { // Call Cancel logic CancelQuery(stmt); // Clean the queue @@ -211,7 +209,7 @@ void TSCommunication::StopResultRetrieval(StatementClass* stmt) { } } -Aws::String TSCommunication::GetUserAgent() { +Aws::String DBCommunication::GetUserAgent() { Aws::String program_name(GetExeProgramName()); Aws::String name_suffix = " [" + program_name + "]"; Aws::String msg = "Name of the application using the driver: " + name_suffix; @@ -228,7 +226,7 @@ class Context : public Aws::Client::AsyncCallerContext { /** * Parameterized constructor for the context */ - Context(PrefetchQueue* q, StatementClass* s, std::promise< Aws::TimestreamQuery::Model::QueryOutcome > p) + Context(PrefetchQueue* q, StatementClass* s, std::promise< QueryOutcome > p) : Aws::Client::AsyncCallerContext(), queue_(q), stmt_(s), promise_(std::move(p)) { } /** @@ -249,7 +247,7 @@ class Context : public Aws::Client::AsyncCallerContext { * Make promise * @param outcome const Aws::TimestreamQuery::Model::QueryOutcome& */ - void MakePromise(const Aws::TimestreamQuery::Model::QueryOutcome& outcome) { + void MakePromise(const QueryOutcome& outcome) { promise_.set_value(outcome); } private: @@ -265,14 +263,14 @@ class Context : public Aws::Client::AsyncCallerContext { * Promise made by the request * Wait to be fullfilled in the QueryCallback function */ - std::promise< Aws::TimestreamQuery::Model::QueryOutcome > promise_; + std::promise< QueryOutcome > promise_; }; // Callback function of QueryAsync operation by aws-sdk-cpp timestream-query void QueryCallback( - const Aws::TimestreamQuery::TimestreamQueryClient* client, - const Aws::TimestreamQuery::Model::QueryRequest& request, - const Aws::TimestreamQuery::Model::QueryOutcome& outcome, + const DatabaseQueryClient* client, + const QueryRequest& request, + const QueryOutcome& outcome, const std::shared_ptr< const Aws::Client::AsyncCallerContext >& context) { auto ctxt = (std::static_pointer_cast< const Context >(context)); auto p = const_cast< Context* >(ctxt.get()); @@ -288,8 +286,8 @@ void QueryCallback( SC_UnsetQueryId(sc); sc->query_id = strdup(outcome.GetResult().GetQueryId().c_str()); } - Aws::TimestreamQuery::Model::QueryRequest next_request(request); - std::promise next_promise; + QueryRequest next_request(request); + std::promise next_promise; auto success = p->GetPrefetchQueue()->Push(next_promise.get_future()); if (success) { // Issue next request @@ -307,7 +305,7 @@ void QueryCallback( } } -bool TSCommunication::ExecDirect(StatementClass* sc, const char* query) { +bool DBCommunication::ExecDirect(StatementClass* sc, const char* query) { CSTR func = "ExecDirect"; std::string statement(query); std::string msg = "Attempting to execute a query \"" + statement + "\""; @@ -318,10 +316,10 @@ bool TSCommunication::ExecDirect(StatementClass* sc, const char* query) { PrefetchQueue* pPrefetchQueue = prefetch_queues_map[sc].get(); pPrefetchQueue->Reset(); // Issue request - Aws::TimestreamQuery::Model::QueryRequest request; + QueryRequest request; request.SetQueryString(statement.c_str()); // Use QueryAsync - std::promise< Aws::TimestreamQuery::Model::QueryOutcome > promise; + std::promise< QueryOutcome > promise; pPrefetchQueue->SetRetrieving(true); auto success = pPrefetchQueue->Push(promise.get_future()); if (success) { @@ -337,7 +335,7 @@ bool TSCommunication::ExecDirect(StatementClass* sc, const char* query) { } } -bool TSCommunication::CancelQuery(StatementClass* stmt) { +bool DBCommunication::CancelQuery(StatementClass* stmt) { if (stmt == nullptr) return false; auto prefetch_queue_iterator = prefetch_queues_map.find(stmt); @@ -347,7 +345,7 @@ bool TSCommunication::CancelQuery(StatementClass* stmt) { } // Try to cancel current query (Not guaranteed in Timestream service) if (stmt->query_id != nullptr && strlen(stmt->query_id) != 0) { - Aws::TimestreamQuery::Model::CancelQueryRequest cancel_request; + CancelQueryRequest cancel_request; cancel_request.SetQueryId(stmt->query_id); auto outcome = m_client->CancelQuery(cancel_request); if (outcome.IsSuccess()) { diff --git a/src/odbcdriver/odbc_communication.h b/src/odbcdriver/odbc_communication.h index 1af8d5e49..122ccac2e 100644 --- a/src/odbcdriver/odbc_communication.h +++ b/src/odbcdriver/odbc_communication.h @@ -17,7 +17,7 @@ #ifndef DB_COMMUNICATION #define DB_COMMUNICATION -#include +#include "DatabaseQueryClient.h" #include #include @@ -29,11 +29,11 @@ /** * AWS Timestream communication class */ -class TSCommunication : public Communication { +class DBCommunication : public Communication { public: - TSCommunication(); + DBCommunication(); - ~TSCommunication(); + ~DBCommunication(); /** * Validate options @@ -96,7 +96,7 @@ class TSCommunication : public Communication { * @param options const runtime_options& * @return std::unique_ptr< Aws::TimestreamQuery::TimestreamQueryClient > */ - std::unique_ptr< Aws::TimestreamQuery::TimestreamQueryClient > + std::unique_ptr< DatabaseQueryClient > CreateQueryClient(const runtime_options& options); /** @@ -108,7 +108,7 @@ class TSCommunication : public Communication { /** * Timestream query client */ - std::unique_ptr< Aws::TimestreamQuery::TimestreamQueryClient > m_client; + std::unique_ptr< DatabaseQueryClient > m_client; }; #endif diff --git a/src/odbcdriver/odbc_statement.cpp b/src/odbcdriver/odbc_statement.cpp index 762079036..98f4d3c18 100644 --- a/src/odbcdriver/odbc_statement.cpp +++ b/src/odbcdriver/odbc_statement.cpp @@ -21,7 +21,7 @@ #include "helper.h" #include "misc.h" #include "statement.h" -#include +#include "DatabaseQueryClient.h" extern "C" void *common_cs; diff --git a/src/odbcdriver/parse_result.cpp b/src/odbcdriver/parse_result.cpp index 8e27822a6..22acf81b6 100644 --- a/src/odbcdriver/parse_result.cpp +++ b/src/odbcdriver/parse_result.cpp @@ -27,7 +27,7 @@ typedef std::vector< std::pair< std::string, OID > > schema_type; bool _CC_from_TSResult( QResultClass *q_res, ConnectionClass *conn, StatementClass *stmt, const char *next_token, - const Aws::TimestreamQuery::Model::QueryOutcome &result); + const QueryOutcome &result); /** * Responsible for looping through columns, allocating memory for column fields @@ -37,7 +37,7 @@ bool _CC_from_TSResult( * @return true if successfully assigned */ bool AssignColumnHeaders(QResultClass *q_res, - const Aws::TimestreamQuery::Model::QueryOutcome &result); + const QueryOutcome &result); /** * Responsible for looping through rows, allocating tuples and passing rows for @@ -47,7 +47,7 @@ bool AssignColumnHeaders(QResultClass *q_res, * @param fields ColumnInfoClass to get information about columns * @return true if successfully assigned */ -bool AssignTableData(const Aws::TimestreamQuery::Model::QueryOutcome &result, +bool AssignTableData(const QueryOutcome &result, QResultClass *q_res, ColumnInfoClass &fields); /** @@ -58,7 +58,7 @@ bool AssignTableData(const Aws::TimestreamQuery::Model::QueryOutcome &result, * @param col_size size of the column * @return true if successfully assigned */ -bool AssignRowData(const Aws::TimestreamQuery::Model::Row &row, +bool AssignRowData(const Row &row, QResultClass *q_res, ColumnInfoClass &fields, const size_t &col_size); void UpdateResultFields(QResultClass *q_res, const ConnectionClass *conn, @@ -75,7 +75,7 @@ void ClearError(); * @param datum_value String representation of the datum to fill in recursively * @param column_attr_id Column attribute ID */ -void ParseDatum(const Aws::TimestreamQuery::Model::Datum &datum, +void ParseDatum(const Datum &datum, std::string &datum_value, OID column_attr_id); /** @@ -86,7 +86,7 @@ void ParseDatum(const Aws::TimestreamQuery::Model::Datum &datum, * @param array_value String representation of the datum to fill in recursively * @param column_attr_id Column attribute ID */ -void ParseArray(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > &datums, +void ParseArray(const Aws::Vector< Datum > &datums, std::string &array_value, OID column_attr_id); /** @@ -97,7 +97,7 @@ void ParseArray(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > &datums, * @param row_value String representation of the datum to fill in recursively * @param column_attr_id Column attribute ID */ -void ParseRow(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > &datums, +void ParseRow(const Aws::Vector< Datum > &datums, std::string &row_value, OID column_attr_id); @@ -115,30 +115,30 @@ static const std::string JSON_KW_CURSOR = "cursor"; #define DB_VARCHAR_SIZE (-2) -const std::map< Aws::TimestreamQuery::Model::ScalarType, +const std::map< ScalarType, std::pair< OID, int16_t > > scalar_type_to_oid_size_map = { - {Aws::TimestreamQuery::Model::ScalarType::BIGINT, + {ScalarType::BIGINT, std::make_pair(DB_TYPE_BIGINT, (int16_t)8)}, - {Aws::TimestreamQuery::Model::ScalarType::BOOLEAN, + {ScalarType::BOOLEAN, std::make_pair(DB_TYPE_BOOLEAN, (int16_t)1)}, - {Aws::TimestreamQuery::Model::ScalarType::DATE, + {ScalarType::DATE, std::make_pair(DB_TYPE_DATE, (int16_t)6)}, - {Aws::TimestreamQuery::Model::ScalarType::DOUBLE, + {ScalarType::DOUBLE, std::make_pair(DB_TYPE_DOUBLE, (int16_t)8)}, - {Aws::TimestreamQuery::Model::ScalarType::INTEGER, + {ScalarType::INTEGER, std::make_pair(DB_TYPE_INTEGER, (int16_t)4)}, - {Aws::TimestreamQuery::Model::ScalarType::INTERVAL_DAY_TO_SECOND, + {ScalarType::INTERVAL_DAY_TO_SECOND, std::make_pair(DB_TYPE_VARCHAR, (int16_t)DB_VARCHAR_SIZE)}, - {Aws::TimestreamQuery::Model::ScalarType::INTERVAL_YEAR_TO_MONTH, + {ScalarType::INTERVAL_YEAR_TO_MONTH, std::make_pair(DB_TYPE_VARCHAR, (int16_t)DB_VARCHAR_SIZE)}, - {Aws::TimestreamQuery::Model::ScalarType::TIME, + {ScalarType::TIME, std::make_pair(DB_TYPE_TIME, (int16_t)6)}, - {Aws::TimestreamQuery::Model::ScalarType::TIMESTAMP, + {ScalarType::TIMESTAMP, std::make_pair(DB_TYPE_TIMESTAMP, (int16_t)16)}, - {Aws::TimestreamQuery::Model::ScalarType::VARCHAR, + {ScalarType::VARCHAR, std::make_pair(DB_TYPE_VARCHAR, (int16_t)DB_VARCHAR_SIZE)}, - {Aws::TimestreamQuery::Model::ScalarType::UNKNOWN, + {ScalarType::UNKNOWN, std::make_pair(DB_TYPE_VARCHAR, (int16_t)DB_VARCHAR_SIZE)}, }; @@ -159,14 +159,14 @@ std::string GetResultParserError() { BOOL CC_from_TSResult( QResultClass *q_res, ConnectionClass *conn, StatementClass *stmt, const char *next_token, - const Aws::TimestreamQuery::Model::QueryOutcome &result) { + const QueryOutcome &result) { ClearError(); return _CC_from_TSResult(q_res, conn, stmt, next_token, result) ? TRUE : FALSE; } BOOL CC_Append_Table_Data( - const Aws::TimestreamQuery::Model::QueryOutcome &result, + const QueryOutcome &result, QResultClass *q_res, ColumnInfoClass &fields) { ClearError(); return AssignTableData(result, q_res, fields) @@ -177,7 +177,7 @@ BOOL CC_Append_Table_Data( bool _CC_from_TSResult( QResultClass *q_res, ConnectionClass *conn, StatementClass *stmt, const char *next_token, - const Aws::TimestreamQuery::Model::QueryOutcome &result) { + const QueryOutcome &result) { CSTR func = "_CC_from_TSResult"; // Note - NULL conn and/or cursor is valid if (q_res == NULL) @@ -210,7 +210,7 @@ bool _CC_from_TSResult( } bool AssignColumnHeaders(QResultClass *q_res, - const Aws::TimestreamQuery::Model::QueryOutcome &outcome) { + const QueryOutcome &outcome) { // Allocte memory for column fields const auto &column_info = outcome.GetResult().GetColumnInfo(); QR_set_num_fields(q_res, (uint16_t)column_info.size()); @@ -244,9 +244,6 @@ bool AssignColumnHeaders(QResultClass *q_res, } else if (type.RowColumnInfoHasBeenSet()) { column_type_id = DB_TYPE_VARCHAR; column_size = DB_VARCHAR_SIZE; - } else if (type.TimeSeriesMeasureValueColumnInfoHasBeenSet()) { - column_type_id = DB_TYPE_VARCHAR; - column_size = DB_VARCHAR_SIZE; } else { throw std::runtime_error("Unsupported Timestream type."); } @@ -261,7 +258,7 @@ bool AssignColumnHeaders(QResultClass *q_res, return true; } -bool AssignTableData(const Aws::TimestreamQuery::Model::QueryOutcome &outcome, +bool AssignTableData(const QueryOutcome &outcome, QResultClass *q_res, ColumnInfoClass &fields) { auto rows = outcome.GetResult().GetRows(); auto col_size = outcome.GetResult().GetColumnInfo().size(); @@ -277,7 +274,7 @@ bool AssignTableData(const Aws::TimestreamQuery::Model::QueryOutcome &outcome, return true; } -void ParseDatum(const Aws::TimestreamQuery::Model::Datum &datum, +void ParseDatum(const Datum &datum, std::string &datum_value, OID column_attr_id) { if (datum.ScalarValueHasBeenSet()) { auto scalar_value = datum.GetScalarValue(); @@ -302,7 +299,7 @@ void ParseDatum(const Aws::TimestreamQuery::Model::Datum &datum, } } -void ParseArray(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > & datums, std::string& array_value, OID column_attr_id) { +void ParseArray(const Aws::Vector< Datum > & datums, std::string& array_value, OID column_attr_id) { if (datums.size() == 0) { array_value += "-"; } else { @@ -321,7 +318,7 @@ void ParseArray(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > & datums } } -void ParseRow(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > &datums, +void ParseRow(const Aws::Vector< Datum > &datums, std::string &row_value, OID column_attr_id) { row_value += "("; for (auto &datum : datums) { @@ -337,7 +334,7 @@ void ParseRow(const Aws::Vector< Aws::TimestreamQuery::Model::Datum > &datums, row_value += ")"; } -bool AssignRowData(const Aws::TimestreamQuery::Model::Row &row, +bool AssignRowData(const Row &row, QResultClass *q_res, ColumnInfoClass &fields, const size_t &col_size) { TupleField *tuple = diff --git a/src/odbcdriver/parse_result.h b/src/odbcdriver/parse_result.h index 44ec9ed0e..4695ecae6 100644 --- a/src/odbcdriver/parse_result.h +++ b/src/odbcdriver/parse_result.h @@ -28,16 +28,16 @@ extern "C" { #ifdef __cplusplus #include "helper.h" -#include -#include -#include +#include "Type.h" +#include "ScalarType.h" +#include "DatabaseQueryClient.h" // const char* is used instead of string for the cursor, because a NULL cursor // is sometimes used Cannot pass q_res as reference because it breaks qresult.h // macros that expect to use -> operator BOOL CC_from_TSResult( QResultClass *q_res, ConnectionClass *conn, StatementClass *stmt, const char *next_token, - const Aws::TimestreamQuery::Model::QueryOutcome &result); -BOOL CC_Append_Table_Data(const Aws::TimestreamQuery::Model::QueryOutcome &result, QResultClass *q_res, ColumnInfoClass &fields); + const QueryOutcome &result); +BOOL CC_Append_Table_Data(const QueryOutcome &result, QResultClass *q_res, ColumnInfoClass &fields); #endif #endif diff --git a/src/odbcdriver/prefetch_queue.cpp b/src/odbcdriver/prefetch_queue.cpp index f7124c845..0d4ed0f01 100644 --- a/src/odbcdriver/prefetch_queue.cpp +++ b/src/odbcdriver/prefetch_queue.cpp @@ -15,7 +15,7 @@ */ #include "prefetch_queue.h" -bool PrefetchQueue::Push(std::shared_future< Aws::TimestreamQuery::Model::QueryOutcome > future_outcome) { +bool PrefetchQueue::Push(std::shared_future< QueryOutcome > future_outcome) { std::unique_lock< std::mutex > lock(mutex); condition_variable.wait( lock, [&]() { return queue.size() < CAPACITY || !retrieving; }); @@ -38,7 +38,7 @@ void PrefetchQueue::Pop() { condition_variable.notify_one(); } -Aws::TimestreamQuery::Model::QueryOutcome PrefetchQueue::Front() { +QueryOutcome PrefetchQueue::Front() { auto outcome = queue.front().get(); return outcome; } @@ -80,4 +80,4 @@ bool PrefetchQueue::IsRetrieving() { void PrefetchQueue::NotifyOne() { condition_variable.notify_one(); -} +} \ No newline at end of file diff --git a/src/odbcdriver/prefetch_queue.h b/src/odbcdriver/prefetch_queue.h index ebf965960..cda2f91c3 100644 --- a/src/odbcdriver/prefetch_queue.h +++ b/src/odbcdriver/prefetch_queue.h @@ -18,7 +18,7 @@ #include #include -#include +#include "DatabaseQueryClient.h" /** * PrefetchQueue class for query @@ -34,7 +34,7 @@ class PrefetchQueue { * @param future_outcome std::shared_future< Aws::TimestreamQuery::Model::QueryOutcome > * @return bool */ - bool Push(std::shared_future< Aws::TimestreamQuery::Model::QueryOutcome > future_outcome); + bool Push(std::shared_future< QueryOutcome > future_outcome); /** * Pop function * @return void @@ -44,7 +44,7 @@ class PrefetchQueue { * Front function * @return Aws::TimestreamQuery::Model::QueryOutcome */ - Aws::TimestreamQuery::Model::QueryOutcome Front(); + QueryOutcome Front(); /** * Check the readiness of the front * It could be interrupted by if the caller cancels @@ -83,7 +83,7 @@ class PrefetchQueue { * The queue storing the future object * If future object is not ready, it means AWS is still processing the corresponding query request */ - std::queue< std::shared_future< Aws::TimestreamQuery::Model::QueryOutcome > > queue; + std::queue< std::shared_future< QueryOutcome > > queue; /** * If true, it is in retrieving state */ diff --git a/src/odbcdriver/types.h b/src/odbcdriver/types.h index c6b80c5f3..951546319 100644 --- a/src/odbcdriver/types.h +++ b/src/odbcdriver/types.h @@ -20,7 +20,7 @@ #include "dlg_specific.h" #include "odbc.h" #ifdef __cplusplus -#include +#include "QueryResult.h" extern "C" { #endif /* the type numbers are defined by the OID's of the types' rows */