Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Disks/ObjectStorages/IObjectStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,22 @@ WriteSettings IObjectStorage::patchSettings(const WriteSettings & write_settings
return write_settings;
}


void RelativePathWithMetadata::loadMetadata(ObjectStoragePtr object_storage, bool ignore_non_existent_file)
{
if (!metadata)
{
const auto & path = isArchive() ? getPathToArchive() : getPath();

if (ignore_non_existent_file)
{
metadata = object_storage->tryGetObjectMetadata(path);
}
else
{
metadata = object_storage->getObjectMetadata(path);
}
}
}

}
2 changes: 2 additions & 0 deletions src/Disks/ObjectStorages/IObjectStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ struct RelativePathWithMetadata
virtual bool isArchive() const { return false; }
virtual std::string getPathToArchive() const { throw Exception(ErrorCodes::LOGICAL_ERROR, "Not an archive"); }
virtual size_t fileSizeInArchive() const { throw Exception(ErrorCodes::LOGICAL_ERROR, "Not an archive"); }

void loadMetadata(ObjectStoragePtr object_storage, bool ignore_non_existent_file);
};

struct ObjectKeyWithMetadata
Expand Down
10 changes: 7 additions & 3 deletions src/Storages/ObjectStorage/DataLakes/IDataLakeMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ class KeysIterator : public IObjectIterator
return nullptr;

auto key = data_files[current_index];
auto object_metadata = object_storage->getObjectMetadata(key);

if (callback)
callback(FileProgress(0, object_metadata.size_bytes));
{
/// Too expencive to load size for metadata always
/// because it requires API call to external storage.
/// In many cases only keys are needed.
callback(FileProgress(0, 1));
}

return std::make_shared<ObjectInfo>(key, std::move(object_metadata));
return std::make_shared<ObjectInfo>(key, std::nullopt);
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/Storages/ObjectStorage/ReadBufferIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ std::optional<ColumnsDescription> ReadBufferIterator::tryGetColumnsFromCache(
const auto & object_info = (*it);
auto get_last_mod_time = [&] -> std::optional<time_t>
{
const auto & path = object_info->isArchive() ? object_info->getPathToArchive() : object_info->getPath();
if (!object_info->metadata)
object_info->metadata = object_storage->tryGetObjectMetadata(path);

object_info->loadMetadata(object_storage);
return object_info->metadata
? std::optional<time_t>(object_info->metadata->last_modified.epochTime())
: std::nullopt;
Expand Down Expand Up @@ -150,7 +147,6 @@ std::unique_ptr<ReadBuffer> ReadBufferIterator::recreateLastReadBuffer()
{
auto context = getContext();

const auto & path = current_object_info->isArchive() ? current_object_info->getPathToArchive() : current_object_info->getPath();
auto impl = StorageObjectStorageSource::createReadBuffer(*current_object_info, object_storage, context, getLogger("ReadBufferIterator"));

const auto compression_method = chooseCompressionMethod(current_object_info->getFileName(), configuration->compression_method);
Expand Down Expand Up @@ -249,6 +245,8 @@ ReadBufferIterator::Data ReadBufferIterator::next()
prev_read_keys_size = read_keys.size();
}

current_object_info->loadMetadata(object_storage);

if (query_settings.skip_empty_files
&& current_object_info->metadata && current_object_info->metadata->size_bytes == 0)
continue;
Expand Down
16 changes: 1 addition & 15 deletions src/Storages/ObjectStorage/StorageObjectStorageSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,21 +439,7 @@ StorageObjectStorageSource::ReaderHolder StorageObjectStorageSource::createReade
if (!object_info || object_info->getPath().empty())
return {};

if (!object_info->metadata)
{
const auto & path = object_info->isArchive() ? object_info->getPathToArchive() : object_info->getPath();

if (query_settings.ignore_non_existent_file)
{
auto metadata = object_storage->tryGetObjectMetadata(path);
if (!metadata)
return {};

object_info->metadata = metadata;
}
else
object_info->metadata = object_storage->getObjectMetadata(path);
}
object_info->loadMetadata(object_storage, query_settings.ignore_non_existent_file);
}
while (query_settings.skip_empty_files && object_info->metadata->size_bytes == 0);

Expand Down
Loading