diff --git a/src/IO/IRemoteFileMetadata.cpp b/src/IO/IRemoteFileMetadata.cpp index 80d3999078e..cd9aec68123 100644 --- a/src/IO/IRemoteFileMetadata.cpp +++ b/src/IO/IRemoteFileMetadata.cpp @@ -5,6 +5,7 @@ namespace DB namespace ErrorCodes { extern const int LOGICAL_ERROR; + extern const int BAD_ARGUMENTS; } IRemoteFileMetadata::~IRemoteFileMetadata() {} @@ -15,11 +16,11 @@ RemoteFileMetadataFactory & RemoteFileMetadataFactory::instance() return g_factory; } -IRemoteFileMetadataPtr RemoteFileMetadataFactory::createClass(const String & class_name) +IRemoteFileMetadataPtr RemoteFileMetadataFactory::get(const String & class_name) { auto it = class_creators.find(class_name); if (it == class_creators.end()) - return nullptr; + throw Exception(ErrorCodes::BAD_ARGUMENTS, "Not found metadata class:{}", class_name); return (it->second)(); } diff --git a/src/IO/IRemoteFileMetadata.h b/src/IO/IRemoteFileMetadata.h index becf90f4920..92830cd481e 100644 --- a/src/IO/IRemoteFileMetadata.h +++ b/src/IO/IRemoteFileMetadata.h @@ -27,7 +27,7 @@ public: inline UInt64 getLastModificationTimestamp() const { return last_modification_timestamp; } // deserialize - virtual bool fromString(const String &buf) = 0; + virtual bool fromString(const String & buf) = 0; // serialize virtual String toString() const = 0; @@ -43,7 +43,7 @@ using IRemoteFileMetadataPtr = std::shared_ptr; /* * How to register a subclass into the factory and use it ? - * 1) define your own subclass derive from IRemoteFileMetadata. Notice! the getClassName() must be the same + * 1) define your own subclass derive from IRemoteFileMetadata. Notice! the getName() must be the same * as your subclass name. * 2) in a .cpp file, call REGISTTER_REMOTE_FILE_META_DATA_CLASS(subclass), * 3) call RemoteFileMetadataFactory::instance().createClass(subclass_name) where you want to make a new object @@ -56,7 +56,7 @@ public: ~RemoteFileMetadataFactory() = default; static RemoteFileMetadataFactory & instance(); - IRemoteFileMetadataPtr createClass(const String & class_name); + IRemoteFileMetadataPtr get(const String & class_name); void registerClass(const String &class_name, ClassCreator creator); protected: RemoteFileMetadataFactory() = default; diff --git a/src/IO/RemoteReadBufferCache.cpp b/src/IO/RemoteReadBufferCache.cpp index 594a2ea450c..36680063c5f 100644 --- a/src/IO/RemoteReadBufferCache.cpp +++ b/src/IO/RemoteReadBufferCache.cpp @@ -57,7 +57,7 @@ std::shared_ptr RemoteCacheController::recover(const std: return nullptr; } - cache_controller->file_metadata_ptr = RemoteFileMetadataFactory::instance().createClass(cache_controller->metadata_class); + cache_controller->file_metadata_ptr = RemoteFileMetadataFactory::instance().get(cache_controller->metadata_class); if (!cache_controller->file_metadata_ptr) { // do not load this invalid cached file and clear it. the clear action is in