From 6e0e7c2f5b06f1d2b2f4ac9726d7c6f643568f91 Mon Sep 17 00:00:00 2001 From: George Arama Date: Tue, 16 Jan 2024 12:12:53 -0800 Subject: [PATCH 01/10] mroe quotes --- sdk/tables/azure-data-tables/test/ut/serializers_test.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp b/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp index a21c9a8585..f5d5d27b87 100644 --- a/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp +++ b/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp @@ -8,6 +8,5 @@ namespace Azure { namespace Data { namespace Test { - class SerializersTest : public Azure::Storage::Test::StorageTest { - }; + class SerializersTest : public Azure::Storage::Test::StorageTest {}; }}} // namespace Azure::Data::Test From cd9c1ecefdedc0bb1d69b4d036cfe07fafbdd198 Mon Sep 17 00:00:00 2001 From: George Arama Date: Tue, 16 Jan 2024 12:14:48 -0800 Subject: [PATCH 02/10] dssf --- sdk/tables/azure-data-tables/test/ut/serializers_test.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp b/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp index f5d5d27b87..a21c9a8585 100644 --- a/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp +++ b/sdk/tables/azure-data-tables/test/ut/serializers_test.hpp @@ -8,5 +8,6 @@ namespace Azure { namespace Data { namespace Test { - class SerializersTest : public Azure::Storage::Test::StorageTest {}; + class SerializersTest : public Azure::Storage::Test::StorageTest { + }; }}} // namespace Azure::Data::Test From f24d203148643ed1b16f324349ee9de3430f60f9 Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 12:13:40 -0700 Subject: [PATCH 03/10] getentity --- .../inc/azure/data/tables/tables_clients.hpp | 14 +++++++ .../azure-data-tables/src/tables_clients.cpp | 33 +++++++++++++++++ .../test/ut/table_client_test.cpp | 37 +++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp index 0a31d0002a..faa3223b16 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp @@ -300,6 +300,20 @@ namespace Azure { namespace Data { namespace Tables { Models::QueryEntitiesPagedResponse QueryEntities( Models::QueryEntitiesOptions const& options = {}, Core::Context const& context = {}); + + /** + * @brief GetTableEntity. + * + * @param partitionKey The partition key of the entity. + * @param rowKey The row key of the entity. + * @param context for canceling long running operations. + * @return Entity list paged response. + */ + Response GetEntity( + const std::string & partitionKey, + const std::string & rowKey, + Core::Context const& context = {}); + /** * @brief Creates a new transaction. * diff --git a/sdk/tables/azure-data-tables/src/tables_clients.cpp b/sdk/tables/azure-data-tables/src/tables_clients.cpp index 78693cd7bd..584a84b31b 100644 --- a/sdk/tables/azure-data-tables/src/tables_clients.cpp +++ b/sdk/tables/azure-data-tables/src/tables_clients.cpp @@ -11,6 +11,7 @@ #include "azure/data/tables/internal/policies/timeout_policy.hpp" #include "azure/data/tables/internal/serializers.hpp" + #include #include using namespace Azure::Data::Tables; @@ -807,6 +808,38 @@ void Models::QueryEntitiesPagedResponse::OnNextPage(const Azure::Core::Context& *this = m_tableClient->QueryEntities(m_operationOptions, context); } + Azure::Response TableClient::GetEntity( + const std::string& partitionKey, + const std::string& rowKey, + Core::Context const& context) +{ + auto url = m_url; + url.AppendPath(m_tableName + "(PartitionKey='" + partitionKey + "',RowKey='" + rowKey + "')"); + + Core::Http::Request request(Core::Http::HttpMethod::Get, url); + request.SetHeader("Accept", "application/json;odata=fullmetadata"); + + auto rawResponse = m_pipeline->Send(request, context); + auto const httpStatusCode = rawResponse->GetStatusCode(); + if (httpStatusCode != Core::Http::HttpStatusCode::Ok) + { + throw Core::RequestFailedException(rawResponse); + } + + Models::TableEntity response{}; + { + const auto& responseBody = rawResponse->GetBody(); + std::string responseString = std::string(responseBody.begin(), responseBody.end()); + + + auto const jsonRoot + = Azure::Core::Json::_internal::json::parse(responseBody.begin(), responseBody.end()); + + response = DeserializeEntity(jsonRoot); + } + return Response(std::move(response), std::move(rawResponse)); +} + Models::QueryEntitiesPagedResponse TableClient::QueryEntities( Models::QueryEntitiesOptions const& options, Core::Context const& context) diff --git a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp index 17697bc664..3f61c22eee 100644 --- a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp +++ b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp @@ -461,6 +461,43 @@ namespace Azure { namespace Data { namespace Test { EXPECT_EQ(responseQuery.TableEntities.size(), 1); } + TEST_P(TablesClientTest, EntityGet) + { + if (GetParam() == AuthType::Key + && Azure::Core::_internal::StringExtensions::ToLower(GetEnv("AZURE_TEST_MODE")) == "live") + { + EXPECT_TRUE(true); + return; + } + Azure::Data::Tables::Models::TableEntity entity; + + entity.PartitionKey = "P1"; + entity.RowKey = "R1"; + entity.Properties["Name"] = "Azure"; + entity.Properties["Product"] = "Tables"; + auto createResponse = m_tableClient->Create(); + auto response = m_tableClient->CreateEntity(entity); + EXPECT_EQ(response.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent); + EXPECT_FALSE(response.Value.ETag.empty()); + + entity.Properties["Product"] = "Tables2"; + entity.RowKey = "R2"; + m_tableClient->CreateEntity(entity); + + entity.Properties["Product"] = "Tables3"; + entity.RowKey = "R3"; + m_tableClient->CreateEntity(entity); + + + std::string partitionKey = "P1"; + std::string rowKey = "R1"; + auto responseQuery = m_tableClient->GetEntity(partitionKey,rowKey); + EXPECT_EQ(responseQuery.Value.PartitionKey, "P1"); + EXPECT_EQ(responseQuery.Value.RowKey, "R1"); + EXPECT_EQ(responseQuery.Value.Properties["Name"], "Azure"); + EXPECT_EQ(responseQuery.Value.Properties["Product"], "Tables"); + } + TEST_P(TablesClientTest, TransactionCreateFail_LIVEONLY_) { Azure::Data::Tables::Models::TableEntity entity; From c4372b91aee19f8154b1d57f29f2c56df272d60f Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 12:46:33 -0700 Subject: [PATCH 04/10] tests --- sdk/core/azure-core-test/src/test_proxy_manager.cpp | 2 +- sdk/tables/azure-data-tables/src/tables_clients.cpp | 3 +-- sdk/tables/azure-data-tables/test/ut/table_client_test.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/core/azure-core-test/src/test_proxy_manager.cpp b/sdk/core/azure-core-test/src/test_proxy_manager.cpp index 6d21f0909b..3aeb83a35b 100644 --- a/sdk/core/azure-core-test/src/test_proxy_manager.cpp +++ b/sdk/core/azure-core-test/src/test_proxy_manager.cpp @@ -19,7 +19,7 @@ using Azure::Core::_internal::Environment; TestMode TestProxyManager::GetTestMode() { - auto value = Environment::GetVariable("AZURE_TEST_MODE"); + auto value = std::string{"PLAYBACK"}; // Environment::GetVariable("AZURE_TEST_MODE"); if (value.empty()) { return Azure::Core::Test::TestMode::LIVE; diff --git a/sdk/tables/azure-data-tables/src/tables_clients.cpp b/sdk/tables/azure-data-tables/src/tables_clients.cpp index a4c05a33c7..dbc66c5569 100644 --- a/sdk/tables/azure-data-tables/src/tables_clients.cpp +++ b/sdk/tables/azure-data-tables/src/tables_clients.cpp @@ -843,12 +843,11 @@ void Models::QueryEntitiesPagedResponse::OnNextPage(const Azure::Core::Context& { const auto& responseBody = rawResponse->GetBody(); std::string responseString = std::string(responseBody.begin(), responseBody.end()); - auto const jsonRoot = Azure::Core::Json::_internal::json::parse(responseBody.begin(), responseBody.end()); - response = DeserializeEntity(jsonRoot); + response = Serializers::DeserializeEntity(jsonRoot); } return Response(std::move(response), std::move(rawResponse)); } diff --git a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp index bef08f8385..e91b1be819 100644 --- a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp +++ b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp @@ -483,7 +483,7 @@ namespace Azure { namespace Data { namespace Test { entity.RowKey = "R1"; entity.Properties["Name"] = "Azure"; entity.Properties["Product"] = "Tables"; - auto createResponse = m_tableClient->Create(); + auto createResponse = m_tableServiceClient->CreateTable(m_tableName); auto response = m_tableClient->CreateEntity(entity); EXPECT_EQ(response.RawResponse->GetStatusCode(), Azure::Core::Http::HttpStatusCode::NoContent); EXPECT_FALSE(response.Value.ETag.empty()); From 576ad30d853c22c1b351cb9dea3adaf6d0ec7819 Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 13:34:45 -0700 Subject: [PATCH 05/10] re --- sdk/core/azure-core-test/src/test_proxy_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/core/azure-core-test/src/test_proxy_manager.cpp b/sdk/core/azure-core-test/src/test_proxy_manager.cpp index 3aeb83a35b..6d21f0909b 100644 --- a/sdk/core/azure-core-test/src/test_proxy_manager.cpp +++ b/sdk/core/azure-core-test/src/test_proxy_manager.cpp @@ -19,7 +19,7 @@ using Azure::Core::_internal::Environment; TestMode TestProxyManager::GetTestMode() { - auto value = std::string{"PLAYBACK"}; // Environment::GetVariable("AZURE_TEST_MODE"); + auto value = Environment::GetVariable("AZURE_TEST_MODE"); if (value.empty()) { return Azure::Core::Test::TestMode::LIVE; From c3d215d1ceb264bd95f084987ed91c19c79749a7 Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 14:28:15 -0700 Subject: [PATCH 06/10] assets working now --- sdk/tables/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/assets.json b/sdk/tables/assets.json index 587fc753d2..c9b0f1d86e 100644 --- a/sdk/tables/assets.json +++ b/sdk/tables/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "cpp", "TagPrefix": "cpp/tables", - "Tag": "cpp/tables_ca30219607" + "Tag": "cpp/tables_69657814a3" } From 3e644f55126ef9dd450df2dcbfebf1589060466d Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 14:44:42 -0700 Subject: [PATCH 07/10] re --- .../inc/azure/data/tables/tables_clients.hpp | 2 +- sdk/tables/azure-data-tables/src/tables_clients.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp index 59971e4ba6..454ae6b453 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp @@ -302,7 +302,7 @@ namespace Azure { namespace Data { namespace Tables { Core::Context const& context = {}); /** - * @brief GetTableEntity. + * @brief Get one table entity. * * @param partitionKey The partition key of the entity. * @param rowKey The row key of the entity. diff --git a/sdk/tables/azure-data-tables/src/tables_clients.cpp b/sdk/tables/azure-data-tables/src/tables_clients.cpp index dbc66c5569..845e6b42d8 100644 --- a/sdk/tables/azure-data-tables/src/tables_clients.cpp +++ b/sdk/tables/azure-data-tables/src/tables_clients.cpp @@ -11,7 +11,6 @@ #include "azure/data/tables/internal/policies/timeout_policy.hpp" #include "azure/data/tables/internal/serializers.hpp" - #include #include using namespace Azure::Data::Tables; @@ -821,7 +820,7 @@ void Models::QueryEntitiesPagedResponse::OnNextPage(const Azure::Core::Context& *this = m_tableClient->QueryEntities(m_operationOptions, context); } - Azure::Response TableClient::GetEntity( +Azure::Response TableClient::GetEntity( const std::string& partitionKey, const std::string& rowKey, Core::Context const& context) @@ -843,7 +842,7 @@ void Models::QueryEntitiesPagedResponse::OnNextPage(const Azure::Core::Context& { const auto& responseBody = rawResponse->GetBody(); std::string responseString = std::string(responseBody.begin(), responseBody.end()); - + auto const jsonRoot = Azure::Core::Json::_internal::json::parse(responseBody.begin(), responseBody.end()); From fd7e64df3130a3effabab4b1833f815befbbdbbc Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 15:00:08 -0700 Subject: [PATCH 08/10] fgf --- .../azure-data-tables/test/ut/table_client_test.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp index e91b1be819..32561c3b9d 100644 --- a/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp +++ b/sdk/tables/azure-data-tables/test/ut/table_client_test.cpp @@ -469,10 +469,9 @@ namespace Azure { namespace Data { namespace Test { EXPECT_EQ(responseQuery.TableEntities.size(), 1); } - TEST_P(TablesClientTest, EntityGet) + TEST_P(TablesClientTest, EntityGet) { - if (GetParam() == AuthType::Key - && Azure::Core::_internal::StringExtensions::ToLower(GetEnv("AZURE_TEST_MODE")) == "live") + if (GetParam() == AuthType::Key) { EXPECT_TRUE(true); return; @@ -496,10 +495,9 @@ namespace Azure { namespace Data { namespace Test { entity.RowKey = "R3"; m_tableClient->CreateEntity(entity); - std::string partitionKey = "P1"; std::string rowKey = "R1"; - auto responseQuery = m_tableClient->GetEntity(partitionKey,rowKey); + auto responseQuery = m_tableClient->GetEntity(partitionKey, rowKey); EXPECT_EQ(responseQuery.Value.PartitionKey, "P1"); EXPECT_EQ(responseQuery.Value.RowKey, "R1"); EXPECT_EQ(responseQuery.Value.Properties["Name"], "Azure"); From c702052cab037ca24108f4f393134c834b41d9b4 Mon Sep 17 00:00:00 2001 From: George Arama Date: Mon, 18 Mar 2024 15:27:39 -0700 Subject: [PATCH 09/10] clang --- .../inc/azure/data/tables/tables_clients.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp index 454ae6b453..8b74b9d987 100644 --- a/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp +++ b/sdk/tables/azure-data-tables/inc/azure/data/tables/tables_clients.hpp @@ -301,7 +301,7 @@ namespace Azure { namespace Data { namespace Tables { Models::QueryEntitiesOptions const& options = {}, Core::Context const& context = {}); - /** + /** * @brief Get one table entity. * * @param partitionKey The partition key of the entity. @@ -310,8 +310,8 @@ namespace Azure { namespace Data { namespace Tables { * @return Entity list paged response. */ Response GetEntity( - const std::string & partitionKey, - const std::string & rowKey, + const std::string& partitionKey, + const std::string& rowKey, Core::Context const& context = {}); /** From bf445f492923d083f05380098d2f12d439381f32 Mon Sep 17 00:00:00 2001 From: George Arama Date: Tue, 19 Mar 2024 11:33:20 -0700 Subject: [PATCH 10/10] url encode --- .../azure-data-tables/src/tables_clients.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/tables_clients.cpp b/sdk/tables/azure-data-tables/src/tables_clients.cpp index 845e6b42d8..9f8e8605fe 100644 --- a/sdk/tables/azure-data-tables/src/tables_clients.cpp +++ b/sdk/tables/azure-data-tables/src/tables_clients.cpp @@ -672,8 +672,8 @@ Azure::Response TableClient::UpdateEntity( (void)options; auto url = m_url; url.AppendPath( - m_tableName + "(PartitionKey='" + tableEntity.PartitionKey + "',RowKey='" + tableEntity.RowKey - + "')"); + m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(tableEntity.PartitionKey) + + "',RowKey='" + Azure::Core::Url::Encode(tableEntity.RowKey) + "')"); std::string jsonBody = Serializers::UpdateEntity(tableEntity); @@ -716,8 +716,8 @@ Azure::Response TableClient::MergeEntity( (void)options; auto url = m_url; url.AppendPath( - m_tableName + "(PartitionKey='" + tableEntity.PartitionKey + "',RowKey='" + tableEntity.RowKey - + "')"); + m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(tableEntity.PartitionKey) + + "',RowKey='" + Azure::Core::Url::Encode(tableEntity.RowKey) + "')"); std::string jsonBody = Serializers::MergeEntity(tableEntity); @@ -758,8 +758,8 @@ Azure::Response TableClient::DeleteEntity( { auto url = m_url; url.AppendPath( - m_tableName + "(PartitionKey='" + tableEntity.PartitionKey + "',RowKey='" + tableEntity.RowKey - + "')"); + m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(tableEntity.PartitionKey) + + "',RowKey='" + Azure::Core::Url::Encode(tableEntity.RowKey) + "')"); Core::Http::Request request(Core::Http::HttpMethod::Delete, url); @@ -826,7 +826,9 @@ Azure::Response TableClient::GetEntity( Core::Context const& context) { auto url = m_url; - url.AppendPath(m_tableName + "(PartitionKey='" + partitionKey + "',RowKey='" + rowKey + "')"); + url.AppendPath( + m_tableName + "(PartitionKey='" + Azure::Core::Url::Encode(partitionKey) + "',RowKey='" + + Azure::Core::Url::Encode(rowKey) + "')"); Core::Http::Request request(Core::Http::HttpMethod::Get, url); request.SetHeader("Accept", "application/json;odata=fullmetadata"); @@ -859,11 +861,11 @@ Models::QueryEntitiesPagedResponse TableClient::QueryEntities( std::string appendPath = m_tableName + "("; if (!options.PartitionKey.empty()) { - appendPath += "PartitionKey='" + options.PartitionKey + "'"; + appendPath += "PartitionKey='" + Azure::Core::Url::Encode(options.PartitionKey) + "'"; } if (!options.RowKey.empty()) { - appendPath += ",RowKey='" + options.RowKey + "'"; + appendPath += ",RowKey='" + Azure::Core::Url::Encode(options.RowKey) + "'"; } appendPath += ")"; @@ -871,11 +873,11 @@ Models::QueryEntitiesPagedResponse TableClient::QueryEntities( if (options.Filter.HasValue()) { - url.AppendQueryParameter("$filter", options.Filter.Value()); + url.AppendQueryParameter("$filter", Azure::Core::Url::Encode(options.Filter.Value())); } if (!options.SelectColumns.empty()) { - url.AppendQueryParameter("$select", options.SelectColumns); + url.AppendQueryParameter("$select", Azure::Core::Url::Encode(options.SelectColumns)); } Core::Http::Request request(Core::Http::HttpMethod::Get, url);