fix ListObject in azure client

This commit is contained in:
Anton Popov 2024-08-07 12:43:36 +00:00
parent bf4caa06c1
commit b3b9d65c04
2 changed files with 22 additions and 2 deletions

View File

@ -25,6 +25,7 @@ namespace DB
namespace ErrorCodes namespace ErrorCodes
{ {
extern const int BAD_ARGUMENTS; extern const int BAD_ARGUMENTS;
extern const int LOGICAL_ERROR;
} }
namespace AzureBlobStorage namespace AzureBlobStorage
@ -76,11 +77,28 @@ BlockBlobClient ContainerClientWrapper::GetBlockBlobClient(const String & blob_n
return client.GetBlockBlobClient(blob_prefix / blob_name); return client.GetBlockBlobClient(blob_prefix / blob_name);
} }
BlobContainerPropertiesRespones ContainerClientWrapper::GetProperties() const
{
return client.GetProperties();
}
ListBlobsPagedResponse ContainerClientWrapper::ListBlobs(const ListBlobsOptions & options) const ListBlobsPagedResponse ContainerClientWrapper::ListBlobs(const ListBlobsOptions & options) const
{ {
auto new_options = options; auto new_options = options;
new_options.Prefix = blob_prefix / options.Prefix.ValueOr(""); 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 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) static bool containerExists(const ContainerClient & client)
{ {
ProfileEvents::increment(ProfileEvents::AzureGetProperties); ProfileEvents::increment(ProfileEvents::AzureGetProperties);
if (client.GetClickhouseOptions().IsClientForDisk) if (client.IsClientForDisk())
ProfileEvents::increment(ProfileEvents::DiskAzureGetProperties); ProfileEvents::increment(ProfileEvents::DiskAzureGetProperties);
try try

View File

@ -100,6 +100,7 @@ using RawContainerClient = Azure::Storage::Blobs::BlobContainerClient;
using Azure::Storage::Blobs::ListBlobsOptions; using Azure::Storage::Blobs::ListBlobsOptions;
using Azure::Storage::Blobs::ListBlobsPagedResponse; using Azure::Storage::Blobs::ListBlobsPagedResponse;
using BlobContainerPropertiesRespones = Azure::Response<Azure::Storage::Blobs::Models::BlobContainerProperties>;
/// A wrapper for ContainerClient that correctly handles the prefix of blobs. /// A wrapper for ContainerClient that correctly handles the prefix of blobs.
/// See AzureBlobStorageEndpoint and processAzureBlobStorageEndpoint for details. /// See AzureBlobStorageEndpoint and processAzureBlobStorageEndpoint for details.
@ -111,6 +112,7 @@ public:
bool IsClientForDisk() const; bool IsClientForDisk() const;
BlobClient GetBlobClient(const String & blob_name) const; BlobClient GetBlobClient(const String & blob_name) const;
BlockBlobClient GetBlockBlobClient(const String & blob_name) const; BlockBlobClient GetBlockBlobClient(const String & blob_name) const;
BlobContainerPropertiesRespones GetProperties() const;
ListBlobsPagedResponse ListBlobs(const ListBlobsOptions & options) const; ListBlobsPagedResponse ListBlobs(const ListBlobsOptions & options) const;
private: private: