From b3b9d65c045d716a8a76f8119ea00eaab7cd1a33 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Wed, 7 Aug 2024 12:43:36 +0000 Subject: [PATCH] fix ListObject in azure client --- .../AzureBlobStorageCommon.cpp | 22 +++++++++++++++++-- .../AzureBlobStorage/AzureBlobStorageCommon.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp b/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp index 79f371eb8f5..f8b0eb9ac56 100644 --- a/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp +++ b/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.cpp @@ -25,6 +25,7 @@ namespace DB namespace ErrorCodes { extern const int BAD_ARGUMENTS; + extern const int LOGICAL_ERROR; } namespace AzureBlobStorage @@ -76,11 +77,28 @@ BlockBlobClient ContainerClientWrapper::GetBlockBlobClient(const String & blob_n return client.GetBlockBlobClient(blob_prefix / blob_name); } +BlobContainerPropertiesRespones ContainerClientWrapper::GetProperties() const +{ + return client.GetProperties(); +} + ListBlobsPagedResponse ContainerClientWrapper::ListBlobs(const ListBlobsOptions & options) const { auto new_options = options; new_options.Prefix = blob_prefix / options.Prefix.ValueOr(""); - return client.ListBlobs(new_options); + + auto response = client.ListBlobs(new_options); + auto blob_prefix_str = blob_prefix.string() + "/"; + + for (auto & blob : response.Blobs) + { + if (!blob.Name.starts_with(blob_prefix_str)) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Expected prefix '{}' in blob name '{}'", blob_prefix_str, blob.Name); + + blob.Name = blob.Name.substr(blob_prefix_str.size()); + } + + return response; } bool ContainerClientWrapper::IsClientForDisk() const @@ -258,7 +276,7 @@ void processURL(const String & url, const String & container_name, Endpoint & en static bool containerExists(const ContainerClient & client) { ProfileEvents::increment(ProfileEvents::AzureGetProperties); - if (client.GetClickhouseOptions().IsClientForDisk) + if (client.IsClientForDisk()) ProfileEvents::increment(ProfileEvents::DiskAzureGetProperties); try diff --git a/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.h b/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.h index a82e0f07a3f..af47fbbf772 100644 --- a/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.h +++ b/src/Disks/ObjectStorages/AzureBlobStorage/AzureBlobStorageCommon.h @@ -100,6 +100,7 @@ using RawContainerClient = Azure::Storage::Blobs::BlobContainerClient; using Azure::Storage::Blobs::ListBlobsOptions; using Azure::Storage::Blobs::ListBlobsPagedResponse; +using BlobContainerPropertiesRespones = Azure::Response; /// A wrapper for ContainerClient that correctly handles the prefix of blobs. /// See AzureBlobStorageEndpoint and processAzureBlobStorageEndpoint for details. @@ -111,6 +112,7 @@ public: bool IsClientForDisk() const; BlobClient GetBlobClient(const String & blob_name) const; BlockBlobClient GetBlockBlobClient(const String & blob_name) const; + BlobContainerPropertiesRespones GetProperties() const; ListBlobsPagedResponse ListBlobs(const ListBlobsOptions & options) const; private: